diff mbox series

[FFmpeg-devel,v6,2/5] lavc/libopenh264enc: add default gop size and bit rate

Message ID 1588129250-30726-2-git-send-email-linjie.fu@intel.com
State Accepted
Commit e5f097eca78342bf34a70f4c43c61238c8ae41c2
Headers show
Series [FFmpeg-devel,v6,1/5] lavc/libopenh264enc: Add qmin/qmax support | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Fu, Linjie April 29, 2020, 3 a.m. UTC
It would be 200kbps bitrate with gop size = 12 by default
which generated too many IDR frames in rather low bit rate.
The quality would be poor.

Set these default values to -1 to check whether it's specified
by user explicitly.

Use 2Mbps bitrate as nvenc sugguested, and leave gop size
untouched in libopenh264.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 libavcodec/libopenh264enc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Martin Storsjö April 29, 2020, 8:52 a.m. UTC | #1
On Wed, 29 Apr 2020, Linjie Fu wrote:

> It would be 200kbps bitrate with gop size = 12 by default
> which generated too many IDR frames in rather low bit rate.
> The quality would be poor.
>
> Set these default values to -1 to check whether it's specified
> by user explicitly.
>
> Use 2Mbps bitrate as nvenc sugguested, and leave gop size
> untouched in libopenh264.
>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
> libavcodec/libopenh264enc.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
> index 265eb9c..245752d 100644
> --- a/libavcodec/libopenh264enc.c
> +++ b/libavcodec/libopenh264enc.c
> @@ -37,6 +37,8 @@
> #define SM_SIZELIMITED_SLICE SM_DYN_SLICE
> #endif
> 
> +#define TARGET_BITRATE_DEFAULT 2*1000*1000
> +
> typedef struct SVCContext {
>     const AVClass *av_class;
>     ISVCEncoder *encoder;
> @@ -132,7 +134,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>     param.fMaxFrameRate              = 1/av_q2d(avctx->time_base);
>     param.iPicWidth                  = avctx->width;
>     param.iPicHeight                 = avctx->height;
> -    param.iTargetBitrate             = avctx->bit_rate;
> +    param.iTargetBitrate             = avctx->bit_rate > 0 ? avctx->bit_rate : TARGET_BITRATE_DEFAULT;
>     param.iMaxBitrate                = FFMAX(avctx->rc_max_rate, avctx->bit_rate);
>     param.iRCMode                    = RC_QUALITY_MODE;
>     if (avctx->qmax >= 0)
> @@ -147,7 +149,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>     param.bEnableFrameSkip           = s->skip_frames;
>     param.bEnableLongTermReference   = 0;
>     param.iLtrMarkPeriod             = 30;
> -    param.uiIntraPeriod              = avctx->gop_size;
> +    if (avctx->gop_size >= 0)
> +        param.uiIntraPeriod          = avctx->gop_size;
> #if OPENH264_VER_AT_LEAST(1, 4)
>     param.eSpsPpsIdStrategy          = CONSTANT_ID;
> #else
> @@ -336,6 +339,8 @@ static int svc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
> }
> 
> static const AVCodecDefault svc_enc_defaults[] = {
> +    { "b",         "0"     },
> +    { "g",         "-1"    },
>     { "qmin",      "-1"    },
>     { "qmax",      "-1"    },
>     { NULL },
> -- 
> 2.7.4

LGTM

// Martin
diff mbox series

Patch

diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 265eb9c..245752d 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -37,6 +37,8 @@ 
 #define SM_SIZELIMITED_SLICE SM_DYN_SLICE
 #endif
 
+#define TARGET_BITRATE_DEFAULT 2*1000*1000
+
 typedef struct SVCContext {
     const AVClass *av_class;
     ISVCEncoder *encoder;
@@ -132,7 +134,7 @@  FF_ENABLE_DEPRECATION_WARNINGS
     param.fMaxFrameRate              = 1/av_q2d(avctx->time_base);
     param.iPicWidth                  = avctx->width;
     param.iPicHeight                 = avctx->height;
-    param.iTargetBitrate             = avctx->bit_rate;
+    param.iTargetBitrate             = avctx->bit_rate > 0 ? avctx->bit_rate : TARGET_BITRATE_DEFAULT;
     param.iMaxBitrate                = FFMAX(avctx->rc_max_rate, avctx->bit_rate);
     param.iRCMode                    = RC_QUALITY_MODE;
     if (avctx->qmax >= 0)
@@ -147,7 +149,8 @@  FF_ENABLE_DEPRECATION_WARNINGS
     param.bEnableFrameSkip           = s->skip_frames;
     param.bEnableLongTermReference   = 0;
     param.iLtrMarkPeriod             = 30;
-    param.uiIntraPeriod              = avctx->gop_size;
+    if (avctx->gop_size >= 0)
+        param.uiIntraPeriod          = avctx->gop_size;
 #if OPENH264_VER_AT_LEAST(1, 4)
     param.eSpsPpsIdStrategy          = CONSTANT_ID;
 #else
@@ -336,6 +339,8 @@  static int svc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 }
 
 static const AVCodecDefault svc_enc_defaults[] = {
+    { "b",         "0"     },
+    { "g",         "-1"    },
     { "qmin",      "-1"    },
     { "qmax",      "-1"    },
     { NULL },