diff mbox

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

Message ID 20191228235514.5335-1-jamrial@gmail.com
State Superseded
Headers show

Commit Message

James Almer Dec. 28, 2019, 11:55 p.m. UTC
There's no reason to ignore them if set.

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

Comments

Derek Buitenhuis Dec. 30, 2019, 5:06 p.m. UTC | #1
On 28/12/2019 23:55, James Almer wrote:
> +    if (avctx->gop_size >= 0)
> +        ctx->params->keyframeMax = avctx->gop_size;

For this patch and the others, you should call x265_param_parse with the
correct key for these (kind of how librav1e.c does). x265 is not great at
struct ABI compatability, and this function is always part of the ABI.

- Derek
diff mbox

Patch

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
+@item b
+Sets target video bitrate.
+
+@item bf
+
+@item g
+Set the GOP size.
+
+@item keyint_min
+Minimum GOP size.
+
+@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 },
 };