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

lance.lmwang at gmail.com lance.lmwang at gmail.com
Thu Sep 16 13:54:17 EEST 2021


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

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

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 64d604e..2300bb9 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1807,9 +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)
+Constant quantizer(not set crf): use fixed values of qindex (dependent on the frame type)
 throughout the stream.  This mode is the default.
 
+Constant quality(set crf): maintain a constant QP throughout the stream.
+
 @item vbr
 Variable bitrate: use a target bitrate for the whole stream.
 
@@ -1826,6 +1828,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 1f1f86b..29be4bd 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, 3, VE , "rc"},
-        { "cqp", "Constant quantizer", 0, AV_OPT_TYPE_CONST, { .i64 = 0 },  INT_MIN, INT_MAX, VE, "rc" },
+        { "cqp", "Constant quantizer(not set crf), Constant quality(set crf)", 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", OFFSET(crf),
+      AV_OPT_TYPE_INT, { .i64 = -1 }, -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