X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg.c;h=f428ba55501754f11b125a8572f3a82e81b5d6b0;hb=0dac708e2d31898ebccacdb5911b5496b1616989;hp=516156511069594f3c3a68849ad02e3ea32f80a2;hpb=8767060cd2e5f9a29251f90b98b0f0cdafad93ef;p=ffmpeg diff --git a/ffmpeg.c b/ffmpeg.c index 51615651106..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 @@ -61,7 +63,7 @@ #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 */ @@ -78,7 +80,7 @@ typedef struct AVMetaDataMap { int in_file; } AVMetaDataMap; -extern const OptionDef options[]; +static const OptionDef options[]; #define MAX_FILES 20 @@ -1064,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) @@ -2224,15 +2226,17 @@ 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) @@ -2425,7 +2429,7 @@ static void opt_frame_pad_right(const char *arg) } } -void list_pix_fmts(void) +static void list_pix_fmts(void) { int i; char pix_fmt_str[128]; @@ -2508,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) @@ -3372,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"); - av_exit(0); -} - static void parse_matrix_coeffs(uint16_t *dest, const char *str) { int i; @@ -3567,12 +3450,6 @@ static void show_help(void) av_opt_show(sws_opts, NULL); } -static void opt_show_help(void) -{ - show_help(); - av_exit(0); -} - static void opt_target(const char *arg) { int norm = -1; @@ -3756,24 +3633,12 @@ static int opt_bsf(const char *opt, const char *arg) return 0; } -static void opt_show_license(void) -{ - show_license(); - av_exit(0); -} - -static void opt_show_version(void) -{ - show_version(program_name); - av_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" }, @@ -3799,7 +3664,7 @@ 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}, "set the logging verbosity level", "number" }, + { "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", "" }, @@ -3836,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", "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)" }, @@ -3862,8 +3727,8 @@ const OptionDef options[] = { { "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" },