[FFmpeg-devel] [PATCH v2 6/6] avcodec/libsvtav1: support constant quality mode

lance.lmwang at gmail.com lance.lmwang at gmail.com
Sat Sep 18 04:26:45 EEST 2021


From: Limin Wang <lance.lmwang at gmail.com>

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 doc/encoders.texi      | 10 ++++++++--
 libavcodec/libsvtav1.c | 10 +++++++++-
 libavcodec/version.h   |  2 +-
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 64d604e..e7f61ff 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1807,8 +1807,11 @@ Set the rate control mode to use.
 Possible modes:
 @table @option
 @item cqp
-Constant quantizer: use fixed values of qindex (dependent on the frame type)
-throughout the stream.  This mode is the default.
+Constant quantizer(crf: -1): use fixed values of qindex (dependent on the frame type)
+throughout the stream.
+
+Constant quality(crf > 0): maintain a constant QP throughout the stream. This mode is
+the default.
 
 @item vbr
 Variable bitrate: use a target bitrate for the whole stream.
@@ -1826,6 +1829,9 @@ Set the minimum quantizer to use when using a bitrate mode.
 @item qp
 Set the quantizer used in cqp rate control mode (0-63).
 
+ at item crf
+Select the quality for constant quality mode (0-63).
+
 @item sc_detection
 Enable scene change detection.
 
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 509d92d..f982bb6 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -66,6 +66,7 @@ typedef struct SvtContext {
     int rc_mode;
     int scd;
     int qp;
+    int crf;
 
     int tier;
 
@@ -210,6 +211,10 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
         param->min_qp_allowed       = avctx->qmin;
     } else {
         param->enable_tpl_la = 0; /* CQP need turn off enable_tp_la */
+        if ( svt_enc->crf > 0) {
+            param->qp = svt_enc->crf;
+            param->enable_tpl_la = 1;
+        }
     }
 
     /* 2 = IDR, closed GOP, 1 = CRA, open GOP */
@@ -523,13 +528,16 @@ static const AVOption options[] = {
 
     { "rc", "Bit rate control mode", OFFSET(rc_mode),
       AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, VE , "rc"},
-        { "cqp", "Constant quantizer", 0, AV_OPT_TYPE_CONST, { .i64 = 0 },  INT_MIN, INT_MAX, VE, "rc" },
+        { "cqp", "Constant quantizer(crf: -1), Constant quality(crf > 0)", 0, AV_OPT_TYPE_CONST, { .i64 = 0 },  INT_MIN, INT_MAX, VE, "rc" },
         { "vbr", "Variable Bit Rate, use a target bitrate for the entire stream", 0, AV_OPT_TYPE_CONST, { .i64 = 1 },  INT_MIN, INT_MAX, VE, "rc" },
         { "cvbr", "Constrained Variable Bit Rate, use a target bitrate for each GOP", 0, AV_OPT_TYPE_CONST,{ .i64 = 2 },  INT_MIN, INT_MAX, VE, "rc" },
 
     { "qp", "Quantizer to use with cqp rate control mode", OFFSET(qp),
       AV_OPT_TYPE_INT, { .i64 = 50 }, 0, 63, VE },
 
+    { "crf", "Select the quality for constant quality mode, set to -1 for cqp rate control mode", OFFSET(crf),
+      AV_OPT_TYPE_INT, { .i64 = 50 }, -1, 63, VE },
+
     { "sc_detection", "Scene change detection", OFFSET(scd),
       AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 4b4fe54..b0a741b 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  59
 #define LIBAVCODEC_VERSION_MINOR   7
-#define LIBAVCODEC_VERSION_MICRO 103
+#define LIBAVCODEC_VERSION_MICRO 104
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list