From patchwork Thu Feb 4 00:01:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bohan Li X-Patchwork-Id: 25378 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 06F93449BE7 for ; Thu, 4 Feb 2021 02:01:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C39EB6898A8; Thu, 4 Feb 2021 02:01:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 463F2680679 for ; Thu, 4 Feb 2021 02:01:47 +0200 (EET) Received: by mail-pj1-f73.google.com with SMTP id a22so650150pjs.2 for ; Wed, 03 Feb 2021 16:01:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=iPjLNruTVsgNNSQgL5845vs90o3kt05gqwCgtO4nEfY=; b=DscjIFs5MHajJz+PicpTRZtIhyQxwxlUxaS6/fwizo9NQyof6D0iOgMZ3mZYGyIdeq Jo5skHsLPcn5Btz5BWF/uQvIGO3PXBLAK5cuBeTF43dShv8TwreYDsjFCq6fwPZ3Cz5W qKrMEGLSn4DEDe0O8qACSadN77/B9o/H9LSa6Fxf1YPxA6CRyF5K7Fy0z7eUhOZaKhAT u5Wwwaav29RPbJdlPC+8fVFOj1aQMXSFWVd0b19qXwQueX2S7HjdtfNe1DO2jCHcniUW QovwrKq9aUpPMWWx1oUoLhat9hotgrr0lwusJ1sv2AharFQj1t3o2Fd13Oa9R/uTui0+ rsHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=iPjLNruTVsgNNSQgL5845vs90o3kt05gqwCgtO4nEfY=; b=gz0vyfUv9k3QdFZ6jayW87uCOYRdpEXUFZ/wjPruNy+lAb/+aFm0FNpeIMuXpXcKX5 n/3V8iVecmMizm5YlMdUtAw0O49pjyJswg2NOZwmQf+JclCEqk5wknjFKbwydGGpRmKH gSMif5StaSRoab40IlHxPif+aRSaunjImEYCCwNqw2+2BblJq4VGW9wJ2U2YXf1AlmGW zzVCmp+WDCQpDGmA6a388vQECXdM58zIoNc4POlKO5+GVcXKZPwRoFVDHyx8qJ6qB3ng DFn7x4B0De3C32xjmIIuF4I9HchbvffdnvNo5E3YKcYvykbuCvQ742EQ9ufNb+hxeK8k ZiUQ== X-Gm-Message-State: AOAM531FYP7NRLpzeBdJUQkklyTR0fXnJFmF1fyckgEL4wZpKQCcVMX5 5NFeVo29FZI0b/VZQUYs/qWLomke1dGB3PYMy2Xzq9OYgoJ5YopOlQbrFVranb5lFIo3drVDTiV 9iHH6YfxrdLLdjHLoXEIeUN/juNm3IXdICIQZWH11AzoL7fTDaMQQpMdVG8uH+NrpbQ== X-Google-Smtp-Source: ABdhPJwFvWKtT+TkI8xqjW24ay31y5XW79EwVKYUCMR7IiACHKCwP4Yy5NM8OqUq3sgIKss0A2da+M4+eIXU X-Received: from bohanli.mtv.corp.google.com ([2620:0:1000:2511:2dff:abe0:783e:348c]) (user=bohanli job=sendgmr) by 2002:a63:a804:: with SMTP id o4mr6324658pgf.67.1612396905221; Wed, 03 Feb 2021 16:01:45 -0800 (PST) Date: Wed, 3 Feb 2021 16:01:41 -0800 Message-Id: <20210204000142.4135063-1-bohanli@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog From: Bohan Li To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] Add support for the new key & value API in libaom. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Bohan Li Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- 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. +@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}: + +@example +ffmpeg -i input -c:v libaom-av1 -b:v 500K -libaom-params tune=psnr:enable-tpl-model=1 output.mp4 +@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); + + res = aom_codec_set_option(&ctx->encoder, key, value); + if (res != AOM_CODEC_OK) { + log_encoder_error(avctx, 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 }, };