Message ID | 20210209040441.462673-1-bohanli@google.com |
---|---|
State | Accepted |
Commit | 82aab8a4eec33ee92c92c7679a4d7e6f03b109b4 |
Headers | show |
Series | [FFmpeg-devel,v2] Add support for the new key & value API in libaom. | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
andriy/PPC64_make_fate | success | Make fate finished |
Thanks for the info! Just uploaded the patch v2 as suggested. Best, Bohan On Mon, Feb 8, 2021 at 8:04 PM Bohan Li <bohanli@google.com> wrote: > 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@google.com> > --- > doc/encoders.texi | 11 +++++++++++ > libavcodec/libaomenc.c | 18 ++++++++++++++++++ > 2 files changed, 29 insertions(+) > > diff --git a/doc/encoders.texi b/doc/encoders.texi > index c2ba7d3e6f..8fb573c416 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 aom-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{-aom-params}: > + > +@example > +ffmpeg -i input -c:v libaom-av1 -b:v 500K -aom-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..9a26b5f9ef 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 *aom_params; > } AOMContext; > > static const char *const ctlidstr[] = { > @@ -874,6 +875,20 @@ 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->aom_params, "", en, > AV_DICT_IGNORE_SUFFIX))) { > + int ret = aom_codec_set_option(&ctx->encoder, en->key, > en->value); > + if (ret != AOM_CODEC_OK) { > + log_encoder_error(avctx, en->key); > + return AVERROR_EXTERNAL; > + } > + } > + } > +#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 +1314,9 @@ 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}, > +#if AOM_ENCODER_ABI_VERSION >= 23 > + { "aom-params", "Set libaom options using a > :-separated list of key=value pairs", OFFSET(aom_params), AV_OPT_TYPE_DICT, > { 0 }, 0, 0, VE }, > +#endif > { NULL }, > }; > > -- > 2.30.0.478.g8a0d178c01-goog > >
On Tue, Feb 9, 2021 at 6:05 AM Bohan Li <bohanli-at-google.com@ffmpeg.org> wrote: > > This key & value API can greatly help with users who wants to try > libaom-av1 specific options that are not supported by ffmpeg options. > Looks good to me code-wise at this point. Thanks for noticing the small issues I had created due to not testing the modifications I did late in the night :) . I have tested this patch with both c1d42fe6615c96fc929257~1 (last revision without this feature) and current libaom master, and both compiled correctly. The error message from the library looks good enough (in my case omochi=unyoon led to an "unknown option" error), and the option is not available in the wrapper if the libaom version built against didn't have it. So two things I did: - Adjust the author to match the name & e-mail in the Signed-off-by (the mailing list changes the From field as it attempts to rewrite fields when sending the messages out, so if you just apply the patch from f.ex. Patchwork you get the wrong one). - Rewrote the commit message. https://github.com/jeeb/ffmpeg/commits/libaom_key_value_api_v2 Please tell if there are any issues with this from your side. If not, I think we can start pulling this in :) . Jan
Hi Jan, Yes the modified patch looks good to me. Please let me know if there is anything needed from my end. Thank you very much! Bohan On Tue, Feb 9, 2021, 12:01 PM Jan Ekström <jeebjp@gmail.com> wrote: > On Tue, Feb 9, 2021 at 6:05 AM Bohan Li > <bohanli-at-google.com@ffmpeg.org> wrote: > > > > This key & value API can greatly help with users who wants to try > > libaom-av1 specific options that are not supported by ffmpeg options. > > > > Looks good to me code-wise at this point. Thanks for noticing the > small issues I had created due to not testing the modifications I did > late in the night :) . > > I have tested this patch with both c1d42fe6615c96fc929257~1 (last > revision without this feature) and current libaom master, and both > compiled correctly. The error message from the library looks good > enough (in my case omochi=unyoon led to an "unknown option" error), > and the option is not available in the wrapper if the libaom version > built against didn't have it. > > So two things I did: > - Adjust the author to match the name & e-mail in the Signed-off-by > (the mailing list changes the From field as it attempts to rewrite > fields when sending the messages out, so if you just apply the patch > from f.ex. Patchwork you get the wrong one). > - Rewrote the commit message. > > https://github.com/jeeb/ffmpeg/commits/libaom_key_value_api_v2 > > Please tell if there are any issues with this from your side. If not, > I think we can start pulling this in :) . > > Jan > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
On Wed, Feb 10, 2021 at 9:16 AM Bohan Li <bohanli-at-google.com@ffmpeg.org> wrote: > > Hi Jan, > > Yes the modified patch looks good to me. > Please let me know if there is anything needed from my end. > > Thank you very much! > > Bohan > Cheers, pulled in as 82aab8a4eec33ee92c92c7679a4d7e6f03b109b4 . Jan
On Wed, Feb 10, 2021 at 9:16 AM Bohan Li <bohanli-at-google.com@ffmpeg.org> wrote: > > Hi Jan, > > Yes the modified patch looks good to me. > Please let me know if there is anything needed from my end. > > Thank you very much! > > Bohan > FYI, apparently the symbol is not exported in shared builds of libaom. I did test that versions before and after this feature got added to verify that the ABI number could be utilized as a build-time check, and that current release versions of libaom would still work, but unfortunately only in static configuration. Relevant libaom issue: https://bugs.chromium.org/p/aomedia/issues/detail?id=2962 Jan
diff --git a/doc/encoders.texi b/doc/encoders.texi index c2ba7d3e6f..8fb573c416 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 aom-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{-aom-params}: + +@example +ffmpeg -i input -c:v libaom-av1 -b:v 500K -aom-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..9a26b5f9ef 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 *aom_params; } AOMContext; static const char *const ctlidstr[] = { @@ -874,6 +875,20 @@ 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->aom_params, "", en, AV_DICT_IGNORE_SUFFIX))) { + int ret = aom_codec_set_option(&ctx->encoder, en->key, en->value); + if (ret != AOM_CODEC_OK) { + log_encoder_error(avctx, en->key); + return AVERROR_EXTERNAL; + } + } + } +#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 +1314,9 @@ 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}, +#if AOM_ENCODER_ABI_VERSION >= 23 + { "aom-params", "Set libaom options using a :-separated list of key=value pairs", OFFSET(aom_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE }, +#endif { NULL }, };
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@google.com> --- doc/encoders.texi | 11 +++++++++++ libavcodec/libaomenc.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+)