From patchwork Thu Feb 4 00:01:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bohan Li X-Patchwork-Id: 25380 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 2D792449EE0 for ; Thu, 4 Feb 2021 02:02:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 125B8689AA6; Thu, 4 Feb 2021 02:02:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 11D97689A91 for ; Thu, 4 Feb 2021 02:02:07 +0200 (EET) Received: by mail-qk1-f201.google.com with SMTP id q7so1065592qkn.7 for ; Wed, 03 Feb 2021 16:02:07 -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=iPjLNruTVsgNNSQgL5845vs90o3kt05gqwCgtO4nEfY=; b=vK61WM+g5DzhPMOVX8OwD4mt4JTKuwZ2i/Xz7IVD2zllQxcE8yjRKqLTcFgB5XIoxx AC41cb1SgG4eB1rYCFQxjaJPukyB+XaKd10Jcd3dGJHFuin3OeqsZHH074hn7cswYmK/ ddnBs4o9D3IaVl0//xPrbqGvQ1SJvlS5j5weRCq1nOLw1HNySSCQpZ1mSwckcnx5xg6P IxxcFdFFKZ6uYiEeO+TOKomH589CIlEx1UJ2ddqVN6zC7O6B4c+MgbYpwe88yFpeV931 a7411bP6dyOpkXPFShoCPhukqK+txlzEHZpaRmuJ4NgFmbjNI1+/RUxy8hAowW9t794L Gssw== 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=iPjLNruTVsgNNSQgL5845vs90o3kt05gqwCgtO4nEfY=; b=hP4jVIL9y7++3RKDhigWxbMDr8p0Q9qe0eKBBrzFEmorYYUCGYIzeGdlkep0Ab7WHl 1nJ2kEH0zgM3Z3KJ8zgtBWM5L/fd+h7WB4/hhBd/liUXyD4n8fWyprb5Ez5Pm6Ri9Qh8 n4LPmky8KWjXKvg+RTDnThOeVW3Ii4b18Wc2fLXo5WWY9NOp6r9FIiQ8nNU2EPotJzm7 Lg/ggABnUoiXYvMhNmW12OtiEIOfibLzH4DEVNxYOwX5+xP/v2X+KWpLdJub4wlYM89t /V3BL9RCaj22X6F9iQ9gTgE++OjCEmZs9P7XqOW9m+lKyLeWw2J72pXa4Eqri0t3vRSs VqeQ== X-Gm-Message-State: AOAM532YhpAOkh2WQ5uQbWucW8nJznL83UPLxVRiIlpLye8Rr0BH2GU9 IB69siefTF34voJLXMHMpscr7aa/jNnd3vycr3WxNUIbyceiDf40YFs6ygyn0jPICBNcgFIMnQk LDzsNW1Hc8/Pm/ItJnZw4y6ZqA37gmtXclt4MFRDNm9JvxgOVfU6+Z5SrvrWUM5H6HQ== X-Google-Smtp-Source: ABdhPJx6KE21Dsui6Bi8ycyH/++p4hhi9MYYMhj/sK3eubNYeGc7bJM0UaO6fYSrwLGaAYQNkNo7HAe5996G X-Received: from bohanli.mtv.corp.google.com ([2620:0:1000:2511:2dff:abe0:783e:348c]) (user=bohanli job=sendgmr) by 2002:ad4:5606:: with SMTP id ca6mr5415653qvb.1.1612396925398; Wed, 03 Feb 2021 16:02:05 -0800 (PST) Date: Wed, 3 Feb 2021 16:01:42 -0800 In-Reply-To: <20210204000142.4135063-1-bohanli@google.com> Message-Id: <20210204000142.4135063-2-bohanli@google.com> Mime-Version: 1.0 References: <20210204000142.4135063-1-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 | 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 }, };