X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg.c;h=f428ba55501754f11b125a8572f3a82e81b5d6b0;hb=ad9d62ef22de83b36fc7da009734292a209ab765;hp=3cce5cedd7e788065f8f03f8f443721f57a6fd8f;hpb=10e7fc7ce4c5e1fc3aa37dccd49087af1ad7a227;p=ffmpeg diff --git a/ffmpeg.c b/ffmpeg.c index 3cce5cedd7e..f428ba55501 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -27,16 +27,19 @@ #include #include #include -#include "avformat.h" -#include "avdevice.h" -#include "swscale.h" -#include "framehook.h" -#include "opt.h" -#include "fifo.h" -#include "avstring.h" -#include "os_support.h" - -#if !defined(HAVE_GETRUSAGE) && defined(HAVE_GETPROCESSTIMES) +#include "libavformat/avformat.h" +#include "libavdevice/avdevice.h" +#include "libswscale/swscale.h" +#include "libavformat/framehook.h" +#include "libavcodec/opt.h" +#include "libavutil/fifo.h" +#include "libavutil/avstring.h" +#include "libavformat/os_support.h" + +#ifdef HAVE_SYS_RESOURCE_H +#include +#include +#elif defined(HAVE_GETPROCESSTIMES) #include #endif @@ -46,7 +49,6 @@ #include #include #include -#include #elif defined(HAVE_CONIO_H) #include #endif @@ -59,13 +61,9 @@ #undef NDEBUG #include -#if !defined(INFINITY) && defined(HUGE_VAL) -#define INFINITY HUGE_VAL -#endif - #undef exit -static const char program_name[] = "FFmpeg"; +const char program_name[] = "FFmpeg"; static const int program_birth_year = 2000; /* select an input stream for an output stream */ @@ -82,7 +80,7 @@ typedef struct AVMetaDataMap { int in_file; } AVMetaDataMap; -extern const OptionDef options[]; +static const OptionDef options[]; #define MAX_FILES 20 @@ -210,7 +208,7 @@ static uint64_t limit_filesize = 0; // static int pgmyuv_compatibility_hack=0; static float dts_delta_threshold = 10; -static int sws_flags = SWS_BICUBIC; +static unsigned int sws_flags = SWS_BICUBIC; static const char **opt_names; static int opt_name_count; @@ -375,6 +373,59 @@ static int decode_interrupt_cb(void) return q_pressed || (q_pressed = read_key() == 'q'); } +static int av_exit(int ret) +{ + int i; + + /* close files */ + for(i=0;ioformat->flags & AVFMT_NOFILE) && s->pb) + url_fclose(s->pb); + for(j=0;jnb_streams;j++) { + av_free(s->streams[j]->codec); + av_free(s->streams[j]); + } + av_free(s); + } + for(i=0;ichannels, dec->sample_rate, enc->channels, enc->sample_rate); - exit(1); + av_exit(1); } } @@ -845,7 +896,7 @@ static void do_video_out(AVFormatContext *s, &big_picture); if (ret == -1) { fprintf(stderr, "Video encoding failed\n"); - exit(1); + av_exit(1); } //enc->frame_number = enc->real_pict_num; if(ret>0){ @@ -876,7 +927,6 @@ static void do_video_out(AVFormatContext *s, } static double psnr(double d){ - if(d==0) return INFINITY; return -10.0*log(d)/log(10.0); } @@ -892,7 +942,7 @@ static void do_video_stats(AVFormatContext *os, AVOutputStream *ost, vstats_file = fopen(vstats_filename, "w"); if (!vstats_file) { perror("fopen"); - exit(1); + av_exit(1); } } @@ -1016,7 +1066,7 @@ static void print_report(AVFormatContext **output_files, bitrate = (double)(total_size * 8) / ti1 / 1000.0; snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - "size=%8.0fkB time=%0.1f bitrate=%6.1fkbits/s", + "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s", (double)total_size / 1024, ti1, bitrate); if (verbose > 1) @@ -1477,13 +1527,13 @@ static int av_encode(AVFormatContext **output_files, os = output_files[i]; if (!os->nb_streams) { fprintf(stderr, "Output file does not contain any stream\n"); - exit(1); + av_exit(1); } nb_ostreams += os->nb_streams; } if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) { fprintf(stderr, "Number of stream maps must match number of output streams\n"); - exit(1); + av_exit(1); } /* Sanity check the mapping args -- do the input files & streams exist? */ @@ -1494,14 +1544,14 @@ static int av_encode(AVFormatContext **output_files, if (fi < 0 || fi > nb_input_files - 1 || si < 0 || si > file_table[fi].nb_streams - 1) { fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); - exit(1); + av_exit(1); } fi = stream_maps[i].sync_file_index; si = stream_maps[i].sync_stream_index; if (fi < 0 || fi > nb_input_files - 1 || si < 0 || si > file_table[fi].nb_streams - 1) { fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si); - exit(1); + av_exit(1); } } @@ -1533,7 +1583,7 @@ static int av_encode(AVFormatContext **output_files, fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", stream_maps[n-1].file_index, stream_maps[n-1].stream_index, ost->file_index, ost->index); - exit(1); + av_exit(1); } } else { @@ -1572,7 +1622,7 @@ static int av_encode(AVFormatContext **output_files, if (!found) { fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n", ost->file_index, ost->index); - exit(1); + av_exit(1); } } } @@ -1597,6 +1647,8 @@ static int av_encode(AVFormatContext **output_files, av_strlcpy(ost->st->language, ist->st->language, sizeof(ost->st->language)); + ost->st->disposition = ist->st->disposition; + if (ost->st->stream_copy) { /* if stream_copy is selected, no need to decode or encode */ codec->codec_id = icodec->codec_id; @@ -1628,7 +1680,7 @@ static int av_encode(AVFormatContext **output_files, case CODEC_TYPE_VIDEO: if(using_vhook) { fprintf(stderr,"-vcodec copy and -vhook are incompatible (frames are not decoded)\n"); - exit(1); + av_exit(1); } codec->pix_fmt = icodec->pix_fmt; codec->width = icodec->width; @@ -1681,7 +1733,7 @@ static int av_encode(AVFormatContext **output_files, if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, codec->pix_fmt, codec->width, codec->height ) ) { fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n"); - exit(1); + av_exit(1); } sws_flags = av_get_int(sws_opts, "sws_flags", NULL); ost->img_resample_ctx = sws_getContext( @@ -1694,7 +1746,7 @@ static int av_encode(AVFormatContext **output_files, sws_flags, NULL, NULL, NULL); if (ost->img_resample_ctx == NULL) { fprintf(stderr, "Cannot get resampling context\n"); - exit(1); + av_exit(1); } ost->resample_height = icodec->height - (frame_topBand + frame_bottomBand); } @@ -1724,7 +1776,7 @@ static int av_encode(AVFormatContext **output_files, f = fopen(logfilename, "w"); if (!f) { perror(logfilename); - exit(1); + av_exit(1); } ost->logfile = f; } else { @@ -1732,7 +1784,7 @@ static int av_encode(AVFormatContext **output_files, f = fopen(logfilename, "r"); if (!f) { perror(logfilename); - exit(1); + av_exit(1); } fseek(f, 0, SEEK_END); size = ftell(f); @@ -1740,7 +1792,7 @@ static int av_encode(AVFormatContext **output_files, logbuffer = av_malloc(size + 1); if (!logbuffer) { fprintf(stderr, "Could not allocate log buffer\n"); - exit(1); + av_exit(1); } size = fread(logbuffer, 1, size, f); fclose(f); @@ -1793,12 +1845,12 @@ static int av_encode(AVFormatContext **output_files, if (!codec) { fprintf(stderr, "Unsupported codec for output stream #%d.%d\n", ost->file_index, ost->index); - exit(1); + av_exit(1); } if (avcodec_open(ost->st->codec, codec) < 0) { fprintf(stderr, "Error while opening codec for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n", ost->file_index, ost->index); - exit(1); + av_exit(1); } extra_size += ost->st->codec->extradata_size; } @@ -1813,12 +1865,12 @@ static int av_encode(AVFormatContext **output_files, if (!codec) { fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n", ist->st->codec->codec_id, ist->file_index, ist->index); - exit(1); + av_exit(1); } if (avcodec_open(ist->st->codec, codec) < 0) { fprintf(stderr, "Error while opening codec for input stream #%d.%d\n", ist->file_index, ist->index); - exit(1); + av_exit(1); } //if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO) // ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD; @@ -2121,7 +2173,7 @@ static void opt_format(const char *arg) file_oformat = guess_format(arg, NULL, NULL); if (!file_iformat && !file_oformat) { fprintf(stderr, "Unknown input or output format: %s\n", arg); - exit(1); + av_exit(1); } } @@ -2174,22 +2226,24 @@ static void opt_video_rc_override_string(const char *arg) video_rc_override_string = arg; } -static void opt_me_threshold(const char *arg) +static int opt_me_threshold(const char *opt, const char *arg) { - me_threshold = atoi(arg); + me_threshold = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); + return 0; } -static void opt_verbose(const char *arg) +static int opt_verbose(const char *opt, const char *arg) { - verbose = atoi(arg); + verbose = parse_number_or_die(opt, arg, OPT_INT64, AV_LOG_QUIET, AV_LOG_DEBUG); av_log_set_level(verbose); + return 0; } static void opt_frame_rate(const char *arg) { if (av_parse_video_frame_rate(&frame_rate, arg) < 0) { fprintf(stderr, "Incorrect frame rate\n"); - exit(1); + av_exit(1); } } @@ -2210,15 +2264,15 @@ static void opt_frame_crop_top(const char *arg) frame_topBand = atoi(arg); if (frame_topBand < 0) { fprintf(stderr, "Incorrect top crop size\n"); - exit(1); + av_exit(1); } if ((frame_topBand % 2) != 0) { fprintf(stderr, "Top crop size must be a multiple of 2\n"); - exit(1); + av_exit(1); } if ((frame_topBand) >= frame_height){ fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n"); - exit(1); + av_exit(1); } frame_height -= frame_topBand; } @@ -2228,15 +2282,15 @@ static void opt_frame_crop_bottom(const char *arg) frame_bottomBand = atoi(arg); if (frame_bottomBand < 0) { fprintf(stderr, "Incorrect bottom crop size\n"); - exit(1); + av_exit(1); } if ((frame_bottomBand % 2) != 0) { fprintf(stderr, "Bottom crop size must be a multiple of 2\n"); - exit(1); + av_exit(1); } if ((frame_bottomBand) >= frame_height){ fprintf(stderr, "Vertical crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n"); - exit(1); + av_exit(1); } frame_height -= frame_bottomBand; } @@ -2246,15 +2300,15 @@ static void opt_frame_crop_left(const char *arg) frame_leftBand = atoi(arg); if (frame_leftBand < 0) { fprintf(stderr, "Incorrect left crop size\n"); - exit(1); + av_exit(1); } if ((frame_leftBand % 2) != 0) { fprintf(stderr, "Left crop size must be a multiple of 2\n"); - exit(1); + av_exit(1); } if ((frame_leftBand) >= frame_width){ fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n"); - exit(1); + av_exit(1); } frame_width -= frame_leftBand; } @@ -2264,15 +2318,15 @@ static void opt_frame_crop_right(const char *arg) frame_rightBand = atoi(arg); if (frame_rightBand < 0) { fprintf(stderr, "Incorrect right crop size\n"); - exit(1); + av_exit(1); } if ((frame_rightBand % 2) != 0) { fprintf(stderr, "Right crop size must be a multiple of 2\n"); - exit(1); + av_exit(1); } if ((frame_rightBand) >= frame_width){ fprintf(stderr, "Horizontal crop dimensions are outside the range of the original image.\nRemember to crop first and scale second.\n"); - exit(1); + av_exit(1); } frame_width -= frame_rightBand; } @@ -2281,11 +2335,11 @@ static void opt_frame_size(const char *arg) { if (av_parse_video_frame_size(&frame_width, &frame_height, arg) < 0) { fprintf(stderr, "Incorrect frame size\n"); - exit(1); + av_exit(1); } if ((frame_width % 2) != 0 || (frame_height % 2) != 0) { fprintf(stderr, "Frame size must be a multiple of 2\n"); - exit(1); + av_exit(1); } } @@ -2326,11 +2380,11 @@ static void opt_frame_pad_top(const char *arg) frame_padtop = atoi(arg); if (frame_padtop < 0) { fprintf(stderr, "Incorrect top pad size\n"); - exit(1); + av_exit(1); } if ((frame_padtop % 2) != 0) { fprintf(stderr, "Top pad size must be a multiple of 2\n"); - exit(1); + av_exit(1); } } @@ -2339,11 +2393,11 @@ static void opt_frame_pad_bottom(const char *arg) frame_padbottom = atoi(arg); if (frame_padbottom < 0) { fprintf(stderr, "Incorrect bottom pad size\n"); - exit(1); + av_exit(1); } if ((frame_padbottom % 2) != 0) { fprintf(stderr, "Bottom pad size must be a multiple of 2\n"); - exit(1); + av_exit(1); } } @@ -2353,11 +2407,11 @@ static void opt_frame_pad_left(const char *arg) frame_padleft = atoi(arg); if (frame_padleft < 0) { fprintf(stderr, "Incorrect left pad size\n"); - exit(1); + av_exit(1); } if ((frame_padleft % 2) != 0) { fprintf(stderr, "Left pad size must be a multiple of 2\n"); - exit(1); + av_exit(1); } } @@ -2367,15 +2421,15 @@ static void opt_frame_pad_right(const char *arg) frame_padright = atoi(arg); if (frame_padright < 0) { fprintf(stderr, "Incorrect right pad size\n"); - exit(1); + av_exit(1); } if ((frame_padright % 2) != 0) { fprintf(stderr, "Right pad size must be a multiple of 2\n"); - exit(1); + av_exit(1); } } -void list_pix_fmts(void) +static void list_pix_fmts(void) { int i; char pix_fmt_str[128]; @@ -2391,7 +2445,7 @@ static void opt_frame_pix_fmt(const char *arg) frame_pix_fmt = avcodec_get_pix_fmt(arg); else { list_pix_fmts(); - exit(0); + av_exit(0); } } @@ -2414,7 +2468,7 @@ static void opt_frame_aspect_ratio(const char *arg) if (!ar) { fprintf(stderr, "Incorrect aspect ratio specification.\n"); - exit(1); + av_exit(1); } frame_aspect_ratio = ar; } @@ -2425,7 +2479,7 @@ static void opt_qscale(const char *arg) if (video_qscale <= 0 || video_qscale > 255) { fprintf(stderr, "qscale must be > 0.0 and <= 255\n"); - exit(1); + av_exit(1); } } @@ -2435,7 +2489,7 @@ static void opt_qdiff(const char *arg) if (video_qdiff < 0 || video_qdiff > 31) { fprintf(stderr, "qdiff must be >= 1 and <= 31\n"); - exit(1); + av_exit(1); } } @@ -2458,14 +2512,16 @@ static void opt_thread_count(const char *arg) #endif } -static void opt_audio_rate(const char *arg) +static int opt_audio_rate(const char *opt, const char *arg) { - audio_sample_rate = atoi(arg); + audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); + return 0; } -static void opt_audio_channels(const char *arg) +static int opt_audio_channels(const char *opt, const char *arg) { - audio_channels = atoi(arg); + audio_channels = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); + return 0; } static void opt_video_channel(const char *arg) @@ -2530,7 +2586,7 @@ static void add_frame_hooker(const char *arg) if (i != 0) { fprintf(stderr, "Failed to add video hook function: %s\n", arg); - exit(1); + av_exit(1); } } #endif @@ -2583,35 +2639,28 @@ static void opt_map_meta_data(const char *arg) m->in_file = strtol(p, &p, 0); } -static int64_t parse_time_or_die(const char *timestr, int is_duration) +static int opt_recording_time(const char *opt, const char *arg) { - int64_t us = parse_date(timestr, is_duration); - if (us == INT64_MIN) { - fprintf(stderr, "Invalid %s specification: %s\n", - is_duration ? "duration" : "date", timestr); - exit(1); - } - return us; -} - -static void opt_recording_time(const char *arg) -{ - recording_time = parse_time_or_die(arg, 1); + recording_time = parse_time_or_die(opt, arg, 1); + return 0; } -static void opt_start_time(const char *arg) +static int opt_start_time(const char *opt, const char *arg) { - start_time = parse_time_or_die(arg, 1); + start_time = parse_time_or_die(opt, arg, 1); + return 0; } -static void opt_rec_timestamp(const char *arg) +static int opt_rec_timestamp(const char *opt, const char *arg) { - rec_timestamp = parse_time_or_die(arg, 0) / 1000000; + rec_timestamp = parse_time_or_die(opt, arg, 0) / 1000000; + return 0; } -static void opt_input_ts_offset(const char *arg) +static int opt_input_ts_offset(const char *opt, const char *arg) { - input_ts_offset = parse_time_or_die(arg, 1); + input_ts_offset = parse_time_or_die(opt, arg, 1); + return 0; } static enum CodecID find_codec_or_die(const char *name, int type, int encoder) @@ -2626,11 +2675,11 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder) avcodec_find_decoder_by_name(name); if(!codec) { av_log(NULL, AV_LOG_ERROR, "Unknown %s '%s'\n", codec_string, name); - exit(1); + av_exit(1); } if(codec->type != type) { av_log(NULL, AV_LOG_ERROR, "Invalid %s type '%s'\n", codec_string, name); - exit(1); + av_exit(1); } return codec->id; } @@ -2683,7 +2732,7 @@ static void opt_input_file(const char *filename) err = av_open_input_file(&ic, filename, file_iformat, 0, ap); if (err < 0) { print_error(filename, err); - exit(1); + av_exit(1); } if(opt_programid) { int i; @@ -2699,7 +2748,7 @@ static void opt_input_file(const char *filename) ret = av_find_stream_info(ic); if (ret < 0 && verbose >= 0) { fprintf(stderr, "%s: could not find codec parameters\n", filename); - exit(1); + av_exit(1); } timestamp = start_time; @@ -2854,7 +2903,7 @@ static void new_video_stream(AVFormatContext *oc) st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); - exit(1); + av_exit(1); } avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO); bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters; @@ -2956,7 +3005,7 @@ static void new_video_stream(AVFormatContext *oc) int e=sscanf(p, "%d,%d,%d", &start, &end, &q); if(e!=3){ fprintf(stderr, "error parsing rc_override\n"); - exit(1); + av_exit(1); } video_enc->rc_override= av_realloc(video_enc->rc_override, @@ -3009,7 +3058,7 @@ static void new_audio_stream(AVFormatContext *oc) st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); - exit(1); + av_exit(1); } avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO); @@ -3078,7 +3127,7 @@ static void new_subtitle_stream(AVFormatContext *oc) st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); - exit(1); + av_exit(1); } avcodec_get_context_defaults2(st->codec, CODEC_TYPE_SUBTITLE); @@ -3116,7 +3165,7 @@ static void opt_new_audio_stream(void) AVFormatContext *oc; if (nb_output_files <= 0) { fprintf(stderr, "At least one output file must be specified\n"); - exit(1); + av_exit(1); } oc = output_files[nb_output_files - 1]; new_audio_stream(oc); @@ -3127,7 +3176,7 @@ static void opt_new_video_stream(void) AVFormatContext *oc; if (nb_output_files <= 0) { fprintf(stderr, "At least one output file must be specified\n"); - exit(1); + av_exit(1); } oc = output_files[nb_output_files - 1]; new_video_stream(oc); @@ -3138,7 +3187,7 @@ static void opt_new_subtitle_stream(void) AVFormatContext *oc; if (nb_output_files <= 0) { fprintf(stderr, "At least one output file must be specified\n"); - exit(1); + av_exit(1); } oc = output_files[nb_output_files - 1]; new_subtitle_stream(oc); @@ -3161,7 +3210,7 @@ static void opt_output_file(const char *filename) if (!file_oformat) { fprintf(stderr, "Unable to find a suitable output format for '%s'\n", filename); - exit(1); + av_exit(1); } } @@ -3174,7 +3223,7 @@ static void opt_output_file(const char *filename) parameters from ffserver */ if (read_ffserver_streams(oc, filename) < 0) { fprintf(stderr, "Could not read stream parameters from '%s'\n", filename); - exit(1); + av_exit(1); } } else { use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; @@ -3239,7 +3288,7 @@ static void opt_output_file(const char *filename) if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(oc->filename)) { print_error(oc->filename, AVERROR_NUMEXPECTED); - exit(1); + av_exit(1); } } @@ -3258,12 +3307,12 @@ static void opt_output_file(const char *filename) c = getchar(); if (toupper(c) != 'Y') { fprintf(stderr, "Not overwriting - exiting\n"); - exit(1); + av_exit(1); } } else { fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); - exit(1); + av_exit(1); } } } @@ -3271,7 +3320,7 @@ static void opt_output_file(const char *filename) /* open the file */ if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) { fprintf(stderr, "Could not open '%s'\n", filename); - exit(1); + av_exit(1); } } @@ -3279,7 +3328,7 @@ static void opt_output_file(const char *filename) if (av_set_parameters(oc, ap) < 0) { fprintf(stderr, "%s: Invalid encoding parameters\n", oc->filename); - exit(1); + av_exit(1); } oc->preload= (int)(mux_preload*AV_TIME_BASE); @@ -3306,7 +3355,7 @@ static void opt_pass(const char *pass_str) pass = atoi(pass_str); if (pass != 1 && pass != 2) { fprintf(stderr, "pass number can be only 1 or 2\n"); - exit(1); + av_exit(1); } do_pass = pass; } @@ -3329,129 +3378,6 @@ static int64_t getutime(void) #endif } -static void opt_show_formats(void) -{ - AVInputFormat *ifmt=NULL; - AVOutputFormat *ofmt=NULL; - URLProtocol *up=NULL; - AVCodec *p=NULL, *p2; - AVBitStreamFilter *bsf=NULL; - const char *last_name; - - printf("File formats:\n"); - last_name= "000"; - for(;;){ - int decode=0; - int encode=0; - const char *name=NULL; - const char *long_name=NULL; - - while((ofmt= av_oformat_next(ofmt))) { - if((name == NULL || strcmp(ofmt->name, name)<0) && - strcmp(ofmt->name, last_name)>0){ - name= ofmt->name; - long_name= ofmt->long_name; - encode=1; - } - } - while((ifmt= av_iformat_next(ifmt))) { - if((name == NULL || strcmp(ifmt->name, name)<0) && - strcmp(ifmt->name, last_name)>0){ - name= ifmt->name; - long_name= ifmt->long_name; - encode=0; - } - if(name && strcmp(ifmt->name, name)==0) - decode=1; - } - if(name==NULL) - break; - last_name= name; - - printf( - " %s%s %-15s %s\n", - decode ? "D":" ", - encode ? "E":" ", - name, - long_name ? long_name:" "); - } - printf("\n"); - - printf("Codecs:\n"); - last_name= "000"; - for(;;){ - int decode=0; - int encode=0; - int cap=0; - const char *type_str; - - p2=NULL; - while((p= av_codec_next(p))) { - if((p2==NULL || strcmp(p->name, p2->name)<0) && - strcmp(p->name, last_name)>0){ - p2= p; - decode= encode= cap=0; - } - if(p2 && strcmp(p->name, p2->name)==0){ - if(p->decode) decode=1; - if(p->encode) encode=1; - cap |= p->capabilities; - } - } - if(p2==NULL) - break; - last_name= p2->name; - - switch(p2->type) { - case CODEC_TYPE_VIDEO: - type_str = "V"; - break; - case CODEC_TYPE_AUDIO: - type_str = "A"; - break; - case CODEC_TYPE_SUBTITLE: - type_str = "S"; - break; - default: - type_str = "?"; - break; - } - printf( - " %s%s%s%s%s%s %s", - decode ? "D": (/*p2->decoder ? "d":*/" "), - encode ? "E":" ", - type_str, - cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ", - cap & CODEC_CAP_DR1 ? "D":" ", - cap & CODEC_CAP_TRUNCATED ? "T":" ", - p2->name); - /* if(p2->decoder && decode==0) - printf(" use %s for decoding", p2->decoder->name);*/ - printf("\n"); - } - printf("\n"); - - printf("Bitstream filters:\n"); - while((bsf = av_bitstream_filter_next(bsf))) - printf(" %s", bsf->name); - printf("\n"); - - printf("Supported file protocols:\n"); - while((up = av_protocol_next(up))) - printf(" %s:", up->name); - printf("\n"); - - printf("Frame size, frame rate abbreviations:\n ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n"); - printf("\n"); - printf( -"Note, the names of encoders and decoders do not always match, so there are\n" -"several cases where the above table shows encoder only or decoder only entries\n" -"even though both encoding and decoding are supported. For example, the h263\n" -"decoder corresponds to the h263 and h263p encoders, for file formats it is even\n" -"worse.\n"); - exit(0); -} - static void parse_matrix_coeffs(uint16_t *dest, const char *str) { int i; @@ -3463,7 +3389,7 @@ static void parse_matrix_coeffs(uint16_t *dest, const char *str) p = strchr(p, ','); if(!p) { fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i); - exit(1); + av_exit(1); } p++; } @@ -3524,12 +3450,6 @@ static void show_help(void) av_opt_show(sws_opts, NULL); } -static void opt_show_help(void) -{ - show_help(); - exit(0); -} - static void opt_target(const char *arg) { int norm = -1; @@ -3583,7 +3503,7 @@ static void opt_target(const char *arg) fprintf(stderr, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n"); fprintf(stderr, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n"); fprintf(stderr, "or set a framerate with \"-r xxx\".\n"); - exit(1); + av_exit(1); } if(!strcmp(arg, "vcd")) { @@ -3671,7 +3591,7 @@ static void opt_target(const char *arg) } else { fprintf(stderr, "Unknown target: %s\n", arg); - exit(1); + av_exit(1); } } @@ -3699,7 +3619,7 @@ static int opt_bsf(const char *opt, const char *arg) if(!bsfc){ fprintf(stderr, "Unknown bitstream filter %s\n", arg); - exit(1); + av_exit(1); } bsfp= *opt == 'v' ? &video_bitstream_filters : @@ -3713,35 +3633,23 @@ static int opt_bsf(const char *opt, const char *arg) return 0; } -static void opt_show_license(void) -{ - show_license(); - exit(0); -} - -static void opt_show_version(void) -{ - show_version(program_name); - exit(0); -} - -const OptionDef options[] = { +static const OptionDef options[] = { /* main options */ - { "L", 0, {(void*)opt_show_license}, "show license" }, - { "h", 0, {(void*)opt_show_help}, "show help" }, - { "version", 0, {(void*)opt_show_version}, "show version" }, - { "formats", 0, {(void*)opt_show_formats}, "show available formats, codecs, protocols, ..." }, + { "L", OPT_EXIT, {(void*)show_license}, "show license" }, + { "h", OPT_EXIT, {(void*)show_help}, "show help" }, + { "version", OPT_EXIT, {(void*)show_version}, "show version" }, + { "formats", OPT_EXIT, {(void*)show_formats}, "show available formats, codecs, protocols, ..." }, { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" }, { "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" }, { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" }, { "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream[:syncfile:syncstream]" }, { "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "set meta data information of outfile from infile", "outfile:infile" }, - { "t", HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" }, + { "t", OPT_FUNC2 | HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" }, { "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, // - { "ss", HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" }, - { "itsoffset", HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" }, + { "ss", OPT_FUNC2 | HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" }, + { "itsoffset", OPT_FUNC2 | HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" }, { "title", HAS_ARG | OPT_STRING, {(void*)&str_title}, "set the title", "string" }, - { "timestamp", HAS_ARG, {(void*)&opt_rec_timestamp}, "set the timestamp", "time" }, + { "timestamp", OPT_FUNC2 | HAS_ARG, {(void*)&opt_rec_timestamp}, "set the timestamp", "time" }, { "author", HAS_ARG | OPT_STRING, {(void*)&str_author}, "set the author", "string" }, { "copyright", HAS_ARG | OPT_STRING, {(void*)&str_copyright}, "set the copyright", "string" }, { "comment", HAS_ARG | OPT_STRING, {(void*)&str_comment}, "set the comment", "string" }, @@ -3756,21 +3664,21 @@ const OptionDef options[] = { { "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" }, { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" }, { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" }, - { "v", HAS_ARG, {(void*)opt_verbose}, "control amount of logging", "verbose" }, + { "v", HAS_ARG | OPT_FUNC2, {(void*)opt_verbose}, "set the logging verbosity level", "number" }, { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" }, { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" }, { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" }, { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" }, - { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "" }, + { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "threshold" }, { "vglobal", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_global_header}, "video global header storage type", "" }, { "copyts", OPT_BOOL | OPT_EXPERT, {(void*)©_ts}, "copy timestamps" }, { "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, // - { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "" }, + { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "threshold" }, { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" }, /* video options */ - { "b", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" }, - { "vb", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" }, + { "b", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, + { "vb", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, { "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[CODEC_TYPE_VIDEO]}, "set the number of video frames to record", "number" }, { "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[CODEC_TYPE_DATA]}, "set the number of data frames to record", "number" }, { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, @@ -3793,7 +3701,7 @@ const OptionDef options[] = { { "qdiff", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qdiff}, "max difference between the quantizer scale (VBR)", "q" }, { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" }, { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" }, - { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "" }, + { "me_threshold", HAS_ARG | OPT_FUNC2 | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "threshold" }, { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to follow the standards", "strictness" }, { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality}, "use same video quality as source (implies VBR)" }, @@ -3816,11 +3724,11 @@ const OptionDef options[] = { { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, /* audio options */ - { "ab", OPT_FUNC2 | HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" }, + { "ab", OPT_FUNC2 | HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "bitrate" }, { "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[CODEC_TYPE_AUDIO]}, "set the number of audio frames to record", "number" }, { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", }, - { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" }, - { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" }, + { "ar", HAS_ARG | OPT_FUNC2 | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" }, + { "ac", HAS_ARG | OPT_FUNC2 | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" }, { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" }, { "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" }, { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_audio_tag}, "force audio tag/fourcc", "fourcc/tag" }, @@ -3851,59 +3759,6 @@ const OptionDef options[] = { { NULL, }, }; -static int av_exit() -{ - int i; - - /* close files */ - for(i=0;ioformat->flags & AVFMT_NOFILE)) - url_fclose(s->pb); - for(j=0;jnb_streams;j++) { - av_free(s->streams[j]->codec); - av_free(s->streams[j]); - } - av_free(s); - } - for(i=0;i