diff mbox series

[FFmpeg-devel] avcodec/libaomenc: Add parameter for avif single image encoding

Message ID 20220217211838.3404301-1-vigneshv@google.com
State New
Headers show
Series [FFmpeg-devel] avcodec/libaomenc: Add parameter for avif single image encoding | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
yinshiyou/configure_loongarch64 warning Failed to run configure
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished

Commit Message

Vignesh Venkat Feb. 17, 2022, 9:18 p.m. UTC
Add a parameter to libaom-av1 encoder to enforce some of the single
image constraints in the AV1 encoder. Setting this flag will limit
the encoder to producing exactly one frame and the sequence header
that is produced by the encoder will be conformant to the AVIF
specification [1].

Part of Fixing Trac ticket #7621

[1] https://aomediacodec.github.io/av1-avif

Signed-off-by:: Vignesh Venkatasubramanian <vigneshv@google.com>
---
 libavcodec/libaomenc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 963cc1bcbc..638c1deca6 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -99,6 +99,7 @@  typedef struct AOMEncoderContext {
     int enable_restoration;
     int usage;
     int tune;
+    int still_picture;
     int enable_rect_partitions;
     int enable_1to4_partitions;
     int enable_ab_partitions;
@@ -746,6 +747,18 @@  static av_cold int aom_init(AVCodecContext *avctx,
     if (res < 0)
         return res;
 
+    if (ctx->still_picture) {
+        // Set the maximum number of frames to 1. This will let libaom set
+        // still_picture and reduced_still_picture_header to 1 in the Sequence
+        // Header as required by AVIF still images.
+        enccfg.g_limit = 1;
+        // Reduce memory usage for still images.
+        enccfg.g_lag_in_frames = 0;
+        // All frames will be key frames.
+        enccfg.kf_max_dist = 0;
+        enccfg.kf_mode = AOM_KF_DISABLED;
+    }
+
     /* Construct Encoder Context */
     res = aom_codec_enc_init(&ctx->encoder, iface, &enccfg, flags);
     if (res != AOM_CODEC_OK) {
@@ -1290,6 +1303,7 @@  static const AVOption options[] = {
     { "psnr",            NULL,         0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
     { "ssim",            NULL,         0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
     FF_AV1_PROFILE_OPTS
+    { "still-picture", "Encode in single frame mode (typically used for still AVIF images).", OFFSET(still_picture), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },
     { "enable-rect-partitions", "Enable rectangular partitions", OFFSET(enable_rect_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
     { "enable-1to4-partitions", "Enable 1:4/4:1 partitions",     OFFSET(enable_1to4_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
     { "enable-ab-partitions",   "Enable ab shape partitions",    OFFSET(enable_ab_partitions),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},