From patchwork Thu Feb 4 21:02:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bohan Li X-Patchwork-Id: 25442 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 8397844A536 for ; Thu, 4 Feb 2021 23:02:32 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5E56C68A2A9; Thu, 4 Feb 2021 23:02:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9CB668A141 for ; Thu, 4 Feb 2021 23:02:25 +0200 (EET) Received: by mail-pl1-f201.google.com with SMTP id k16so2918834plk.20 for ; Thu, 04 Feb 2021 13:02:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=eQ1a3WfOoBmUmgjoSRHlidVpw2496aVMDz20DkDFxKQ=; b=fcn9K+X8GdQRXqBRmPhymcMQdXHgpMqTidCF1IaJ9HpELkIA7n588948u4FQfqpB6R nW2QEZgJUc5hNwjKAFPtgCgjuvehDd2h6KIYgWhJW2SRkfYwbAGJYfaHZJO9H07lVBii y7ALBBiBYsRPVKYxZ3ZS6pXpeCNe6jW53TkmvLWNoa8ewmB/dVQipFrvg1XRoUrtJQAd r6AL+ENOS/SL/VXS7RxyeWHrKM6vNR82L22x+66xeEdMX9SxDxduFiuLgL1SZfdG3Hmf sSbfnYmWENXJ7RyqafPvOMOr/vdtclP2xic1Av7YBN9V9xswtabE/Wumcfw+DvKIWZXZ Ceag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=eQ1a3WfOoBmUmgjoSRHlidVpw2496aVMDz20DkDFxKQ=; b=mfJupsYZOd9wnmdmLDSN36TW6U0xUIc1Ic5xhVsNh2aXetppi2O8ELCGvJBUhAWAbH bOMwNf3BWK4XRVl1Oa5QxAsDfdCv/9xLWf87m7TEwMsanrGlMUKBa2Q9CpFuDB8NX/5k EV0LP0tMXkmLjn4ILwR6MA6NcYyhhCgstDr2oe0YjY0qWpbbZF2EKTnWlXWHbdy91N9l /K0W92IIPEC94mYNobw3AeM8KgMFZy3nCKoMtJgKBWseLxTDY2CAQEUJtvSDWnsuS7Vc GcMlI4IKVwcUQO1SyxJyzLF/9I6cMVf3a+0NBZSoNw4m304ozVgVsEyVVg+CsRHWzyH1 bp6w== X-Gm-Message-State: AOAM531IUSSBU0/GlYjH2zdfmnvQpkF9uwzeb05rJu1hbzJ7NO5zVnzO 2bWjSPS/Il6zqRqGfYde8i/loYlsH1sdIYIeG/qUV9H5Pf5ONvHNfz3sa292NouhcMVpmJcdGYv GSvF9ArkrhdvOO67ujuqnpZDzjb29u1b6LufZsBFLUHizoZP+uLmkn3aN0NeCgNZ4kg== X-Google-Smtp-Source: ABdhPJwYYjlWP1GIPYiz33hMsdTGj8XhqvdS+eFoFksene96bNjLsfavZUNFrASmhAsahygCQXSZ8lZyGSo0 X-Received: from bohanli.mtv.corp.google.com ([2620:0:1000:2511:2dff:abe0:783e:348c]) (user=bohanli job=sendgmr) by 2002:a05:6a00:851:b029:1b3:fbb3:faed with SMTP id q17-20020a056a000851b02901b3fbb3faedmr1299660pfk.18.1612472543529; Thu, 04 Feb 2021 13:02:23 -0800 (PST) Date: Thu, 4 Feb 2021 13:02:20 -0800 In-Reply-To: <20210204000142.4135063-2-bohanli@google.com> Message-Id: <20210204210220.219884-1-bohanli@google.com> Mime-Version: 1.0 References: <20210204000142.4135063-2-bohanli@google.com> 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 | 11 +++++++++++ libavcodec/libaomenc.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/doc/encoders.texi b/doc/encoders.texi index c2ba7d3e6f..9fab512892 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1684,6 +1684,17 @@ 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 ":". For a list of supported options, see @command{aomenc --help} under the +section "AV1 Specific 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..c7a87e01cd 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,25 @@ 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; + int width = -30; + int res; + + av_log(avctx, AV_LOG_DEBUG, " %*s: %s\n", width, key, value); + + res = aom_codec_set_option(&ctx->encoder, key, value); + if (res != AOM_CODEC_OK) { + log_encoder_error(avctx, key); + return AVERROR(EINVAL); + } + + return 0; +} + static av_cold int aom_free(AVCodecContext *avctx) { AOMContext *ctx = avctx->priv_data; @@ -874,6 +894,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 +1328,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 }, };