]> git.sesse.net Git - ffmpeg/commitdiff
lavc/libopenh264enc: Add qmin/qmax support
authorLinjie Fu <linjie.fu@intel.com>
Wed, 29 Apr 2020 03:00:46 +0000 (11:00 +0800)
committerMartin Storsjö <martin@martin.st>
Wed, 29 Apr 2020 17:58:17 +0000 (20:58 +0300)
Clip iMinQp/iMaxQp to (1, 51) for user specified qp range.

If not set, leave iMinQp/iMaxQp untouched and use the values (0, 51)
initialized in FillDefault(), and the QP range would be adjusted to the
defaults inside libopenh264 library according to the iUsageType, (12, 42)
for iUsageType == CAMERA_VIDEO_REAL_TIME which is default.

<https://github.com/cisco/openh264/blob/master/codec/encoder/core/src/encoder_ext.cpp#L375>

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
libavcodec/libopenh264enc.c

index dd5d4ee7b9a7d67de515cdf2fc7422b1773b2ee1..265eb9c941150b9ed999e0c998bb1c73072f13e7 100644 (file)
@@ -135,6 +135,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
     param.iTargetBitrate             = avctx->bit_rate;
     param.iMaxBitrate                = FFMAX(avctx->rc_max_rate, avctx->bit_rate);
     param.iRCMode                    = RC_QUALITY_MODE;
+    if (avctx->qmax >= 0)
+        param.iMaxQp                 = av_clip(avctx->qmax, 1, 51);
+    if (avctx->qmin >= 0)
+        param.iMinQp                 = av_clip(avctx->qmin, 1, param.iMaxQp);
     param.iTemporalLayerNum          = 1;
     param.iSpatialLayerNum           = 1;
     param.bEnableDenoise             = 0;
@@ -331,6 +335,12 @@ static int svc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     return 0;
 }
 
+static const AVCodecDefault svc_enc_defaults[] = {
+    { "qmin",      "-1"    },
+    { "qmax",      "-1"    },
+    { NULL },
+};
+
 AVCodec ff_libopenh264_encoder = {
     .name           = "libopenh264",
     .long_name      = NULL_IF_CONFIG_SMALL("OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
@@ -344,6 +354,7 @@ AVCodec ff_libopenh264_encoder = {
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
     .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
                                                     AV_PIX_FMT_NONE },
+    .defaults       = svc_enc_defaults,
     .priv_class     = &class,
     .wrapper_name   = "libopenh264",
 };