diff options
author | James Almer <jamrial@gmail.com> | 2019-08-13 22:07:08 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2020-01-01 13:25:18 -0300 |
commit | 3c22436ddf5995dd2be7f54c0301a737e22056c8 (patch) | |
tree | 62fac9450c8ef1698f0e166adfa64b8728767384 | |
parent | 40d9cbdc22340572ea5ebe5fe77c73eafafabef8 (diff) | |
download | ffmpeg-3c22436ddf5995dd2be7f54c0301a737e22056c8.tar.gz |
avcodec/libx265: apply some global AVCodecContext settings to the encoder context
There's no reason to ignore them if set.
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r-- | doc/encoders.texi | 14 | ||||
-rw-r--r-- | libavcodec/libx265.c | 41 |
2 files changed, 55 insertions, 0 deletions
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..798ba12efa 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -82,10 +82,26 @@ static av_cold int libx265_encode_close(AVCodecContext *avctx) return 0; } +static av_cold int libx265_param_parse_int(AVCodecContext *avctx, + const char *key, int value) +{ + libx265Context *ctx = avctx->priv_data; + char buf[256]; + + snprintf(buf, sizeof(buf), "%d", value); + if (ctx->api->param_parse(ctx->params, key, buf) == X265_PARAM_BAD_VALUE) { + av_log(avctx, AV_LOG_ERROR, "Invalid value %d for param \"%s\".\n", value, key); + return AVERROR(EINVAL); + } + + return 0; +} + static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; AVCPBProperties *cpb_props = NULL; + int ret; ctx->api = x265_api_get(av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth); if (!ctx->api) @@ -241,6 +257,27 @@ 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) { + ret = libx265_param_parse_int(avctx, "keyint", avctx->gop_size); + if (ret < 0) + return ret; + } + if (avctx->keyint_min > 0) { + ret = libx265_param_parse_int(avctx, "min-keyint", avctx->keyint_min); + if (ret < 0) + return ret; + } + if (avctx->max_b_frames >= 0) { + ret = libx265_param_parse_int(avctx, "bframes", avctx->max_b_frames); + if (ret < 0) + return ret; + } + if (avctx->refs >= 0) { + ret = libx265_param_parse_int(avctx, "ref", avctx->refs); + if (ret < 0) + return ret; + } + if (ctx->x265_opts) { AVDictionary *dict = NULL; AVDictionaryEntry *en = NULL; @@ -556,6 +593,10 @@ static const AVClass class = { static const AVCodecDefault x265_defaults[] = { { "b", "0" }, + { "bf", "-1" }, + { "g", "-1" }, + { "keyint_min", "-1" }, + { "refs", "-1" }, { NULL }, }; |