[FFmpeg-devel] [PATCH] Add support for the new key & value API in libaom.
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Thu Feb 4 07:11:13 EET 2021
Bohan Li:
> This key & value API can greatly help with users who wants to try
> libaom-av1 specific options that are not supported by ffmpeg options.
>
> As was previously discussed in this thread:
> https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2020-October/271658.
>
> The commit that added the API to libaom:
> https://aomedia.googlesource.com/aom/+/c1d42fe6615c96fc929257
>
> The libaom issue tracker:
> https://bugs.chromium.org/p/aomedia/issues/detail?id=2875
>
> Signed-off-by: Bohan Li <bohanli at google.com>
> ---
> doc/encoders.texi | 10 ++++++++++
> libavcodec/libaomenc.c | 32 ++++++++++++++++++++++++++++++++
> 2 files changed, 42 insertions(+)
>
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index c2ba7d3e6f..3f32303b3d 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -1684,6 +1684,16 @@ Enable interintra compound. Default is true.
> @item enable-smooth-interintra (@emph{boolean}) (Requires libaom >= v2.0.0)
> Enable smooth interintra mode. Default is true.
>
> + at item libaom-params
> +Set libaom options using a list of @var{key}=@var{value} pairs separated
> +by ":". See @command{aomenc --help} for a list of options.
> +
> +For example to specify libaom encoding options with @option{-libaom-params}:
> +
> + at example
> +ffmpeg -i input -c:v libaom-av1 -b:v 500K -libaom-params tune=psnr:enable-tpl-model=1 output.mp4
> + at end example
> +
> @end table
>
> @section libsvtav1
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index 342d0883e4..b7c5a64417 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -124,6 +124,7 @@ typedef struct AOMEncoderContext {
> int enable_diff_wtd_comp;
> int enable_dist_wtd_comp;
> int enable_dual_filter;
> + AVDictionary *extra_params;
> } AOMContext;
>
> static const char *const ctlidstr[] = {
> @@ -318,6 +319,27 @@ static av_cold int codecctl_int(AVCodecContext *avctx,
> return 0;
> }
>
> +static av_cold int codec_set_option(AVCodecContext *avctx,
> + const char* key,
> + const char* value)
> +{
> + AOMContext *ctx = avctx->priv_data;
> + char buf[80];
> + int width = -30;
> + int res;
> +
> + snprintf(buf, sizeof(buf), "%s:", key);
> + av_log(avctx, AV_LOG_DEBUG, " %*s%s: %s\n", width, buf, key, value);
This will print key twice (unless your key is so long that it doesn't
fit into buf anymore). Actually, I do not get why you use buf at all.
> +
> + res = aom_codec_set_option(&ctx->encoder, key, value);
> + if (res != AOM_CODEC_OK) {
> + log_encoder_error(avctx, buf);
Unless key is oversized, your string will already end with a ':' and the
message from log_encoder_error will contain a "::". So this is one more
reason to get rid of buf.
> + return AVERROR(EINVAL);
> + }
> +
> + return 0;
> +}
> +
> static av_cold int aom_free(AVCodecContext *avctx)
> {
> AOMContext *ctx = avctx->priv_data;
> @@ -874,6 +896,15 @@ static av_cold int aom_init(AVCodecContext *avctx,
> codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC, ctx->enable_intrabc);
> #endif
>
> +#if AOM_ENCODER_ABI_VERSION >= 23
> + {
> + AVDictionaryEntry *en = NULL;
> + while ((en = av_dict_get(ctx->extra_params, "", en, AV_DICT_IGNORE_SUFFIX))) {
> + codec_set_option(avctx, en->key, en->value);
> + }
> + }
> +#endif
> +
> // provide dummy value to initialize wrapper, values will be updated each _encode()
> aom_img_wrap(&ctx->rawimg, img_fmt, avctx->width, avctx->height, 1,
> (unsigned char*)1);
> @@ -1299,6 +1330,7 @@ static const AVOption options[] = {
> { "enable-masked-comp", "Enable masked compound", OFFSET(enable_masked_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> { "enable-interintra-comp", "Enable interintra compound", OFFSET(enable_interintra_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> { "enable-smooth-interintra", "Enable smooth interintra mode", OFFSET(enable_smooth_interintra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> + { "libaom-params", "Extra parameters for libaom", OFFSET(extra_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
> { NULL },
> };
>
>
More information about the ffmpeg-devel
mailing list