diff options
author | James Almer <jamrial@gmail.com> | 2019-08-14 04:07:08 +0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2020-01-01 19:25:18 +0300 |
commit | 3c22436ddf5995dd2be7f54c0301a737e22056c8 (patch) | |
tree | 62fac9450c8ef1698f0e166adfa64b8728767384 /libavcodec/libx265.c | |
parent | 40d9cbdc22340572ea5ebe5fe77c73eafafabef8 (diff) |
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>
Diffstat (limited to 'libavcodec/libx265.c')
-rw-r--r-- | libavcodec/libx265.c | 41 |
1 files changed, 41 insertions, 0 deletions
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 }, }; |