From d162994a81a311a8dd212a50a2d2ad2b088df97f Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sat, 10 Sep 2011 10:23:50 -0400 Subject: [PATCH 01/31] doc: explain __STDC_CONSTANT_MACROS in C++ In order to build C++ programs using libav you need -D__STDC_CONSTANT_MACROS appened to the CXXFLAGS. --- doc/faq.texi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/faq.texi b/doc/faq.texi index 42a135c429..affe88b813 100644 --- a/doc/faq.texi +++ b/doc/faq.texi @@ -440,6 +440,11 @@ encompassing your Libav includes using @code{extern "C"}. See @url{http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.3} +@section I'm using libavutil from within my C++ application but the compiler complains about 'UINT64_C' was not declared in this scope + +Libav is a pure C project using C99 math features, in order to enable C++ +to use them you have to append -D__STDC_CONSTANT_MACROS to your CXXFLAGS + @section I have a file in memory / a API different from *open/*read/ libc how do I use it with libavformat? You have to implement a URLProtocol, see @file{libavformat/file.c} in From 162f1fbc147bbff6e23b4df1e587cec5d5111052 Mon Sep 17 00:00:00 2001 From: Aviad Rozenhek Date: Thu, 8 Sep 2011 16:18:48 +0300 Subject: [PATCH 02/31] mpegts: on seek, reset the cc for all PIDs Prevent false positive continuity counter error logs. Signed-off-by: Luca Barbato --- libavformat/mpegts.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index a72341865f..41a685c2bb 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1410,12 +1410,14 @@ static int handle_packets(MpegTSContext *ts, int nb_packets) av_dlog("Skipping after seek\n"); /* seek detected, flush pes buffer */ for (i = 0; i < NB_PID_MAX; i++) { - if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) { - PESContext *pes = ts->pids[i]->u.pes_filter.opaque; - av_freep(&pes->buffer); + if (ts->pids[i]) { + if (ts->pids[i]->type == MPEGTS_PES) { + PESContext *pes = ts->pids[i]->u.pes_filter.opaque; + av_freep(&pes->buffer); + pes->data_index = 0; + pes->state = MPEGTS_SKIP; /* skip until pes header */ + } ts->pids[i]->last_cc = -1; - pes->data_index = 0; - pes->state = MPEGTS_SKIP; /* skip until pes header */ } } } From f1f15c3c1a813c86e669aeb58a07c10d9cc21893 Mon Sep 17 00:00:00 2001 From: Georgi Chorbadzhiyski Date: Thu, 8 Sep 2011 20:38:48 +0300 Subject: [PATCH 03/31] mpegts: improve error reporting When reporting continuity error show pid, expected and received cc. Signed-off-by: Luca Barbato --- libavformat/mpegts.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 41a685c2bb..16f69328a0 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1292,7 +1292,9 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) tss->last_cc = cc; if (!cc_ok) { - av_log(ts->stream, AV_LOG_WARNING, "Continuity Check Failed\n"); + av_log(ts->stream, AV_LOG_WARNING, + "Continuity check failed for pid %d expected %d got %d\n", + pid, expected_cc, cc); if(tss->type == MPEGTS_PES) { PESContext *pc = tss->u.pes_filter.opaque; pc->flags |= AV_PKT_FLAG_CORRUPT; From 05bffc12c4faff47aabe08bafe44ee3b31ed5b47 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 31 Aug 2011 08:51:15 +0200 Subject: [PATCH 04/31] avconv: move audio_sample_fmt to options context. Also document it and replace undocumented and inconsistent '-sample_fmt list' syntax with -sample_fmts. --- avconv.c | 36 ++++++++++++------------------------ cmdutils.c | 9 +++++++++ cmdutils.h | 6 ++++++ cmdutils_common_opts.h | 1 + doc/avconv.texi | 3 +++ doc/fftools-common-opts.texi | 3 +++ 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/avconv.c b/avconv.c index cfb231907b..a02d36bb30 100644 --- a/avconv.c +++ b/avconv.c @@ -105,7 +105,6 @@ static int frame_width = 0; static int frame_height = 0; static float frame_aspect_ratio = 0; static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; -static enum AVSampleFormat audio_sample_fmt = AV_SAMPLE_FMT_NONE; static AVRational frame_rate; static float video_qscale = 0; static uint16_t *intra_matrix = NULL; @@ -320,6 +319,8 @@ typedef struct OptionsContext { int nb_bitstream_filters; SpecifierOpt *codec_tags; int nb_codec_tags; + SpecifierOpt *sample_fmts; + int nb_sample_fmts; } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -2572,24 +2573,6 @@ static int opt_top_field_first(const char *opt, const char *arg) return 0; } -static int opt_audio_sample_fmt(const char *opt, const char *arg) -{ - if (strcmp(arg, "list")) { - audio_sample_fmt = av_get_sample_fmt(arg); - if (audio_sample_fmt == AV_SAMPLE_FMT_NONE) { - av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg); - return AVERROR(EINVAL); - } - } else { - int i; - char fmt_str[128]; - for (i = -1; i < AV_SAMPLE_FMT_NB; i++) - printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i)); - exit_program(0); - } - return 0; -} - static int opt_audio_rate(const char *opt, const char *arg) { audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); @@ -2994,7 +2977,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena frame_height = 0; frame_width = 0; audio_sample_rate = 0; - audio_sample_fmt = AV_SAMPLE_FMT_NONE; for (i = 0; i < orig_nb_streams; i++) av_dict_free(&opts[i]); @@ -3204,14 +3186,21 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc) audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; } if (!st->stream_copy) { + char *sample_fmt = NULL; + if (audio_qscale > QSCALE_NONE) { audio_enc->flags |= CODEC_FLAG_QSCALE; audio_enc->global_quality = FF_QP2LAMBDA * audio_qscale; } MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st); - if (audio_sample_fmt != AV_SAMPLE_FMT_NONE) - audio_enc->sample_fmt = audio_sample_fmt; + MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st); + if (sample_fmt && + (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) { + av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", sample_fmt); + exit_program(1); + } + if (audio_sample_rate) audio_enc->sample_rate = audio_sample_rate; } @@ -3642,7 +3631,6 @@ static void opt_output_file(void *optctx, const char *filename) frame_width = 0; frame_height = 0; audio_sample_rate = 0; - audio_sample_fmt = AV_SAMPLE_FMT_NONE; av_freep(&streamid_map); nb_streamid_map = 0; @@ -4079,7 +4067,7 @@ static const OptionDef options[] = { { "acodec", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" }, { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_tag}, "force audio tag/fourcc", "fourcc/tag" }, { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, // - { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_audio_sample_fmt}, "set sample format, 'list' as argument shows all the sample formats supported", "format" }, + { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_SPEC | OPT_STRING, {.off = OFFSET(sample_fmts)}, "set sample format", "format" }, /* subtitle options */ { "sn", OPT_BOOL | OPT_SUBTITLE | OPT_OFFSET, {.off = OFFSET(subtitle_disable)}, "disable subtitle" }, diff --git a/cmdutils.c b/cmdutils.c index 52ec96f951..2aab395a96 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -717,6 +717,15 @@ void show_pix_fmts(void) } } +int show_sample_fmts(const char *opt, const char *arg) +{ + int i; + char fmt_str[128]; + for (i = -1; i < AV_SAMPLE_FMT_NB; i++) + printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i)); + return 0; +} + int read_yesno(void) { int c = getchar(); diff --git a/cmdutils.h b/cmdutils.h index 989d769dfe..dc19486834 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -277,6 +277,12 @@ void show_protocols(void); */ void show_pix_fmts(void); +/** + * Print a listing containing all the sample formats supported by the + * program. + */ +int show_sample_fmts(const char *opt, const char *arg); + /** * Return a positive value if a line read from standard input * starts with [yY], otherwise return 0. diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index 9b5e5d22cd..36b2e322e5 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -10,4 +10,5 @@ { "protocols", OPT_EXIT, {(void*)show_protocols}, "show available protocols" }, { "filters", OPT_EXIT, {(void*)show_filters }, "show available filters" }, { "pix_fmts" , OPT_EXIT, {(void*)show_pix_fmts }, "show available pixel formats" }, + { "sample_fmts", OPT_EXIT, {.func_arg = show_sample_fmts }, "show available audio sample formats" }, { "loglevel", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" }, diff --git a/doc/avconv.texi b/doc/avconv.texi index 827e0f94e5..d9c1461674 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -590,6 +590,9 @@ and is mapped to the corresponding demuxer options. Disable audio recording. @item -acodec @var{codec} Set the audio codec. This is an alias for @code{-codec:a}. +@item -sample_fmt[:@var{stream_specifier}] @var{sample_fmt} +Set the audio sample format. Use @code{-help sample_fmts} to get a list +of supported sample formats. @end table @section Advanced Audio options: diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index 8ffc3299ce..91e1ed7969 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -68,6 +68,9 @@ Show available libavfilter filters. @item -pix_fmts Show available pixel formats. +@item -sample_fmts +Show available sample formats. + @item -loglevel @var{loglevel} Set the logging level used by the library. @var{loglevel} is a number or a string containing one of the following values: From 2c474ddbc5b90541ea4a65961490b6469d12529f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 31 Aug 2011 22:24:06 +0200 Subject: [PATCH 05/31] cmdutils: add support for programs in check_stream_specifier() Remove now redundant (and broken/undocumented) opt_programid. --- avconv.c | 44 +++++++++++++++++--------------------------- cmdutils.c | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/avconv.c b/avconv.c index a02d36bb30..984c263d0c 100644 --- a/avconv.c +++ b/avconv.c @@ -140,7 +140,6 @@ static int copy_tb; static int opt_shortest = 0; static char *vstats_filename; static FILE *vstats_file; -static int opt_programid = 0; static int copy_initial_nonkeyframes = 0; static int audio_volume = 256; @@ -1892,7 +1891,7 @@ static int transcode_init(OutputFile *output_files, InputFile *input_files, int nb_input_files) { - int ret = 0, i, j; + int ret = 0, i, j, k; AVFormatContext *os; AVCodecContext *codec, *icodec; OutputStream *ost; @@ -2190,6 +2189,22 @@ static int transcode_init(OutputFile *output_files, if ((ret = init_input_stream(i, output_streams, nb_output_streams, error, sizeof(error))) < 0) goto dump_format; + /* discard unused programs */ + for (i = 0; i < nb_input_files; i++) { + InputFile *ifile = &input_files[i]; + for (j = 0; j < ifile->ctx->nb_programs; j++) { + AVProgram *p = ifile->ctx->programs[j]; + int discard = AVDISCARD_ALL; + + for (k = 0; k < p->nb_stream_indexes; k++) + if (!input_streams[ifile->ist_index + p->stream_index[k]].discard) { + discard = AVDISCARD_DEFAULT; + break; + } + p->discard = discard; + } + } + /* open files and write file headers */ for (i = 0; i < nb_output_files; i++) { os = output_files[i].ctx; @@ -2904,30 +2919,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena } assert_avoptions(format_opts); - if(opt_programid) { - int i, j; - int found=0; - for(i=0; inb_streams; i++){ - ic->streams[i]->discard= AVDISCARD_ALL; - } - for(i=0; inb_programs; i++){ - AVProgram *p= ic->programs[i]; - if(p->id != opt_programid){ - p->discard = AVDISCARD_ALL; - }else{ - found=1; - for(j=0; jnb_stream_indexes; j++){ - ic->streams[p->stream_index[j]]->discard= AVDISCARD_DEFAULT; - } - } - } - if(!found){ - fprintf(stderr, "Specified program id not found\n"); - exit_program(1); - } - opt_programid=0; - } - /* apply forced codec ids */ for (i = 0; i < ic->nb_streams; i++) choose_codec(o, ic, ic->streams[i], ic->streams[i]->codec->codec_type); @@ -4018,7 +4009,6 @@ static const OptionDef options[] = { { "copytb", OPT_BOOL | OPT_EXPERT, {(void*)©_tb}, "copy input stream time base when stream copying" }, { "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", "threshold" }, - { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" }, { "xerror", OPT_BOOL, {(void*)&exit_on_error}, "exit on error", "error" }, { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)©_initial_nonkeyframes}, "copy initial non-keyframes" }, { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, {.off = OFFSET(max_frames)}, "set the number of frames to record", "number" }, diff --git a/cmdutils.c b/cmdutils.c index 2aab395a96..16b64aff23 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -841,6 +841,26 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) return 0; } return 1; + } else if (*spec == 'p' && *(spec + 1) == ':') { + int prog_id, i, j; + char *endptr; + spec += 2; + prog_id = strtol(spec, &endptr, 0); + for (i = 0; i < s->nb_programs; i++) { + if (s->programs[i]->id != prog_id) + continue; + + if (*endptr++ == ':') { + int stream_idx = strtol(endptr, NULL, 0); + return (stream_idx >= 0 && stream_idx < s->programs[i]->nb_stream_indexes && + st->index == s->programs[i]->stream_index[stream_idx]); + } + + for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) + if (st->index == s->programs[i]->stream_index[j]) + return 1; + } + return 0; } else if (!*spec) /* empty specifier, matches everything */ return 1; From e2469ccf01ced9d4520dcc1fb987fc73a2045066 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Sep 2011 08:20:50 +0200 Subject: [PATCH 06/31] avconv: move audio_sample_rate to the options context. --- avconv.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/avconv.c b/avconv.c index 984c263d0c..fc8a29a70f 100644 --- a/avconv.c +++ b/avconv.c @@ -121,7 +121,6 @@ static int qp_hist = 0; static char *vfilters = NULL; #endif -static int audio_sample_rate = 0; #define QSCALE_NONE -99999 static float audio_qscale = QSCALE_NONE; @@ -280,6 +279,8 @@ typedef struct OptionsContext { int nb_codec_names; SpecifierOpt *audio_channels; int nb_audio_channels; + SpecifierOpt *audio_sample_rate; + int nb_audio_sample_rate; /* input options */ int64_t input_ts_offset; @@ -2588,12 +2589,6 @@ static int opt_top_field_first(const char *opt, const char *arg) return 0; } -static int opt_audio_rate(const char *opt, const char *arg) -{ - audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); - return 0; -} - static int opt_audio_codec(OptionsContext *o, const char *opt, const char *arg) { return parse_option(o, "codec:a", arg, options); @@ -2890,8 +2885,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena print_error(filename, AVERROR(ENOMEM)); exit_program(1); } - if (audio_sample_rate) { - snprintf(buf, sizeof(buf), "%d", audio_sample_rate); + if (o->nb_audio_sample_rate) { + snprintf(buf, sizeof(buf), "%d", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i); av_dict_set(&format_opts, "sample_rate", buf, 0); } if (o->nb_audio_channels) { @@ -2967,7 +2962,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena frame_pix_fmt = PIX_FMT_NONE; frame_height = 0; frame_width = 0; - audio_sample_rate = 0; for (i = 0; i < orig_nb_streams; i++) av_dict_free(&opts[i]); @@ -3192,8 +3186,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc) exit_program(1); } - if (audio_sample_rate) - audio_enc->sample_rate = audio_sample_rate; + MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st); } return ost; @@ -3621,7 +3614,6 @@ static void opt_output_file(void *optctx, const char *filename) frame_rate = (AVRational){0, 0}; frame_width = 0; frame_height = 0; - audio_sample_rate = 0; av_freep(&streamid_map); nb_streamid_map = 0; @@ -3850,7 +3842,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_default("bufsize", "327680"); // 40*1024*8; opt_default("b:a", "224000"); - audio_sample_rate = 44100; + parse_option(o, "ar", "44100", options); parse_option(o, "ac", "2", options); opt_default("packetsize", "2324"); @@ -3880,7 +3872,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_default("b:a", "224000"); - audio_sample_rate = 44100; + parse_option(o, "ar", "44100", options); opt_default("packetsize", "2324"); @@ -3903,7 +3895,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_default("muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8 opt_default("b:a", "448000"); - audio_sample_rate = 48000; + parse_option(o, "ar", "48000", options); } else if(!strncmp(arg, "dv", 2)) { @@ -3914,7 +3906,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) norm == PAL ? "yuv420p" : "yuv411p"); opt_frame_rate("r", frame_rates[norm]); - audio_sample_rate = 48000; + parse_option(o, "ar", "48000", options); parse_option(o, "ac", "2", options); } else { @@ -4051,7 +4043,7 @@ static const OptionDef options[] = { /* audio options */ { "aframes", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_frames}, "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" }, + { "ar", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_sample_rate)}, "set audio sampling rate (in Hz)", "rate" }, { "ac", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_channels)}, "set number of audio channels", "channels" }, { "an", OPT_BOOL | OPT_AUDIO | OPT_OFFSET, {.off = OFFSET(audio_disable)}, "disable audio" }, { "acodec", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" }, From 77d9c4542c129276fedefeca089c5759e5fe6353 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Sep 2011 10:04:35 +0200 Subject: [PATCH 07/31] avconv: rewrite -qscale and -aq handling. Merge video_qscale (set by -qscale) and audio_qscale (set by -aq) into one 'qscale' field in the options context. Add a shortcut -q for -qscale and make -aq an alias for -q:a. --- avconv.c | 42 ++++++++++++++++------------------------ doc/avconv.texi | 9 ++++++--- tests/lavf-regression.sh | 2 +- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/avconv.c b/avconv.c index fc8a29a70f..347b47672e 100644 --- a/avconv.c +++ b/avconv.c @@ -106,7 +106,6 @@ static int frame_height = 0; static float frame_aspect_ratio = 0; static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; static AVRational frame_rate; -static float video_qscale = 0; static uint16_t *intra_matrix = NULL; static uint16_t *inter_matrix = NULL; static const char *video_rc_override_string=NULL; @@ -121,9 +120,6 @@ static int qp_hist = 0; static char *vfilters = NULL; #endif -#define QSCALE_NONE -99999 -static float audio_qscale = QSCALE_NONE; - static int file_overwrite = 0; static int do_benchmark = 0; static int do_hex_dump = 0; @@ -321,6 +317,8 @@ typedef struct OptionsContext { int nb_codec_tags; SpecifierOpt *sample_fmts; int nb_sample_fmts; + SpecifierOpt *qscale; + int nb_qscale; } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -2573,16 +2571,6 @@ static int opt_frame_aspect_ratio(const char *opt, const char *arg) return 0; } -static int opt_qscale(const char *opt, const char *arg) -{ - video_qscale = parse_number_or_die(opt, arg, OPT_FLOAT, 0, 255); - if (video_qscale == 0) { - fprintf(stderr, "qscale must be > 0.0 and <= 255\n"); - return AVERROR(EINVAL); - } - return 0; -} - static int opt_top_field_first(const char *opt, const char *arg) { top_field_first = parse_number_or_die(opt, arg, OPT_INT, 0, 1); @@ -3002,6 +2990,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e int64_t max_frames = INT64_MAX; char *bsf = NULL, *next, *codec_tag = NULL; AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL; + double qscale = -1; if (!st) { av_log(NULL, AV_LOG_ERROR, "Could not alloc stream.\n"); @@ -3051,6 +3040,12 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e st->codec->codec_tag = tag; } + MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st); + if (qscale >= 0 || same_quant) { + st->codec->flags |= CODEC_FLAG_QSCALE; + st->codec->global_quality = FF_QP2LAMBDA * qscale; + } + ost->sws_flags = av_get_int(sws_opts, "sws_flags", NULL); return ost; } @@ -3093,11 +3088,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) video_enc->pix_fmt = frame_pix_fmt; st->sample_aspect_ratio = video_enc->sample_aspect_ratio; - if (video_qscale || same_quant) { - video_enc->flags |= CODEC_FLAG_QSCALE; - video_enc->global_quality = FF_QP2LAMBDA * video_qscale; - } - if(intra_matrix) video_enc->intra_matrix = intra_matrix; if(inter_matrix) @@ -3173,10 +3163,6 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc) if (!st->stream_copy) { char *sample_fmt = NULL; - if (audio_qscale > QSCALE_NONE) { - audio_enc->flags |= CODEC_FLAG_QSCALE; - audio_enc->global_quality = FF_QP2LAMBDA * audio_qscale; - } MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st); MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st); @@ -3694,6 +3680,11 @@ static void opt_intra_matrix(const char *arg) parse_matrix_coeffs(intra_matrix, arg); } +static int opt_audio_qscale(OptionsContext *o, const char *opt, const char *arg) +{ + return parse_option(o, "q:a", arg, options); +} + static void show_usage(void) { printf("Hyper fast Audio and Video encoder\n"); @@ -4005,6 +3996,8 @@ static const OptionDef options[] = { { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)©_initial_nonkeyframes}, "copy initial non-keyframes" }, { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, {.off = OFFSET(max_frames)}, "set the number of frames to record", "number" }, { "tag", OPT_STRING | HAS_ARG | OPT_SPEC, {.off = OFFSET(codec_tags)}, "force codec tag/fourcc", "fourcc/tag" }, + { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" }, + { "qscale", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" }, /* video options */ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" }, @@ -4014,7 +4007,6 @@ static const OptionDef options[] = { { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" }, { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(video_disable)}, "disable video" }, { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" }, - { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video 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 | OPT_FUNC2, {(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 estimation threshold", "threshold" }, @@ -4042,7 +4034,7 @@ static const OptionDef options[] = { /* audio options */ { "aframes", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_frames}, "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", }, + { "aq", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_qscale}, "set audio quality (codec-specific)", "quality", }, { "ar", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_sample_rate)}, "set audio sampling rate (in Hz)", "rate" }, { "ac", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_channels)}, "set number of audio channels", "channels" }, { "an", OPT_BOOL | OPT_AUDIO | OPT_OFFSET, {.off = OFFSET(audio_disable)}, "disable audio" }, diff --git a/doc/avconv.texi b/doc/avconv.texi index d9c1461674..62f21f05e4 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -205,6 +205,11 @@ Set the number of data frames to record. This is an alias for @code{-frames:d}. @item -frames[:stream_specifier] @var{framecount} Stop writing to the stream after @var{framecount} frames. +@item -q @var{q} +@item -qscale @var{q} +Use fixed quality scale (VBR). The meaning of @var{q} is +codec-dependent. + @end table @section Video Options @@ -354,8 +359,6 @@ Set SwScaler flags. Set the group of pictures size. @item -vdt @var{n} Discard threshold. -@item -qscale @var{q} -Use fixed video quantizer scale (VBR). @item -qmin @var{q} minimum video quantizer scale (VBR) @item -qmax @var{q} @@ -580,7 +583,7 @@ default to the frequency of the corresponding input stream. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. @item -aq @var{q} -Set the audio quality (codec-specific, VBR). +Set the audio quality (codec-specific, VBR). This is an alias for -q:a. @item -ac @var{channels} Set the number of audio channels. For output streams it is set by default to the number of input audio channels. For input streams diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index 303e7bd1ac..7cd9f7f909 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -14,7 +14,7 @@ eval do_$test=y do_lavf() { file=${outfile}lavf.$1 - do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale 10 $2 + do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2 do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3 } From 7c0296723ca6bc0ac59da4511d8f892e8742fdef Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Sep 2011 08:20:50 +0200 Subject: [PATCH 08/31] avconv: move forced_key_frames to the options context. --- avconv.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/avconv.c b/avconv.c index 347b47672e..1045fe0540 100644 --- a/avconv.c +++ b/avconv.c @@ -149,7 +149,6 @@ static int nb_frames_dup = 0; static int nb_frames_drop = 0; static int input_sync; static int force_fps = 0; -static char *forced_key_frames = NULL; static float dts_delta_threshold = 10; @@ -319,6 +318,8 @@ typedef struct OptionsContext { int nb_sample_fmts; SpecifierOpt *qscale; int nb_qscale; + SpecifierOpt *forced_key_frames; + int nb_forced_key_frames; } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -3078,6 +3079,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); } else { const char *p; + char *forced_key_frames = NULL; int i; if (frame_rate.num) @@ -3135,12 +3137,12 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) } } + MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st); if (forced_key_frames) parse_forced_key_frames(forced_key_frames, ost, video_enc); } /* reset some key parameters */ - av_freep(&forced_key_frames); frame_pix_fmt = PIX_FMT_NONE; return ost; } @@ -3604,7 +3606,6 @@ static void opt_output_file(void *optctx, const char *filename) av_freep(&streamid_map); nb_streamid_map = 0; - av_freep(&forced_key_frames); reset_options(o); } @@ -4030,7 +4031,7 @@ static const OptionDef options[] = { { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&force_fps}, "force the selected framerate, disable the best supported framerate selection" }, { "streamid", HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" }, - { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void *)&forced_key_frames}, "force key frames at specified timestamps", "timestamps" }, + { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(forced_key_frames)}, "force key frames at specified timestamps", "timestamps" }, /* audio options */ { "aframes", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_frames}, "set the number of audio frames to record", "number" }, From bef737a78a27a1710b6e072280711a0c28d8b77a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Sep 2011 08:20:50 +0200 Subject: [PATCH 09/31] avconv: move force_fps to the options context. --- avconv.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/avconv.c b/avconv.c index 1045fe0540..2b47439c8f 100644 --- a/avconv.c +++ b/avconv.c @@ -148,7 +148,6 @@ static int64_t extra_size = 0; static int nb_frames_dup = 0; static int nb_frames_drop = 0; static int input_sync; -static int force_fps = 0; static float dts_delta_threshold = 10; @@ -213,6 +212,7 @@ typedef struct OutputStream { int resample_width; int resample_pix_fmt; AVRational frame_rate; + int force_fps; float frame_aspect_ratio; @@ -320,6 +320,8 @@ typedef struct OptionsContext { int nb_qscale; SpecifierOpt *forced_key_frames; int nb_forced_key_frames; + SpecifierOpt *force_fps; + int nb_force_fps; } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -2086,7 +2088,7 @@ static int transcode_init(OutputFile *output_files, if (!ost->frame_rate.num) ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1}; - if (ost->enc && ost->enc->supported_framerates && !force_fps) { + if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) { int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); ost->frame_rate = ost->enc->supported_framerates[idx]; } @@ -3080,7 +3082,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) } else { const char *p; char *forced_key_frames = NULL; - int i; + int i, force_fps = 0; if (frame_rate.num) ost->frame_rate = frame_rate; @@ -3140,6 +3142,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st); if (forced_key_frames) parse_forced_key_frames(forced_key_frames, ost, video_enc); + + MATCH_PER_STREAM_OPT(force_fps, i, force_fps, oc, st); + ost->force_fps = force_fps; } /* reset some key parameters */ @@ -4029,7 +4034,7 @@ static const OptionDef options[] = { { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" }, { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" }, { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, - { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&force_fps}, "force the selected framerate, disable the best supported framerate selection" }, + { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(force_fps)}, "force the selected framerate, disable the best supported framerate selection" }, { "streamid", HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" }, { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(forced_key_frames)}, "force key frames at specified timestamps", "timestamps" }, From 91ea4811b34bcae4f51b6f320d52157128ab67d1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Sep 2011 08:20:50 +0200 Subject: [PATCH 10/31] avconv: move frame_rate to the options context. --- avconv.c | 81 ++++++++++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 49 deletions(-) diff --git a/avconv.c b/avconv.c index 2b47439c8f..2ef3d95c55 100644 --- a/avconv.c +++ b/avconv.c @@ -105,7 +105,6 @@ static int frame_width = 0; static int frame_height = 0; static float frame_aspect_ratio = 0; static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; -static AVRational frame_rate; static uint16_t *intra_matrix = NULL; static uint16_t *inter_matrix = NULL; static const char *video_rc_override_string=NULL; @@ -276,6 +275,8 @@ typedef struct OptionsContext { int nb_audio_channels; SpecifierOpt *audio_sample_rate; int nb_audio_sample_rate; + SpecifierOpt *frame_rates; + int nb_frame_rates; /* input options */ int64_t input_ts_offset; @@ -2516,15 +2517,6 @@ static int opt_verbose(const char *opt, const char *arg) return 0; } -static int opt_frame_rate(const char *opt, const char *arg) -{ - if (av_parse_video_rate(&frame_rate, arg) < 0) { - fprintf(stderr, "Incorrect value for %s: %s\n", opt, arg); - exit_program(1); - } - return 0; -} - static int opt_frame_size(const char *opt, const char *arg) { if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) { @@ -2884,9 +2876,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena snprintf(buf, sizeof(buf), "%d", o->audio_channels[o->nb_audio_channels - 1].u.i); av_dict_set(&format_opts, "channels", buf, 0); } - if (frame_rate.num) { - snprintf(buf, sizeof(buf), "%d/%d", frame_rate.num, frame_rate.den); - av_dict_set(&format_opts, "framerate", buf, 0); + if (o->nb_frame_rates) { + av_dict_set(&format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0); } if (frame_width && frame_height) { snprintf(buf, sizeof(buf), "%dx%d", frame_width, frame_height); @@ -2949,7 +2940,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena input_files[nb_input_files - 1].ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp); input_files[nb_input_files - 1].nb_streams = ic->nb_streams; - frame_rate = (AVRational){0, 0}; frame_pix_fmt = PIX_FMT_NONE; frame_height = 0; frame_width = 0; @@ -3081,11 +3071,14 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); } else { const char *p; - char *forced_key_frames = NULL; + char *forced_key_frames = NULL, *frame_rate = NULL; int i, force_fps = 0; - if (frame_rate.num) - ost->frame_rate = frame_rate; + MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); + if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) { + av_log(NULL, AV_LOG_ERROR, "Invalid framerate value: %s\n", frame_rate); + exit_program(1); + } video_enc->width = frame_width; video_enc->height = frame_height; @@ -3604,7 +3597,6 @@ static void opt_output_file(void *optctx, const char *filename) av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0); } - frame_rate = (AVRational){0, 0}; frame_width = 0; frame_height = 0; @@ -3783,34 +3775,25 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) norm = FILM; arg += 5; } else { - int fr; - /* Calculate FR via float to avoid int overflow */ - fr = (int)(frame_rate.num * 1000.0 / frame_rate.den); - if(fr == 25000) { - norm = PAL; - } else if((fr == 29970) || (fr == 23976)) { - norm = NTSC; - } else { - /* Try to determine PAL/NTSC by peeking in the input files */ - if(nb_input_files) { - int i, j; - for (j = 0; j < nb_input_files; j++) { - for (i = 0; i < input_files[j].nb_streams; i++) { - AVCodecContext *c = input_files[j].ctx->streams[i]->codec; - if(c->codec_type != AVMEDIA_TYPE_VIDEO) - continue; - fr = c->time_base.den * 1000 / c->time_base.num; - if(fr == 25000) { - norm = PAL; - break; - } else if((fr == 29970) || (fr == 23976)) { - norm = NTSC; - break; - } - } - if(norm != UNKNOWN) + /* Try to determine PAL/NTSC by peeking in the input files */ + if(nb_input_files) { + int i, j, fr; + for (j = 0; j < nb_input_files; j++) { + for (i = 0; i < input_files[j].nb_streams; i++) { + AVCodecContext *c = input_files[j].ctx->streams[i]->codec; + if(c->codec_type != AVMEDIA_TYPE_VIDEO) + continue; + fr = c->time_base.den * 1000 / c->time_base.num; + if(fr == 25000) { + norm = PAL; break; + } else if((fr == 29970) || (fr == 23976)) { + norm = NTSC; + break; + } } + if(norm != UNKNOWN) + break; } } if(verbose > 0 && norm != UNKNOWN) @@ -3830,7 +3813,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) parse_option(o, "f", "vcd", options); opt_frame_size("s", norm == PAL ? "352x288" : "352x240"); - opt_frame_rate("r", frame_rates[norm]); + parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "1150000"); @@ -3858,7 +3841,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) parse_option(o, "f", "svcd", options); opt_frame_size("s", norm == PAL ? "480x576" : "480x480"); - opt_frame_rate("r", frame_rates[norm]); + parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "2040000"); @@ -3880,7 +3863,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) parse_option(o, "f", "dvd", options); opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480"); - opt_frame_rate("r", frame_rates[norm]); + parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "6000000"); @@ -3901,7 +3884,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_frame_size("s", norm == PAL ? "720x576" : "720x480"); opt_frame_pix_fmt("pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" : norm == PAL ? "yuv420p" : "yuv411p"); - opt_frame_rate("r", frame_rates[norm]); + parse_option(o, "r", frame_rates[norm], options); parse_option(o, "ar", "48000", options); parse_option(o, "ac", "2", options); @@ -4007,7 +3990,7 @@ static const OptionDef options[] = { /* video options */ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" }, - { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, + { "r", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_rates)}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" }, From d4397b0323aee07f340d299f5defd7c4d9f58b9a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Sep 2011 08:20:50 +0200 Subject: [PATCH 11/31] avconv: move frame size to the options context. --- avconv.c | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/avconv.c b/avconv.c index 2ef3d95c55..96aece1b8f 100644 --- a/avconv.c +++ b/avconv.c @@ -101,8 +101,6 @@ static const OptionDef options[]; static int *streamid_map = NULL; static int nb_streamid_map = 0; -static int frame_width = 0; -static int frame_height = 0; static float frame_aspect_ratio = 0; static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; static uint16_t *intra_matrix = NULL; @@ -277,6 +275,8 @@ typedef struct OptionsContext { int nb_audio_sample_rate; SpecifierOpt *frame_rates; int nb_frame_rates; + SpecifierOpt *frame_sizes; + int nb_frame_sizes; /* input options */ int64_t input_ts_offset; @@ -2517,15 +2517,6 @@ static int opt_verbose(const char *opt, const char *arg) return 0; } -static int opt_frame_size(const char *opt, const char *arg) -{ - if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) { - fprintf(stderr, "Incorrect frame size\n"); - return AVERROR(EINVAL); - } - return 0; -} - static int opt_frame_pix_fmt(const char *opt, const char *arg) { if (strcmp(arg, "list")) { @@ -2879,9 +2870,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena if (o->nb_frame_rates) { av_dict_set(&format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0); } - if (frame_width && frame_height) { - snprintf(buf, sizeof(buf), "%dx%d", frame_width, frame_height); - av_dict_set(&format_opts, "video_size", buf, 0); + if (o->nb_frame_sizes) { + av_dict_set(&format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0); } if (frame_pix_fmt != PIX_FMT_NONE) av_dict_set(&format_opts, "pixel_format", av_get_pix_fmt_name(frame_pix_fmt), 0); @@ -2941,8 +2931,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena input_files[nb_input_files - 1].nb_streams = ic->nb_streams; frame_pix_fmt = PIX_FMT_NONE; - frame_height = 0; - frame_width = 0; for (i = 0; i < orig_nb_streams; i++) av_dict_free(&opts[i]); @@ -3066,12 +3054,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; } - if (st->stream_copy) { - video_enc->sample_aspect_ratio = - st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); - } else { + if (!st->stream_copy) { const char *p; - char *forced_key_frames = NULL, *frame_rate = NULL; + char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; int i, force_fps = 0; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); @@ -3080,8 +3065,12 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) exit_program(1); } - video_enc->width = frame_width; - video_enc->height = frame_height; + MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st); + if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) { + av_log(NULL, AV_LOG_ERROR, "Invalid frame size: %s.\n", frame_size); + exit_program(1); + } + video_enc->pix_fmt = frame_pix_fmt; st->sample_aspect_ratio = video_enc->sample_aspect_ratio; @@ -3597,9 +3586,6 @@ static void opt_output_file(void *optctx, const char *filename) av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0); } - frame_width = 0; - frame_height = 0; - av_freep(&streamid_map); nb_streamid_map = 0; @@ -3812,7 +3798,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_audio_codec(o, "c:a", "mp2"); parse_option(o, "f", "vcd", options); - opt_frame_size("s", norm == PAL ? "352x288" : "352x240"); + parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options); parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); @@ -3840,7 +3826,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_audio_codec(o, "c:a", "mp2"); parse_option(o, "f", "svcd", options); - opt_frame_size("s", norm == PAL ? "480x576" : "480x480"); + parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options); parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); @@ -3862,7 +3848,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_audio_codec(o, "c:a", "ac3"); parse_option(o, "f", "dvd", options); - opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480"); + parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options); parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); @@ -3881,7 +3867,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) parse_option(o, "f", "dv", options); - opt_frame_size("s", norm == PAL ? "720x576" : "720x480"); + parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options); opt_frame_pix_fmt("pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" : norm == PAL ? "yuv420p" : "yuv411p"); parse_option(o, "r", frame_rates[norm], options); @@ -3991,7 +3977,7 @@ static const OptionDef options[] = { /* video options */ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" }, { "r", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_rates)}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, - { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, + { "s", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_sizes)}, "set frame size (WxH or abbreviation)", "size" }, { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" }, { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(video_disable)}, "disable video" }, From ca46fde792fd1c98e697b8e3ef54265d7eaf4248 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Sep 2011 08:20:50 +0200 Subject: [PATCH 12/31] avconv: move frame aspect ratio to the options context. --- avconv.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/avconv.c b/avconv.c index 96aece1b8f..2802094648 100644 --- a/avconv.c +++ b/avconv.c @@ -101,7 +101,6 @@ static const OptionDef options[]; static int *streamid_map = NULL; static int nb_streamid_map = 0; -static float frame_aspect_ratio = 0; static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; static uint16_t *intra_matrix = NULL; static uint16_t *inter_matrix = NULL; @@ -323,6 +322,8 @@ typedef struct OptionsContext { int nb_forced_key_frames; SpecifierOpt *force_fps; int nb_force_fps; + SpecifierOpt *frame_aspect_ratios; + int nb_frame_aspect_ratios; } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -2532,7 +2533,7 @@ static int opt_frame_pix_fmt(const char *opt, const char *arg) return 0; } -static int opt_frame_aspect_ratio(const char *opt, const char *arg) +static double parse_frame_aspect_ratio(const char *arg) { int x = 0, y = 0; double ar = 0; @@ -2551,10 +2552,9 @@ static int opt_frame_aspect_ratio(const char *opt, const char *arg) if (!ar) { fprintf(stderr, "Incorrect aspect ratio specification.\n"); - return AVERROR(EINVAL); + exit_program(1); } - frame_aspect_ratio = ar; - return 0; + return ar; } static int opt_top_field_first(const char *opt, const char *arg) @@ -3040,8 +3040,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO); st = ost->st; if (!st->stream_copy) { - ost->frame_aspect_ratio = frame_aspect_ratio; - frame_aspect_ratio = 0; #if CONFIG_AVFILTER ost->avfilter= vfilters; vfilters = NULL; @@ -3057,6 +3055,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) if (!st->stream_copy) { const char *p; char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; + char *frame_aspect_ratio = NULL; int i, force_fps = 0; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); @@ -3071,6 +3070,10 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) exit_program(1); } + MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st); + if (frame_aspect_ratio) + ost->frame_aspect_ratio = parse_frame_aspect_ratio(frame_aspect_ratio); + video_enc->pix_fmt = frame_pix_fmt; st->sample_aspect_ratio = video_enc->sample_aspect_ratio; @@ -3978,7 +3981,7 @@ static const OptionDef options[] = { { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" }, { "r", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_rates)}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, { "s", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_sizes)}, "set frame size (WxH or abbreviation)", "size" }, - { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, + { "aspect", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_aspect_ratios)}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" }, { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(video_disable)}, "disable video" }, { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" }, From b2254d8385dac00f04ce74081810e17b155db785 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Sep 2011 08:20:50 +0200 Subject: [PATCH 13/31] avconv: move frame pixel format to the options context. Also remove redundant -pix_fmt list syntax, it's inconsistent and only makes the code more complicated. -pix_fmts should be enough for everyone. --- avconv.c | 40 +++++++++++++--------------------------- doc/avconv.texi | 2 +- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/avconv.c b/avconv.c index 2802094648..217aaf491f 100644 --- a/avconv.c +++ b/avconv.c @@ -101,7 +101,6 @@ static const OptionDef options[]; static int *streamid_map = NULL; static int nb_streamid_map = 0; -static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; static uint16_t *intra_matrix = NULL; static uint16_t *inter_matrix = NULL; static const char *video_rc_override_string=NULL; @@ -276,6 +275,8 @@ typedef struct OptionsContext { int nb_frame_rates; SpecifierOpt *frame_sizes; int nb_frame_sizes; + SpecifierOpt *frame_pix_fmts; + int nb_frame_pix_fmts; /* input options */ int64_t input_ts_offset; @@ -2518,21 +2519,6 @@ static int opt_verbose(const char *opt, const char *arg) return 0; } -static int opt_frame_pix_fmt(const char *opt, const char *arg) -{ - if (strcmp(arg, "list")) { - frame_pix_fmt = av_get_pix_fmt(arg); - if (frame_pix_fmt == PIX_FMT_NONE) { - fprintf(stderr, "Unknown pixel format requested: %s\n", arg); - return AVERROR(EINVAL); - } - } else { - show_pix_fmts(); - exit_program(0); - } - return 0; -} - static double parse_frame_aspect_ratio(const char *arg) { int x = 0, y = 0; @@ -2873,8 +2859,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena if (o->nb_frame_sizes) { av_dict_set(&format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0); } - if (frame_pix_fmt != PIX_FMT_NONE) - av_dict_set(&format_opts, "pixel_format", av_get_pix_fmt_name(frame_pix_fmt), 0); + if (o->nb_frame_pix_fmts) + av_dict_set(&format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0); ic->flags |= AVFMT_FLAG_NONBLOCK; @@ -2930,8 +2916,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena input_files[nb_input_files - 1].ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp); input_files[nb_input_files - 1].nb_streams = ic->nb_streams; - frame_pix_fmt = PIX_FMT_NONE; - for (i = 0; i < orig_nb_streams; i++) av_dict_free(&opts[i]); av_freep(&opts); @@ -3055,7 +3039,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) if (!st->stream_copy) { const char *p; char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; - char *frame_aspect_ratio = NULL; + char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL; int i, force_fps = 0; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); @@ -3074,7 +3058,11 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) if (frame_aspect_ratio) ost->frame_aspect_ratio = parse_frame_aspect_ratio(frame_aspect_ratio); - video_enc->pix_fmt = frame_pix_fmt; + MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st); + if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) { + av_log(NULL, AV_LOG_ERROR, "Unknown pixel format requested: %s.\n", frame_pix_fmt); + exit_program(1); + } st->sample_aspect_ratio = video_enc->sample_aspect_ratio; if(intra_matrix) @@ -3132,8 +3120,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) ost->force_fps = force_fps; } - /* reset some key parameters */ - frame_pix_fmt = PIX_FMT_NONE; return ost; } @@ -3871,8 +3857,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) parse_option(o, "f", "dv", options); parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options); - opt_frame_pix_fmt("pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" : - norm == PAL ? "yuv420p" : "yuv411p"); + parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" : + norm == PAL ? "yuv420p" : "yuv411p", options); parse_option(o, "r", frame_rates[norm], options); parse_option(o, "ar", "48000", options); @@ -3982,7 +3968,7 @@ static const OptionDef options[] = { { "r", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_rates)}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, { "s", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_sizes)}, "set frame size (WxH or abbreviation)", "size" }, { "aspect", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_aspect_ratios)}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, - { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" }, + { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_pix_fmts)}, "set pixel format", "format" }, { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(video_disable)}, "disable video" }, { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" }, { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" }, diff --git a/doc/avconv.texi b/doc/avconv.texi index 62f21f05e4..1e3236ef4c 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -351,7 +351,7 @@ also sources and sinks). @table @option @item -pix_fmt @var{format} -Set pixel format. Use 'list' as parameter to show all the supported +Set pixel format. Use @code{-pix_fmts} to show all the supported pixel formats. @item -sws_flags @var{flags} Set SwScaler flags. From 0e68c78385606e86cfc5d20203ef3d24e8b005ff Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 16:06:18 +0200 Subject: [PATCH 14/31] avconv: move video_rc_override_string to options context. --- avconv.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/avconv.c b/avconv.c index 217aaf491f..d81a118f75 100644 --- a/avconv.c +++ b/avconv.c @@ -103,7 +103,6 @@ static int nb_streamid_map = 0; static uint16_t *intra_matrix = NULL; static uint16_t *inter_matrix = NULL; -static const char *video_rc_override_string=NULL; static int video_discard = 0; static int same_quant = 0; static int do_deinterlace = 0; @@ -325,6 +324,8 @@ typedef struct OptionsContext { int nb_force_fps; SpecifierOpt *frame_aspect_ratios; int nb_frame_aspect_ratios; + SpecifierOpt *rc_overrides; + int nb_rc_overrides; } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -2501,12 +2502,6 @@ static int transcode(OutputFile *output_files, return ret; } -static int opt_video_rc_override_string(const char *opt, const char *arg) -{ - video_rc_override_string = arg; - return 0; -} - static int opt_me_threshold(const char *opt, const char *arg) { me_threshold = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); @@ -3037,7 +3032,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) } if (!st->stream_copy) { - const char *p; + const char *p = NULL; char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL; int i, force_fps = 0; @@ -3070,7 +3065,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) if(inter_matrix) video_enc->inter_matrix = inter_matrix; - p= video_rc_override_string; + MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st); for(i=0; p; i++){ int start, end, q; int e=sscanf(p, "%d,%d,%d", &start, &end, &q); @@ -3971,7 +3966,7 @@ static const OptionDef options[] = { { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_pix_fmts)}, "set pixel format", "format" }, { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(video_disable)}, "disable video" }, { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" }, - { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" }, + { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(rc_overrides)}, "rate control override for specific intervals", "override" }, { "vcodec", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(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 estimation threshold", "threshold" }, { "same_quant", OPT_BOOL | OPT_VIDEO, {(void*)&same_quant}, From d242d80e36eca6d6f123832ed280d39acb59e680 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 17:06:30 +0200 Subject: [PATCH 15/31] avconv: remove me_threshold option. It's only shadowing the AVOption with the same name. --- avconv.c | 16 ++++------------ libavcodec/options.c | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/avconv.c b/avconv.c index d81a118f75..28e171e6d5 100644 --- a/avconv.c +++ b/avconv.c @@ -107,7 +107,6 @@ static int video_discard = 0; static int same_quant = 0; static int do_deinterlace = 0; static int top_field_first = -1; -static int me_threshold = 0; static int intra_dc_precision = 8; static int qp_hist = 0; #if CONFIG_AVFILTER @@ -1217,7 +1216,7 @@ static void do_video_out(AVFormatContext *s, /* handles same_quant here. This is not correct because it may not be a global option */ big_picture.quality = quality; - if(!me_threshold) + if (!enc->me_threshold) big_picture.pict_type = 0; // big_picture.pts = AV_NOPTS_VALUE; big_picture.pts= ost->sync_opts; @@ -2187,6 +2186,9 @@ static int transcode_init(OutputFile *output_files, av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." "It takes bits/s as argument, not kbits/s\n"); extra_size += ost->st->codec->extradata_size; + + if (ost->st->codec->me_threshold) + input_streams[ost->source_index].st->codec->debug |= FF_DEBUG_MV; } } @@ -2502,12 +2504,6 @@ static int transcode(OutputFile *output_files, return ret; } -static int opt_me_threshold(const char *opt, const char *arg) -{ - me_threshold = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); - return 0; -} - static int opt_verbose(const char *opt, const char *arg) { verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10); @@ -2779,8 +2775,6 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) dec->height >>= dec->lowres; dec->width >>= dec->lowres; } - if(me_threshold) - dec->debug |= FF_DEBUG_MV; if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) { @@ -3092,7 +3086,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) video_enc->rc_override_count=i; if (!video_enc->rc_initial_buffer_occupancy) video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4; - video_enc->me_threshold= me_threshold; video_enc->intra_dc_precision= intra_dc_precision - 8; if (do_psnr) @@ -3968,7 +3961,6 @@ static const OptionDef options[] = { { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" }, { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(rc_overrides)}, "rate control override for specific intervals", "override" }, { "vcodec", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(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 estimation threshold", "threshold" }, { "same_quant", OPT_BOOL | OPT_VIDEO, {(void*)&same_quant}, "use same quantizer as source (implies VBR)" }, { "pass", HAS_ARG | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" }, diff --git a/libavcodec/options.c b/libavcodec/options.c index 7d14beba6a..5cd5cab708 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -352,7 +352,7 @@ static const AVOption options[]={ #endif {"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E|D}, -{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, +{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E}, {"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, {.dbl = 8 }, INT_MIN, INT_MAX, V|E}, From 0bc391281ad80d4eb365f3d8978637b07003e8dc Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 17:31:14 +0200 Subject: [PATCH 16/31] avconv: remove -psnr option. It's redundant -- -flags +psnr does the same thing. --- avconv.c | 5 ----- doc/avconv.texi | 2 -- 2 files changed, 7 deletions(-) diff --git a/avconv.c b/avconv.c index 28e171e6d5..1cd9ce8a5e 100644 --- a/avconv.c +++ b/avconv.c @@ -117,7 +117,6 @@ static int file_overwrite = 0; static int do_benchmark = 0; static int do_hex_dump = 0; static int do_pkt_dump = 0; -static int do_psnr = 0; static int do_pass = 0; static char *pass_logfilename_prefix = NULL; static int video_sync_method= -1; @@ -3088,9 +3087,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4; video_enc->intra_dc_precision= intra_dc_precision - 8; - if (do_psnr) - video_enc->flags|= CODEC_FLAG_PSNR; - /* two pass mode */ if (do_pass) { if (do_pass == 1) { @@ -3967,7 +3963,6 @@ static const OptionDef options[] = { { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename_prefix}, "select two pass log file name prefix", "prefix" }, { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace}, "deinterlace pictures" }, - { "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" }, #if CONFIG_AVFILTER diff --git a/doc/avconv.texi b/doc/avconv.texi index 1e3236ef4c..6daece4a56 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -550,8 +550,6 @@ Use this option if your input file is interlaced and you want to keep the interlaced format for minimum losses. The alternative is to deinterlace the input stream with @option{-deinterlace}, but deinterlacing introduces losses. -@item -psnr -Calculate PSNR of compressed frames. @item -vstats Dump video coding statistics to @file{vstats_HHMMSS.log}. @item -vstats_file @var{file} From 2c2cff16d96533f14c07c78876b76966d84f6cf5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 17:57:56 +0200 Subject: [PATCH 17/31] avconv: move inter/intra matrix to options context. --- avconv.c | 80 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/avconv.c b/avconv.c index 1cd9ce8a5e..882f81782f 100644 --- a/avconv.c +++ b/avconv.c @@ -101,8 +101,6 @@ static const OptionDef options[]; static int *streamid_map = NULL; static int nb_streamid_map = 0; -static uint16_t *intra_matrix = NULL; -static uint16_t *inter_matrix = NULL; static int video_discard = 0; static int same_quant = 0; static int do_deinterlace = 0; @@ -324,6 +322,10 @@ typedef struct OptionsContext { int nb_frame_aspect_ratios; SpecifierOpt *rc_overrides; int nb_rc_overrides; + SpecifierOpt *intra_matrices; + int nb_intra_matrices; + SpecifierOpt *inter_matrices; + int nb_inter_matrices; } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -510,9 +512,6 @@ void exit_program(int ret) for (i = 0; i < nb_input_streams; i++) av_dict_free(&input_streams[i].opts); - av_free(intra_matrix); - av_free(inter_matrix); - if (vstats_file) fclose(vstats_file); av_free(vstats_filename); @@ -3003,6 +3002,23 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e return ost; } +static void parse_matrix_coeffs(uint16_t *dest, const char *str) +{ + int i; + const char *p = str; + for(i = 0;; i++) { + dest[i] = atoi(p); + if(i == 63) + break; + p = strchr(p, ','); + if(!p) { + fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i); + exit_program(1); + } + p++; + } +} + static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) { AVStream *st; @@ -3028,6 +3044,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) const char *p = NULL; char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL; + char *intra_matrix = NULL, *inter_matrix = NULL; int i, force_fps = 0; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); @@ -3053,10 +3070,22 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) } st->sample_aspect_ratio = video_enc->sample_aspect_ratio; - if(intra_matrix) - video_enc->intra_matrix = intra_matrix; - if(inter_matrix) - video_enc->inter_matrix = inter_matrix; + MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st); + if (intra_matrix) { + if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) { + av_log(NULL, AV_LOG_ERROR, "Could not allocate memory for intra matrix.\n"); + exit_program(1); + } + parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix); + } + MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st); + if (inter_matrix) { + if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) { + av_log(NULL, AV_LOG_ERROR, "Could not allocate memory for inter matrix.\n"); + exit_program(1); + } + parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix); + } MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st); for(i=0; p; i++){ @@ -3608,35 +3637,6 @@ static int64_t getmaxrss(void) #endif } -static void parse_matrix_coeffs(uint16_t *dest, const char *str) -{ - int i; - const char *p = str; - for(i = 0;; i++) { - dest[i] = atoi(p); - if(i == 63) - break; - p = strchr(p, ','); - if(!p) { - fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i); - exit_program(1); - } - p++; - } -} - -static void opt_inter_matrix(const char *arg) -{ - inter_matrix = av_mallocz(sizeof(uint16_t) * 64); - parse_matrix_coeffs(inter_matrix, arg); -} - -static void opt_intra_matrix(const char *arg) -{ - intra_matrix = av_mallocz(sizeof(uint16_t) * 64); - parse_matrix_coeffs(intra_matrix, arg); -} - static int opt_audio_qscale(OptionsContext *o, const char *opt, const char *arg) { return parse_option(o, "q:a", arg, options); @@ -3968,8 +3968,8 @@ static const OptionDef options[] = { #if CONFIG_AVFILTER { "vf", OPT_STRING | HAS_ARG, {(void*)&vfilters}, "video filters", "filter list" }, #endif - { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" }, - { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" }, + { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(intra_matrices)}, "specify intra matrix coeffs", "matrix" }, + { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(inter_matrices)}, "specify inter matrix coeffs", "matrix" }, { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" }, { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" }, { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" }, From 828e0bcb869f0b97bc91105686d37ec855c62d6a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 18:03:31 +0200 Subject: [PATCH 18/31] avconv: move top_field_first to options context. --- avconv.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/avconv.c b/avconv.c index 882f81782f..dcc6daaa86 100644 --- a/avconv.c +++ b/avconv.c @@ -104,7 +104,6 @@ static int nb_streamid_map = 0; static int video_discard = 0; static int same_quant = 0; static int do_deinterlace = 0; -static int top_field_first = -1; static int intra_dc_precision = 8; static int qp_hist = 0; #if CONFIG_AVFILTER @@ -203,6 +202,7 @@ typedef struct OutputStream { int resample_pix_fmt; AVRational frame_rate; int force_fps; + int top_field_first; float frame_aspect_ratio; @@ -326,6 +326,8 @@ typedef struct OptionsContext { int nb_intra_matrices; SpecifierOpt *inter_matrices; int nb_inter_matrices; + SpecifierOpt *top_field_first; + int nb_top_field_first; } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -1205,10 +1207,10 @@ static void do_video_out(AVFormatContext *s, settings */ big_picture.interlaced_frame = in_picture->interlaced_frame; if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)) { - if(top_field_first == -1) + if (ost->top_field_first == -1) big_picture.top_field_first = in_picture->top_field_first; else - big_picture.top_field_first = top_field_first; + big_picture.top_field_first = !!ost->top_field_first; } /* handles same_quant here. This is not correct because it may @@ -2532,12 +2534,6 @@ static double parse_frame_aspect_ratio(const char *arg) return ar; } -static int opt_top_field_first(const char *opt, const char *arg) -{ - top_field_first = parse_number_or_die(opt, arg, OPT_INT, 0, 1); - return 0; -} - static int opt_audio_codec(OptionsContext *o, const char *opt, const char *arg) { return parse_option(o, "codec:a", arg, options); @@ -3045,7 +3041,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL; char *intra_matrix = NULL, *inter_matrix = NULL; - int i, force_fps = 0; + int i, force_fps = 0, top_field_first = -1; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) { @@ -3131,6 +3127,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) MATCH_PER_STREAM_OPT(force_fps, i, force_fps, oc, st); ost->force_fps = force_fps; + + MATCH_PER_STREAM_OPT(top_field_first, i, top_field_first, oc, st); + ost->top_field_first = top_field_first; } return ost; @@ -3970,7 +3969,7 @@ static const OptionDef options[] = { #endif { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(intra_matrices)}, "specify intra matrix coeffs", "matrix" }, { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(inter_matrices)}, "specify inter matrix coeffs", "matrix" }, - { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" }, + { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_INT| OPT_SPEC, {.off = OFFSET(top_field_first)}, "top=1/bottom=0/auto=-1 field first", "" }, { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" }, { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" }, { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, From 8e5ce5901bea18578ffe2c7ccb99e2d8c4080f73 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 21:11:00 +0200 Subject: [PATCH 19/31] avconv: extend -vf syntax Add a per-stream -filter option, make -vf an alias for -filter:v. Move vfilters to the options context. --- avconv.c | 32 ++++++++++++++++++++------------ doc/avconv.texi | 7 ++++++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/avconv.c b/avconv.c index dcc6daaa86..bdb2d817a7 100644 --- a/avconv.c +++ b/avconv.c @@ -106,9 +106,6 @@ static int same_quant = 0; static int do_deinterlace = 0; static int intra_dc_precision = 8; static int qp_hist = 0; -#if CONFIG_AVFILTER -static char *vfilters = NULL; -#endif static int file_overwrite = 0; static int do_benchmark = 0; @@ -328,6 +325,10 @@ typedef struct OptionsContext { int nb_inter_matrices; SpecifierOpt *top_field_first; int nb_top_field_first; +#if CONFIG_AVFILTER + SpecifierOpt *filters; + int nb_filters; +#endif } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -3023,13 +3024,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO); st = ost->st; - if (!st->stream_copy) { -#if CONFIG_AVFILTER - ost->avfilter= vfilters; - vfilters = NULL; -#endif - } - video_enc = st->codec; if(oc->oformat->flags & AVFMT_GLOBALHEADER) { @@ -3040,7 +3034,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) const char *p = NULL; char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL; - char *intra_matrix = NULL, *inter_matrix = NULL; + char *intra_matrix = NULL, *inter_matrix = NULL, *filters = NULL; int i, force_fps = 0, top_field_first = -1; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); @@ -3130,6 +3124,12 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) MATCH_PER_STREAM_OPT(top_field_first, i, top_field_first, oc, st); ost->top_field_first = top_field_first; + +#if CONFIG_AVFILTER + MATCH_PER_STREAM_OPT(filters, str, filters, oc, st); + if (filters) + ost->avfilter = av_strdup(filters); +#endif } return ost; @@ -3902,6 +3902,11 @@ static int opt_subtitle_tag(OptionsContext *o, const char *opt, const char *arg) return parse_option(o, "tag:s", arg, options); } +static int opt_video_filters(OptionsContext *o, const char *opt, const char *arg) +{ + return parse_option(o, "filter:v", arg, options); +} + #define OFFSET(x) offsetof(OptionsContext, x) static const OptionDef options[] = { /* main options */ @@ -3945,6 +3950,9 @@ static const OptionDef options[] = { { "tag", OPT_STRING | HAS_ARG | OPT_SPEC, {.off = OFFSET(codec_tags)}, "force codec tag/fourcc", "fourcc/tag" }, { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" }, { "qscale", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" }, +#if CONFIG_AVFILTER + { "filter", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(filters)}, "set stream filterchain", "filter_list" }, +#endif /* video options */ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" }, @@ -3965,7 +3973,7 @@ static const OptionDef options[] = { { "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" }, #if CONFIG_AVFILTER - { "vf", OPT_STRING | HAS_ARG, {(void*)&vfilters}, "video filters", "filter list" }, + { "vf", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_filters}, "video filters", "filter list" }, #endif { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(intra_matrices)}, "specify intra matrix coeffs", "matrix" }, { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(inter_matrices)}, "specify inter matrix coeffs", "matrix" }, diff --git a/doc/avconv.texi b/doc/avconv.texi index 6daece4a56..db7e15723f 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -210,6 +210,11 @@ Stop writing to the stream after @var{framecount} frames. Use fixed quality scale (VBR). The meaning of @var{q} is codec-dependent. +@item -filter[:stream_specifier] @var{filter_graph} +@var{filter_graph} is a description of the filter graph to apply to +the stream. Use @code{-filters} to show all the available filters +(including also sources and sinks). + @end table @section Video Options @@ -343,7 +348,7 @@ stream. @var{filter_graph} is a description of the filter graph to apply to the input video. Use the option "-filters" to show all the available filters (including -also sources and sinks). +also sources and sinks). This is an alias for @code{-filter:v}. @end table From 495ecfd139ac9bf8e467086e17efd7f1970972bc Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 22:07:30 +0200 Subject: [PATCH 20/31] avconv: move streamid_map to options context. --- avconv.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/avconv.c b/avconv.c index bdb2d817a7..e8c48bb6b0 100644 --- a/avconv.c +++ b/avconv.c @@ -97,10 +97,6 @@ typedef struct MetadataMap { static const OptionDef options[]; -/* indexed by output file stream index */ -static int *streamid_map = NULL; -static int nb_streamid_map = 0; - static int video_discard = 0; static int same_quant = 0; static int do_deinterlace = 0; @@ -299,6 +295,10 @@ typedef struct OptionsContext { int subtitle_disable; int data_disable; + /* indexed by output file stream index */ + int *streamid_map; + int nb_streamid_map; + SpecifierOpt *metadata; int nb_metadata; SpecifierOpt *max_frames; @@ -368,6 +368,7 @@ static void reset_options(OptionsContext *o) av_freep(&o->stream_maps); av_freep(&o->meta_data_maps); + av_freep(&o->streamid_map); memset(o, 0, sizeof(*o)); @@ -2934,7 +2935,7 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type) { OutputStream *ost; - AVStream *st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0); + AVStream *st = av_new_stream(oc, oc->nb_streams < o->nb_streamid_map ? o->streamid_map[oc->nb_streams] : 0); int idx = oc->nb_streams - 1; int64_t max_frames = INT64_MAX; char *bsf = NULL, *next, *codec_tag = NULL; @@ -3209,7 +3210,7 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc) } /* arg format is "output-stream-index:streamid-value". */ -static int opt_streamid(const char *opt, const char *arg) +static int opt_streamid(OptionsContext *o, const char *opt, const char *arg) { int idx; char *p; @@ -3225,8 +3226,8 @@ static int opt_streamid(const char *opt, const char *arg) } *p++ = '\0'; idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, INT_MAX); - streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1); - streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX); + o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1); + o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX); return 0; } @@ -3587,9 +3588,6 @@ static void opt_output_file(void *optctx, const char *filename) av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0); } - av_freep(&streamid_map); - nb_streamid_map = 0; - reset_options(o); } @@ -3982,7 +3980,7 @@ static const OptionDef options[] = { { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" }, { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(force_fps)}, "force the selected framerate, disable the best supported framerate selection" }, - { "streamid", HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" }, + { "streamid", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" }, { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(forced_key_frames)}, "force key frames at specified timestamps", "timestamps" }, /* audio options */ From b3dd2010afb46d5e91117067b5e9e1f9dcd18df8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 22:17:38 +0200 Subject: [PATCH 21/31] doc: cosmetics, rename fftools-common-opts to avtools-.... --- doc/avconv.texi | 2 +- doc/avplay.texi | 2 +- doc/avprobe.texi | 2 +- doc/avserver.texi | 2 +- doc/{fftools-common-opts.texi => avtools-common-opts.texi} | 2 +- doc/ffmpeg.texi | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename doc/{fftools-common-opts.texi => avtools-common-opts.texi} (98%) diff --git a/doc/avconv.texi b/doc/avconv.texi index db7e15723f..a6d1c0ab4f 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -82,7 +82,7 @@ described. @chapter Options @c man begin OPTIONS -@include fftools-common-opts.texi +@include avtools-common-opts.texi @section Main options diff --git a/doc/avplay.texi b/doc/avplay.texi index e292481228..502580fb31 100644 --- a/doc/avplay.texi +++ b/doc/avplay.texi @@ -28,7 +28,7 @@ various Libav APIs. @chapter Options @c man begin OPTIONS -@include fftools-common-opts.texi +@include avtools-common-opts.texi @section Main options diff --git a/doc/avprobe.texi b/doc/avprobe.texi index 5fc73a1934..8955e1fdfa 100644 --- a/doc/avprobe.texi +++ b/doc/avprobe.texi @@ -60,7 +60,7 @@ are prefixed by the string "TAG:". @chapter Options @c man begin OPTIONS -@include fftools-common-opts.texi +@include avtools-common-opts.texi @section Main options diff --git a/doc/avserver.texi b/doc/avserver.texi index b0bb06b504..7ac4a137df 100644 --- a/doc/avserver.texi +++ b/doc/avserver.texi @@ -240,7 +240,7 @@ For example: @samp{http://localhost:8080/test.asf?date=2002-07-26T23:05:00}. @chapter Options @c man begin OPTIONS -@include fftools-common-opts.texi +@include avtools-common-opts.texi @section Main options diff --git a/doc/fftools-common-opts.texi b/doc/avtools-common-opts.texi similarity index 98% rename from doc/fftools-common-opts.texi rename to doc/avtools-common-opts.texi index 91e1ed7969..e7c1bba4ac 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/avtools-common-opts.texi @@ -13,7 +13,7 @@ commandline will set to false the boolean option with name "foo". @section Generic options -These options are shared amongst the ff* tools. +These options are shared amongst the av* tools. @table @option diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 32916a7c96..2457d65253 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -68,7 +68,7 @@ specified for the inputs. @chapter Options @c man begin OPTIONS -@include fftools-common-opts.texi +@include avtools-common-opts.texi @section Main options From 1533c10286c21445f55f19d9d6711c5a7aeaa028 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 2 Sep 2011 22:53:54 +0200 Subject: [PATCH 22/31] doc/avconv: remove documentation for removed 'timestamp' option --- doc/avconv.texi | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/doc/avconv.texi b/doc/avconv.texi index a6d1c0ab4f..1bab785c28 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -148,18 +148,6 @@ The offset is added to the timestamps of the input files. Specifying a positive offset means that the corresponding streams are delayed by 'offset' seconds. -@item -timestamp @var{time} -Set the recording timestamp in the container. -The syntax for @var{time} is: -@example -now|([(YYYY-MM-DD|YYYYMMDD)[T|t| ]]((HH[:MM[:SS[.m...]]])|(HH[MM[SS[.m...]]]))[Z|z]) -@end example -If the value is "now" it takes the current time. -Time is local time unless 'Z' or 'z' is appended, in which case it is -interpreted as UTC. -If the year-month-day part is not specified it takes the current -year-month-day. - @item -metadata[:metadata_specifier] @var{key}=@var{value} Set a metadata key/value pair. From d3d6a2582e68bb503cd8a5e8a23cd623549779c7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 3 Sep 2011 07:08:55 +0200 Subject: [PATCH 23/31] doc/avconv: remove entries for nonexistent options --- doc/avconv.texi | 58 ------------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/doc/avconv.texi b/doc/avconv.texi index 1bab785c28..53829938a6 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -442,50 +442,6 @@ Try just the (0, 0) vector. exhaustive search (slow and marginally better than epzs) @end table -@item -dct_algo @var{algo} -Set DCT algorithm to @var{algo}. Available values are: -@table @samp -@item 0 -FF_DCT_AUTO (default) -@item 1 -FF_DCT_FASTINT -@item 2 -FF_DCT_INT -@item 3 -FF_DCT_MMX -@item 4 -FF_DCT_MLIB -@item 5 -FF_DCT_ALTIVEC -@end table - -@item -idct_algo @var{algo} -Set IDCT algorithm to @var{algo}. Available values are: -@table @samp -@item 0 -FF_IDCT_AUTO (default) -@item 1 -FF_IDCT_INT -@item 2 -FF_IDCT_SIMPLE -@item 3 -FF_IDCT_SIMPLEMMX -@item 4 -FF_IDCT_LIBMPEG2MMX -@item 5 -FF_IDCT_PS2 -@item 6 -FF_IDCT_MLIB -@item 7 -FF_IDCT_ARM -@item 8 -FF_IDCT_ALTIVEC -@item 9 -FF_IDCT_SH4 -@item 10 -FF_IDCT_SIMPLEARM -@end table - @item -er @var{n} Set error resilience to @var{n}. @table @samp @@ -522,27 +478,13 @@ FF_MB_DECISION_BITS: Choose the one which needs the fewest bits. FF_MB_DECISION_RD: rate distortion @end table -@item -4mv -Use four motion vector by macroblock (MPEG-4 only). -@item -part -Use data partitioning (MPEG-4 only). @item -bug @var{param} Work around encoder bugs that are not auto-detected. @item -strict @var{strictness} How strictly to follow the standards. -@item -aic -Enable Advanced intra coding (h263+). -@item -umv -Enable Unlimited Motion Vector (h263+) @item -deinterlace Deinterlace pictures. -@item -ilme -Force interlacing support in encoder (MPEG-2 and MPEG-4 only). -Use this option if your input file is interlaced and you want -to keep the interlaced format for minimum losses. -The alternative is to deinterlace the input stream with -@option{-deinterlace}, but deinterlacing introduces losses. @item -vstats Dump video coding statistics to @file{vstats_HHMMSS.log}. @item -vstats_file @var{file} From eb05446367533bd669195be6dae69057a5e0f0e5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 3 Sep 2011 12:53:53 +0200 Subject: [PATCH 24/31] doc/avconv: document that global options should be specified first. --- doc/avconv.texi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/avconv.texi b/doc/avconv.texi index 53829938a6..9cf83b6b2f 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -15,7 +15,7 @@ The generic syntax is: @example @c man begin SYNOPSIS -avconv [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}... +avconv [global options] [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}... @c man end @end example @@ -35,6 +35,8 @@ As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file. +Exceptions from this rule are the global options (e.g. vebosity level), +which should be specified first. @itemize @item From 3a37392efef930bb7c109d2041d5c9ea5bb2a7de Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 3 Sep 2011 13:02:20 +0200 Subject: [PATCH 25/31] doc/avconv: remove two pointless paragraphs. They are misleading and carry no useful information. --- doc/avconv.texi | 9 --------- 1 file changed, 9 deletions(-) diff --git a/doc/avconv.texi b/doc/avconv.texi index 9cf83b6b2f..7b21ee373a 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -26,11 +26,6 @@ avconv is a very fast video and audio converter that can also grab from a live audio/video source. It can also convert between arbitrary sample rates and resize video on the fly with a high quality polyphase filter. -The command line interface is designed to be intuitive, in the sense -that avconv tries to figure out all parameters that can possibly be -derived automatically. You usually only have to specify the target -bitrate you want. - As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is @@ -61,10 +56,6 @@ avconv -r 1 -i input.m2v -r 24 output.avi The format option may be needed for raw input files. -By default avconv tries to convert as losslessly as possible: It -uses the same audio and video parameters for the outputs as the one -specified for the inputs. - @c man end DESCRIPTION @chapter Stream selection From 99442bfe20796316b26856e71cfb70ab501a6345 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 3 Sep 2011 14:55:39 +0200 Subject: [PATCH 26/31] doc/avtools-common-opts: write a section about stream specifiers. --- doc/avtools-common-opts.texi | 44 +++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/doc/avtools-common-opts.texi b/doc/avtools-common-opts.texi index e7c1bba4ac..0f0ecdf943 100644 --- a/doc/avtools-common-opts.texi +++ b/doc/avtools-common-opts.texi @@ -11,6 +11,35 @@ corresponding value to true. They can be set to false by prefixing with "no" the option name, for example using "-nofoo" in the commandline will set to false the boolean option with name "foo". +@section Stream specifiers +Some options are applied per-stream, e.g. bitrate or codec. Stream specifiers +are used to precisely specify which stream(s) does a given option belong to. + +A stream specifier is a string generally appended to the option name and +separated from it by a colon. E.g. @code{-codec:a:1 ac3} option contains +@code{a:1} stream specifer, which matches the second audio stream. Therefore it +would select the ac3 codec for the second audio stream. + +A stream specifier can match several stream, the option is then applied to all +of them. E.g. the stream specifier in @code{-b:a 128k} matches all audio +streams. + +An empty stream specifier matches all streams, for example @code{-codec copy} +or @code{-codec: copy} would copy all the streams without reencoding. + +Possible forms of stream specifiers are: +@table @option +@item @var{stream_index} +Matches the stream with this index. E.g. @code{-threads:1 4} would set the +thread count for the second stream to 4. +@item @var{stream_type}[:@var{stream_index}] +@var{stream_type} is one of: 'v' for video, 'a' for audio, 's' for subtitle and +'d' for data. If @var{stream_index} is given, then matches stream number +@var{stream_index} of this type. Otherwise matches all streams of this type. +@item @var{program_id}[:@var{stream_index}] +If @var{stream_index} is given, then matches stream number @var{stream_index} in +program with id @var{program_id}. Otherwise matches all streams in this program. +@end table @section Generic options These options are shared amongst the av* tools. @@ -117,19 +146,8 @@ muxer: ffmpeg -i input.flac -id3v2_version 3 out.mp3 @end example -You can precisely specify which stream(s) should the codec AVOption apply to by -appending a stream specifier of the form -@option{[:@var{stream_type}][:@var{stream_index}]} to the option name. -@var{stream_type} is 'v' for video, 'a' for audio and 's' for subtitle streams. -@var{stream_index} is a global stream index when @var{stream_type} isn't -given, otherwise it counts streams of the given type only. As always, the index -is zero-based. For example -@example --foo -- applies to all applicable streams --foo:v -- applies to all video streams --foo:a:2 -- applies to the third audio stream --foo:0 -- applies to the first stream -@end example +All codec AVOptions are obviously per-stream, so the chapter on stream +specifiers applies to them Note -nooption syntax cannot be used for boolean AVOptions, use -option 0/-option 1. From 172efad7c7eb6f2ca94d258bc2f0a6c52d3b5ef4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 3 Sep 2011 15:02:52 +0200 Subject: [PATCH 27/31] doc/avconv: document option types (input/output/per-stream/...) Also trim some redundant stream specifiers descriptions. --- doc/avconv.texi | 129 +++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 73 deletions(-) diff --git a/doc/avconv.texi b/doc/avconv.texi index 7b21ee373a..8f10fc5468 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -81,30 +81,22 @@ described. @table @option -@item -f @var{fmt} +@item -f @var{fmt} (@emph{input/output}) Force format. -@item -i @var{filename} +@item -i @var{filename} (@emph{input}) input file name -@item -y +@item -y (@emph{global}) Overwrite output files. -@item -c[:@var{stream_type}][:@var{stream_index}] @var{codec} -@item -codec[:@var{stream_type}][:@var{stream_index}] @var{codec} +@item -c[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream}) +@itemx -codec[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream}) Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. @var{codec} is the name of a decoder/encoder or a special value @code{copy} (output only) to indicate that the stream is not to be reencoded. -@var{stream_type} may be 'v' for video, 'a' for audio, 's' for subtitle and 'd' -for data streams. @var{stream_index} is a global zero-based stream index if -@var{stream_type} isn't given, otherwise it counts only streams of the given -type. If @var{stream_index} is omitted, this option applies to all streams of -the given type or all streams of any type if @var{stream_type} is missing as -well (note that this only makes sense when all streams are of the same type or -@var{codec} is @code{copy}). - For example @example avconv -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT @@ -118,15 +110,15 @@ avconv -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT will copy all the streams except the second video, which will be encoded with libx264, and the 138th audio, which will be encoded with libvorbis. -@item -t @var{duration} +@item -t @var{duration} (@emph{output}) Restrict the transcoded/captured video sequence to the duration specified in seconds. @code{hh:mm:ss[.xxx]} syntax is also supported. -@item -fs @var{limit_size} +@item -fs @var{limit_size} (@emph{output}) Set the file size limit. -@item -ss @var{position} +@item -ss @var{position} (@emph{input/output}) When used as an input option (before @code{-i}), seeks in this input file to @var{position}. When used as an output option (before an output filename), decodes but discards input until the timestamps reach @var{position}. This is @@ -134,14 +126,14 @@ slower, but more accurate. @var{position} may be either in seconds or in @code{hh:mm:ss[.xxx]} form. -@item -itsoffset @var{offset} +@item -itsoffset @var{offset} (@emph{input}) Set the input time offset in seconds. @code{[-]hh:mm:ss[.xxx]} syntax is also supported. The offset is added to the timestamps of the input files. Specifying a positive offset means that the corresponding streams are delayed by 'offset' seconds. -@item -metadata[:metadata_specifier] @var{key}=@var{value} +@item -metadata[:metadata_specifier] @var{key}=@var{value} (@emph{output,per-metadata}) Set a metadata key/value pair. An optional @var{metadata_specifier} may be given to set metadata @@ -161,10 +153,10 @@ To set the language of the second stream: avconv -i INPUT -metadata:s:1 language=eng OUTPUT @end example -@item -v @var{number} +@item -v @var{number} (@emph{global}) Set the logging verbosity level. -@item -target @var{type} +@item -target @var{type} (@emph{output}) Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ... ). All the format options (bitrate, codecs, buffer sizes) are then set automatically. You can just type: @@ -180,18 +172,18 @@ they do not conflict with the standard, as in: avconv -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg @end example -@item -dframes @var{number} +@item -dframes @var{number} (@emph{output}) Set the number of data frames to record. This is an alias for @code{-frames:d}. -@item -frames[:stream_specifier] @var{framecount} +@item -frames[:@var{stream_specifier}] @var{framecount} (@emph{output,per-stream}) Stop writing to the stream after @var{framecount} frames. -@item -q @var{q} -@item -qscale @var{q} +@item -q[:@var{stream_specifier}] @var{q} (@emph{output,per-stream}) +@itemx -qscale[:@var{stream_specifier}] @var{q} (@emph{output,per-stream}) Use fixed quality scale (VBR). The meaning of @var{q} is codec-dependent. -@item -filter[:stream_specifier] @var{filter_graph} +@item -filter[:@var{stream_specifier}] @var{filter_graph} @var{filter_graph} is a description of the filter graph to apply to the stream. Use @code{-filters} to show all the available filters (including also sources and sinks). @@ -201,11 +193,11 @@ the stream. Use @code{-filters} to show all the available filters @section Video Options @table @option -@item -vframes @var{number} +@item -vframes @var{number} (@emph{output}) Set the number of video frames to record. This is an alias for @code{-frames:v}. -@item -r @var{fps} +@item -r[:@var{stream_specifier}] @var{fps} (@emph{input/output,per-stream}) Set frame rate (Hz value, fraction or abbreviation), (default = 25). -@item -s @var{size} +@item -s[:@var{stream_specifier}] @var{size} (@emph{input/output,per-stream}) Set frame size. The format is @samp{wxh} (avserver default = 160x128, avconv default = same as source). The following abbreviations are recognized: @table @samp @@ -269,7 +261,7 @@ The following abbreviations are recognized: 1920x1080 @end table -@item -aspect @var{aspect} +@item -aspect[:@var{stream_specifier}] @var{aspect} (@emph{output,per-stream}) Set the video display aspect ratio specified by @var{aspect}. @var{aspect} can be a floating point number string, or a string of the @@ -277,7 +269,7 @@ form @var{num}:@var{den}, where @var{num} and @var{den} are the numerator and denominator of the aspect ratio. For example "4:3", "16:9", "1.3333", and "1.7777" are valid argument values. -@item -vn +@item -vn (@emph{output}) Disable video recording. @item -bt @var{tolerance} Set video bitrate tolerance (in bits, default 4000k). @@ -298,7 +290,7 @@ avconv -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m It is of little use elsewise. @item -bufsize @var{size} Set video buffer verifier buffer size (in bits). -@item -vcodec @var{codec} +@item -vcodec @var{codec} (@emph{output}) Set the video codec. This is an alias for @code{-codec:v}. @item -same_quant Use same quantizer as source (implies VBR). @@ -319,13 +311,13 @@ avconv -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y NUL avconv -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y /dev/null @end example -@item -passlogfile @var{prefix} +@item -passlogfile @var{prefix} (@emph{global}) Set two-pass log file name prefix to @var{prefix}, the default file name prefix is ``av2pass''. The complete file name will be @file{PREFIX-N.log}, where N is a number specific to the output stream. -@item -vf @var{filter_graph} +@item -vf @var{filter_graph} (@emph{output}) @var{filter_graph} is a description of the filter graph to apply to the input video. Use the option "-filters" to show all the available filters (including @@ -336,10 +328,10 @@ also sources and sinks). This is an alias for @code{-filter:v}. @section Advanced Video Options @table @option -@item -pix_fmt @var{format} +@item -pix_fmt[:@var{stream_specifier}] @var{format} (@emph{input/output,per-stream}) Set pixel format. Use @code{-pix_fmts} to show all the supported pixel formats. -@item -sws_flags @var{flags} +@item -sws_flags @var{flags} (@emph{input/output}) Set SwScaler flags. @item -g @var{gop_size} Set the group of pictures size. @@ -416,7 +408,7 @@ and the following constants are available: @item avgTex @end table -@item -rc_override @var{override} +@item -rc_override[:@var{stream_specifier}] @var{override} (@emph{output,per-stream}) rate control override for specific intervals @item -me_method @var{method} Set motion estimation method to @var{method}. @@ -482,15 +474,15 @@ Deinterlace pictures. Dump video coding statistics to @file{vstats_HHMMSS.log}. @item -vstats_file @var{file} Dump video coding statistics to @var{file}. -@item -top @var{n} +@item -top[:@var{stream_specifier}] @var{n} (@emph{output,per-stream}) top=1/bottom=0/auto=-1 field first @item -dc @var{precision} Intra_dc_precision. -@item -vtag @var{fourcc/tag} +@item -vtag @var{fourcc/tag} (@emph{output}) Force video tag/fourcc. This is an alias for @code{-tag:v}. -@item -qphist +@item -qphist (@emph{global}) Show QP histogram. -@item -force_key_frames @var{time}[,@var{time}...] +@item -force_key_frames[:@var{stream_specifier}] @var{time}[,@var{time}...] (@emph{output,per-stream}) Force key frames at the specified timestamps, more precisely at the first frames after each specified time. This option can be useful to ensure that a seek point is present at a @@ -501,25 +493,25 @@ The timestamps must be specified in ascending order. @section Audio Options @table @option -@item -aframes @var{number} +@item -aframes @var{number} (@emph{output}) Set the number of audio frames to record. This is an alias for @code{-frames:a}. -@item -ar @var{freq} +@item -ar[:@var{stream_specifier}] @var{freq} (@emph{input/output,per-stream}) Set the audio sampling frequency. For output streams it is set by default to the frequency of the corresponding input stream. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. -@item -aq @var{q} +@item -aq @var{q} (@emph{output}) Set the audio quality (codec-specific, VBR). This is an alias for -q:a. -@item -ac @var{channels} +@item -ac[:@var{stream_specifier}] @var{channels} (@emph{input/output,per-stream}) Set the number of audio channels. For output streams it is set by default to the number of input audio channels. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. -@item -an +@item -an (@emph{output}) Disable audio recording. -@item -acodec @var{codec} +@item -acodec @var{codec} (@emph{input/output}) Set the audio codec. This is an alias for @code{-codec:a}. -@item -sample_fmt[:@var{stream_specifier}] @var{sample_fmt} +@item -sample_fmt[:@var{stream_specifier}] @var{sample_fmt} (@emph{output,per-stream}) Set the audio sample format. Use @code{-help sample_fmts} to get a list of supported sample formats. @end table @@ -527,7 +519,7 @@ of supported sample formats. @section Advanced Audio options: @table @option -@item -atag @var{fourcc/tag} +@item -atag @var{fourcc/tag} (@emph{output}) Force audio tag/fourcc. This is an alias for @code{-tag:a}. @item -audio_service_type @var{type} Set the type of service that the audio stream contains. @@ -556,38 +548,31 @@ Karaoke @section Subtitle options: @table @option -@item -scodec @var{codec} +@item -scodec @var{codec} (@emph{input/output}) Set the subtitle codec. This is an alias for @code{-codec:s}. -@item -sn +@item -sn (@emph{output}) Disable subtitle recording. @end table @section Audio/Video grab options @table @option -@item -isync +@item -isync (@emph{global}) Synchronize read on input. @end table @section Advanced options @table @option -@item -map [-]@var{input_file_id}[:@var{input_stream_type}][:@var{input_stream_id}][,@var{sync_file_id}[:@var{sync_stream_type}][:@var{sync_stream_id}]] +@item -map [-]@var{input_file_id}[:@var{stream_specifier}][,@var{sync_file_id}[:@var{stream_specifier}]] (@emph{output}) Designate one or more input streams as a source for the output file. Each input stream is identified by the input file index @var{input_file_id} and the input stream index @var{input_stream_id} within the input file. Both indices start at 0. If specified, -@var{sync_file_id}:@var{sync_stream_id} sets which input stream +@var{sync_file_id}:@var{stream_specifier} sets which input stream is used as a presentation sync reference. -If @var{input_stream_type} is specified -- 'v' for video, 'a' for audio, 's' for -subtitle and 'd' for data -- then @var{input_stream_id} counts only the streams -of this type. Same for @var{sync_stream_type}. - -@var{input_stream_id} may be omitted, in which case all streams of the given -type are mapped (or all streams in the file, if no type is specified). - The first @code{-map} option on the command line specifies the source for output stream 0, the second @code{-map} option specifies the source for output stream 1, etc. @@ -630,7 +615,7 @@ avconv -i INPUT -map 0 -map -0:a:1 OUTPUT Note that using this option disables the default mappings for this output file. -@item -map_metadata[:@var{metadata_type}][:@var{index}] @var{infile}[:@var{metadata_type}][:@var{index}] +@item -map_metadata[:@var{metadata_type}][:@var{index}] @var{infile}[:@var{metadata_type}][:@var{index}] (@emph{output,per-metadata}) Set metadata information of the next output file from @var{infile}. Note that those are file indices (zero-based), not filenames. Optional @var{metadata_type} parameters specify, which metadata to copy - (g)lobal @@ -649,27 +634,25 @@ of the output file: @example avconv -i in.ogg -map_metadata 0:s:0 out.mp3 @end example -@item -map_chapters @var{input_file_index} +@item -map_chapters @var{input_file_index} (@emph{output}) Copy chapters from input file with index @var{input_file_index} to the next output file. If no chapter mapping is specified, then chapters are copied from the first input file with at least one chapter. Use a negative file index to disable any chapter copying. @item -debug Print specific debug info. -@item -benchmark +@item -benchmark (@emph{global}) Show benchmarking information at the end of an encode. Shows CPU time used and maximum memory consumption. Maximum memory consumption is not supported on all systems, it will usually display as 0 if not supported. -@item -dump +@item -dump (@emph{global}) Dump each input packet. -@item -hex +@item -hex (@emph{global}) When dumping packets, also dump the payload. -@item -bitexact -Only use bit exact algorithms (for codec testing). @item -ps @var{size} Set RTP payload size in bytes. -@item -re +@item -re (@emph{input}) Read input at native frame rate. Mainly used to simulate a grab device. @item -threads @var{count} Thread count. @@ -707,11 +690,11 @@ Copy input stream time base from input to output when stream copying. Finish encoding when the shortest input stream ends. @item -dts_delta_threshold Timestamp discontinuity delta threshold. -@item -muxdelay @var{seconds} +@item -muxdelay @var{seconds} (@emph{input}) Set the maximum demux-decode delay. -@item -muxpreload @var{seconds} +@item -muxpreload @var{seconds} (@emph{input}) Set the initial demux-decode delay. -@item -streamid @var{output-stream-index}:@var{new-value} +@item -streamid @var{output-stream-index}:@var{new-value} (@emph{output}) Assign a new stream-id value to an output stream. This option should be specified prior to the output filename to which it applies. For the situation where multiple output files exist, a streamid @@ -723,7 +706,7 @@ an output mpegts file: avconv -i infile -streamid 0:33 -streamid 1:36 out.ts @end example -@item -bsf[:@var{stream_specifier}] @var{bitstream_filters} +@item -bsf[:@var{stream_specifier}] @var{bitstream_filters} (@emph{output,per-stream}) Set bitstream filters for matching streams. @var{bistream_filters} is a comma-separated list of bitstream filters. Use the @code{-bsfs} option to get the list of bitstream filters. @@ -734,7 +717,7 @@ avconv -i h264.mp4 -c:v copy -vbsf h264_mp4toannexb -an out.h264 avconv -i file.mov -an -vn -sbsf mov2textsub -c:s copy -f rawvideo sub.txt @end example -@item -tag[:@var{stream_specifier}] @var{codec_tag} +@item -tag[:@var{stream_specifier}] @var{codec_tag} (@emph{output,per-stream}) Force a tag/fourcc for matching streams. @end table @c man end OPTIONS From f39ecc79aa769677777fc3d6b8de6440bcda3c3f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 5 Sep 2011 14:11:13 +0200 Subject: [PATCH 28/31] avconv: fix inverted variable --- avconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index e8c48bb6b0..471ed00e2e 100644 --- a/avconv.c +++ b/avconv.c @@ -3489,7 +3489,7 @@ static void opt_output_file(void *optctx, const char *filename) } if (o->chapters_input_file >= 0) copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1], - o->metadata_chapters_manual); + !o->metadata_chapters_manual); /* copy metadata */ for (i = 0; i < o->nb_meta_data_maps; i++) { From 4bb3ae1eaa170add52232519c43226ef773c214f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 5 Sep 2011 14:12:28 +0200 Subject: [PATCH 29/31] avconv: use correct index when selecting metadata to write to. --- avconv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avconv.c b/avconv.c index 471ed00e2e..74120c8c5e 100644 --- a/avconv.c +++ b/avconv.c @@ -3571,14 +3571,14 @@ static void opt_output_file(void *optctx, const char *filename) av_log(NULL, AV_LOG_ERROR, "Invalid stream index %d in metadata specifier.\n", index); exit_program(1); } - m = &oc->streams[i]->metadata; + m = &oc->streams[index]->metadata; break; case 'c': if (index < 0 || index >= oc->nb_chapters) { av_log(NULL, AV_LOG_ERROR, "Invalid chapter index %d in metadata specifier.\n", index); exit_program(1); } - m = &oc->chapters[i]->metadata; + m = &oc->chapters[index]->metadata; break; default: av_log(NULL, AV_LOG_ERROR, "Invalid metadata specifier %s.\n", o->metadata[i].specifier); From 3a0b5fa5e8f0f3eccbbe38b179ea458e98751011 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 11 Sep 2011 01:06:57 +0200 Subject: [PATCH 30/31] audioconvert: K&R whitespace cosmetics Signed-off-by: Diego Biurrun --- libavutil/audioconvert.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavutil/audioconvert.c b/libavutil/audioconvert.c index fa27f0168b..d6a4b8a4f2 100644 --- a/libavutil/audioconvert.c +++ b/libavutil/audioconvert.c @@ -91,13 +91,14 @@ void av_get_channel_layout_string(char *buf, int buf_size, snprintf(buf, buf_size, "%d channels", nb_channels); if (channel_layout) { - int i,ch; + int i, ch; av_strlcat(buf, " (", buf_size); - for(i=0,ch=0; i<64; i++) { - if ((channel_layout & (1L<0) av_strlcat(buf, "|", buf_size); + if (ch > 0) + av_strlcat(buf, "|", buf_size); av_strlcat(buf, name, buf_size); } ch++; From 6cfed1127005e9d79e03b4b04fd75124a291d3db Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 11 Sep 2011 01:07:08 +0200 Subject: [PATCH 31/31] audioconvert: add explanatory comments to channel_names array Signed-off-by: Diego Biurrun --- libavutil/audioconvert.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libavutil/audioconvert.c b/libavutil/audioconvert.c index d6a4b8a4f2..7250e36d90 100644 --- a/libavutil/audioconvert.c +++ b/libavutil/audioconvert.c @@ -28,11 +28,26 @@ #include "audioconvert.h" static const char * const channel_names[] = { - "FL", "FR", "FC", "LFE", "BL", "BR", "FLC", "FRC", - "BC", "SL", "SR", "TC", "TFL", "TFC", "TFR", "TBL", - "TBC", "TBR", - [29] = "DL", - [30] = "DR", + [0] = "FL", /* front left */ + [1] = "FR", /* front right */ + [2] = "FC", /* front center */ + [3] = "LFE", /* low frequency */ + [4] = "BL", /* back left */ + [5] = "BR", /* back right */ + [6] = "FLC", /* front left-of-center */ + [7] = "FRC", /* front right-of-center */ + [8] = "BC", /* back-center */ + [9] = "SL", /* side left */ + [10] = "SR", /* side right */ + [11] = "TC", /* top center */ + [12] = "TFL", /* top front left */ + [13] = "TFC", /* top front center */ + [14] = "TFR", /* top front right */ + [15] = "TBL", /* top back left */ + [16] = "TBC", /* top back center */ + [17] = "TBR", /* top back right */ + [29] = "DL", /* downmix left */ + [30] = "DR", /* downmix right */ }; static const char *get_channel_name(int channel_id)