[FFmpeg-devel] [PATCH 1/3] avcodec/libx265: apply some global AVCodecContext settings to the encoder context

James Almer jamrial at gmail.com
Sun Dec 29 01:55:12 EET 2019


There's no reason to ignore them if set.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 doc/encoders.texi    | 14 ++++++++++++++
 libavcodec/libx265.c | 13 +++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index a207363650..673eaf6496 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2415,6 +2415,20 @@ during configuration. You need to explicitly configure the build with
 @subsection Options
 
 @table @option
+ at item b
+Sets target video bitrate.
+
+ at item bf
+
+ at item g
+Set the GOP size.
+
+ at item keyint_min
+Minimum GOP size.
+
+ at item refs
+Number of reference frames each P-frame can use. The range is from @var{1-16}.
+
 @item preset
 Set the x265 preset.
 
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 963c28fb1d..508fade98b 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -241,6 +241,15 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
     if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
         ctx->params->bRepeatHeaders = 1;
 
+    if (avctx->gop_size >= 0)
+        ctx->params->keyframeMax = avctx->gop_size;
+    if (avctx->keyint_min > 0)
+        ctx->params->keyframeMin = avctx->keyint_min;
+    if (avctx->max_b_frames >= 0)
+        ctx->params->bframes = avctx->max_b_frames;
+    if (avctx->refs >= 0)
+        ctx->params->maxNumReferences = avctx->refs;
+
     if (ctx->x265_opts) {
         AVDictionary *dict    = NULL;
         AVDictionaryEntry *en = NULL;
@@ -556,6 +565,10 @@ static const AVClass class = {
 
 static const AVCodecDefault x265_defaults[] = {
     { "b", "0" },
+    { "bf", "-1" },
+    { "g", "-1" },
+    { "keyint_min", "-1" },
+    { "refs", "-1" },
     { NULL },
 };
 
-- 
2.24.1



More information about the ffmpeg-devel mailing list