X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg.c;h=03f9109cd7c90117b08e2d9f209251e91906b237;hb=57be00bea7d66ea28caab6e32753bc167b7bccf1;hp=b196f58462f1a6bfde117eafaf7f1aa7846331aa;hpb=22730e8790a42c2873fd424d7ba66af95e0ab573;p=ffmpeg diff --git a/ffmpeg.c b/ffmpeg.c index b196f58462f..03f9109cd7c 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -41,23 +41,23 @@ #include "libavutil/avstring.h" #include "libavformat/os_support.h" -#ifdef HAVE_SYS_RESOURCE_H +#if HAVE_SYS_RESOURCE_H #include #include -#elif defined(HAVE_GETPROCESSTIMES) +#elif HAVE_GETPROCESSTIMES #include #endif -#ifdef HAVE_SYS_SELECT_H +#if HAVE_SYS_SELECT_H #include #endif -#ifdef HAVE_TERMIOS_H +#if HAVE_TERMIOS_H #include #include #include #include -#elif defined(HAVE_CONIO_H) +#elif HAVE_CONIO_H #include #endif #undef time //needed because HAVE_AV_CONFIG_H is defined on top @@ -295,7 +295,7 @@ typedef struct AVInputFile { int nb_streams; /* nb streams we are aware of */ } AVInputFile; -#ifdef HAVE_TERMIOS_H +#if HAVE_TERMIOS_H /* init terminal so that we can grab keys */ static struct termios oldtty; @@ -303,7 +303,7 @@ static struct termios oldtty; static void term_exit(void) { -#ifdef HAVE_TERMIOS_H +#if HAVE_TERMIOS_H tcsetattr (0, TCSANOW, &oldtty); #endif } @@ -319,7 +319,7 @@ sigterm_handler(int sig) static void term_init(void) { -#ifdef HAVE_TERMIOS_H +#if HAVE_TERMIOS_H struct termios tty; tcgetattr (0, &tty); @@ -344,7 +344,7 @@ static void term_init(void) register a function to be called at normal program termination */ atexit(term_exit); -#ifdef CONFIG_BEOS_NETSERVER +#if CONFIG_BEOS_NETSERVER fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); #endif } @@ -352,10 +352,10 @@ static void term_init(void) /* read a key without blocking */ static int read_key(void) { -#if defined(HAVE_TERMIOS_H) +#if HAVE_TERMIOS_H int n = 1; unsigned char ch; -#ifndef CONFIG_BEOS_NETSERVER +#if !CONFIG_BEOS_NETSERVER struct timeval tv; fd_set rfds; @@ -372,7 +372,7 @@ static int read_key(void) return n; } -#elif defined(HAVE_CONIO_H) +#elif HAVE_CONIO_H if(kbhit()) return(getch()); #endif @@ -396,9 +396,17 @@ static int av_exit(int ret) if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) url_fclose(s->pb); for(j=0;jnb_streams;j++) { + av_metadata_free(&s->streams[j]->metadata); av_free(s->streams[j]->codec); av_free(s->streams[j]); } + for(j=0;jnb_programs;j++) { + av_metadata_free(&s->programs[j]->metadata); + } + for(j=0;jnb_chapters;j++) { + av_metadata_free(&s->chapters[j]->metadata); + } + av_metadata_free(&s->metadata); av_free(s); } for(i=0;iindex; pkt.data= audio_out; @@ -703,6 +715,10 @@ static void do_audio_out(AVFormatContext *s, //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio() ret = avcodec_encode_audio(enc, audio_out, size_out, (short *)buftmp); + if (ret < 0) { + fprintf(stderr, "Audio encoding failed\n"); + av_exit(1); + } audio_size += ret; pkt.stream_index= ost->index; pkt.data= audio_out; @@ -752,7 +768,7 @@ static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void picture2 = picture; } - if (ENABLE_VHOOK) + if (CONFIG_VHOOK) frame_hook_process(picture2, dec->pix_fmt, dec->width, dec->height, 1000000 * ist->pts / AV_TIME_BASE); @@ -959,7 +975,7 @@ static void do_video_out(AVFormatContext *s, ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, &big_picture); - if (ret == -1) { + if (ret < 0) { fprintf(stderr, "Video encoding failed\n"); av_exit(1); } @@ -1401,8 +1417,9 @@ static int output_packet(AVInputStream *ist, int ist_index, if (subtitle_to_free) { if (subtitle_to_free->rects != NULL) { for (i = 0; i < subtitle_to_free->num_rects; i++) { - av_free(subtitle_to_free->rects[i].bitmap); - av_free(subtitle_to_free->rects[i].rgba_palette); + av_freep(&subtitle_to_free->rects[i]->pict.data[0]); + av_freep(&subtitle_to_free->rects[i]->pict.data[1]); + av_freep(&subtitle_to_free->rects[i]); } av_freep(&subtitle_to_free->rects); } @@ -1447,11 +1464,19 @@ static int output_packet(AVInputStream *ist, int ist_index, if(ret <= 0) { ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL); } + if (ret < 0) { + fprintf(stderr, "Audio encoding failed\n"); + av_exit(1); + } audio_size += ret; pkt.flags |= PKT_FLAG_KEY; break; case CODEC_TYPE_VIDEO: ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL); + if (ret < 0) { + fprintf(stderr, "Video encoding failed\n"); + av_exit(1); + } video_size += ret; if(enc->coded_frame && enc->coded_frame->key_frame) pkt.flags |= PKT_FLAG_KEY; @@ -1754,6 +1779,8 @@ static int av_encode(AVFormatContext **output_files, codec->has_b_frames = icodec->has_b_frames; break; case CODEC_TYPE_SUBTITLE: + codec->width = icodec->width; + codec->height = icodec->height; break; default: abort(); @@ -2073,7 +2100,10 @@ static int av_encode(AVFormatContext **output_files, /* read a frame from it and output it in the fifo */ is = input_files[file_index]; - if (av_read_frame(is, &pkt) < 0) { + ret= av_read_frame(is, &pkt); + if(ret == AVERROR(EAGAIN) && strcmp(is->iformat->name, "ffm")) + continue; + if (ret < 0) { file_table[file_index].eof_reached = 1; if (opt_shortest) break; @@ -2528,7 +2558,7 @@ static void opt_top_field_first(const char *arg) static int opt_thread_count(const char *opt, const char *arg) { thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); -#if !defined(HAVE_THREADS) +#if !HAVE_THREADS if (verbose >= 0) fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n"); #endif @@ -2601,7 +2631,7 @@ static void opt_video_tag(const char *arg) video_codec_tag= arg[0] + (arg[1]<<8) + (arg[2]<<16) + (arg[3]<<24); } -#ifdef CONFIG_VHOOK +#if CONFIG_VHOOK static void add_frame_hooker(const char *arg) { int argc = 0; @@ -3391,12 +3421,12 @@ static void opt_pass(const char *pass_str) static int64_t getutime(void) { -#ifdef HAVE_GETRUSAGE +#if HAVE_GETRUSAGE struct rusage rusage; getrusage(RUSAGE_SELF, &rusage); return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec; -#elif defined(HAVE_GETPROCESSTIMES) +#elif HAVE_GETPROCESSTIMES HANDLE proc; FILETIME c, e, k, u; proc = GetCurrentProcess(); @@ -3803,7 +3833,7 @@ static const OptionDef options[] = { { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" }, { "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" }, { "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" }, -#ifdef CONFIG_VHOOK +#if CONFIG_VHOOK { "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" }, #endif { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" }, @@ -3891,8 +3921,9 @@ int main(int argc, char **argv) } ti = getutime(); - av_encode(output_files, nb_output_files, input_files, nb_input_files, - stream_maps, nb_stream_maps); + if (av_encode(output_files, nb_output_files, input_files, nb_input_files, + stream_maps, nb_stream_maps) < 0) + av_exit(1); ti = getutime() - ti; if (do_benchmark) { printf("bench: utime=%0.3fs\n", ti / 1000000.0);