[FFmpeg-cvslog] avconv: rewrite -qscale and -aq handling.

Anton Khirnov git at videolan.org
Mon Sep 12 00:38:57 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Thu Sep  1 10:04:35 2011 +0200| [77d9c4542c129276fedefeca089c5759e5fe6353] | committer: Anton Khirnov

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=77d9c4542c129276fedefeca089c5759e5fe6353
---

 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 fc8a29a..347b476 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*)&copy_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 d9c1461..62f21f0 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.
 
+ at item -q @var{q}
+ at 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.
- at 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 303e7bd..7cd9f7f 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
 }
 



More information about the ffmpeg-cvslog mailing list