[FFmpeg-cvslog] avcodec/libaomenc: add support for setting arbitrary libaom options

2021-02-10 Thread Bohan Li
ffmpeg | branch: master | Bohan Li  | Mon Feb  8 20:04:41 
2021 -0800| [82aab8a4eec33ee92c92c7679a4d7e6f03b109b4] | committer: Jan Ekström

avcodec/libaomenc: add support for setting arbitrary libaom options

A new key & value API lets us gain access to newly added parameters
without adding explicit support for them in our wrapper. Add an
option utilizing this functionality in a similar manner to other
encoder libraries' wrappers.

Signed-off-by: Bohan Li 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=82aab8a4eec33ee92c92c7679a4d7e6f03b109b4
---

 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 },
 };
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/libaomenc: Add unmet target level warning

2022-05-27 Thread Bohan Li
ffmpeg | branch: master | Bohan Li  | Tue Apr 
19 11:18:51 2022 -0700| [950123dc31470ccfd248e465e6b97ec48c640aa9] | committer: 
James Zern

avcodec/libaomenc: Add unmet target level warning

When target levels are set, this patch checks whether they are
satisfied by libaom. If not, a warning is shown. Otherwise the output
levels are also logged.

This patch applies basically the same approach used for libvpx.

Signed-off-by: Bohan Li 
Signed-off-by: James Zern 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=950123dc31470ccfd248e465e6b97ec48c640aa9
---

 libavcodec/libaomenc.c | 64 ++
 libavcodec/version.h   |  2 +-
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 0411773bbf..ca5a581b3e 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -199,6 +199,12 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] = "AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
 [AV1E_SET_ENABLE_REF_FRAME_MVS] = "AV1E_SET_ENABLE_REF_FRAME_MVS",
 #endif
+#ifdef AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX
+[AV1E_GET_SEQ_LEVEL_IDX]= "AV1E_GET_SEQ_LEVEL_IDX",
+#endif
+#ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
+[AV1E_GET_TARGET_SEQ_LEVEL_IDX] = "AV1E_GET_TARGET_SEQ_LEVEL_IDX",
+#endif
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -324,10 +330,68 @@ static av_cold int codecctl_int(AVCodecContext *avctx,
 return 0;
 }
 
+#if defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
+defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
+static av_cold int codecctl_intp(AVCodecContext *avctx,
+#ifdef UENUM1BYTE
+ aome_enc_control_id id,
+#else
+ enum aome_enc_control_id id,
+#endif
+ int* ptr)
+{
+AOMContext *ctx = avctx->priv_data;
+char buf[80];
+int width = -30;
+int res;
+
+snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
+av_log(avctx, AV_LOG_DEBUG, "  %*s%d\n", width, buf, *ptr);
+
+res = aom_codec_control(&ctx->encoder, id, ptr);
+if (res != AOM_CODEC_OK) {
+snprintf(buf, sizeof(buf), "Failed to set %s codec control",
+ ctlidstr[id]);
+log_encoder_error(avctx, buf);
+return AVERROR(EINVAL);
+}
+
+return 0;
+}
+#endif
+
 static av_cold int aom_free(AVCodecContext *avctx)
 {
 AOMContext *ctx = avctx->priv_data;
 
+#if defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
+defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
+if (!(avctx->flags & AV_CODEC_FLAG_PASS1)) {
+int levels[32] = { 0 };
+int target_levels[32] = { 0 };
+
+if (!codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) &&
+!codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX,
+   target_levels)) {
+for (int i = 0; i < 32; i++) {
+if (levels[i] > target_levels[i]) {
+// Warn when the target level was not met
+av_log(avctx, AV_LOG_WARNING,
+   "Could not encode to target level %d.%d for "
+   "operating point %d. The output level is %d.%d.\n",
+   2 + (target_levels[i] >> 2), target_levels[i] & 3,
+   i, 2 + (levels[i] >> 2), levels[i] & 3);
+} else if (target_levels[i] < 31) {
+// Log the encoded level if a target level was given
+av_log(avctx, AV_LOG_INFO,
+   "Output level for operating point %d is %d.%d.\n",
+   i, 2 + (levels[i] >> 2), levels[i] & 3);
+}
+}
+}
+}
+#endif
+
 aom_codec_destroy(&ctx->encoder);
 av_freep(&ctx->twopass_stats.buf);
 av_freep(&avctx->stats_out);
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 56dbb9238d..02192c86f7 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  32
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".