Opened 6 days ago

Last modified 2 days ago

#7600 new enhancement

Add lossless option to libaom-av1

Reported by: Ewout Owned by:
Priority: wish Component: avcodec
Version: git-master Keywords: libaom
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

libaom supports lossless encoding, an option could be added to the CLI to enable this mode.

in libvpx-vp9:
-lossless <int> E..V..... Lossless mode (from -1 to 1) (default -1)

in aomenc:
--lossless=<arg> Lossless mode (0: false (default), 1: true)

Change History (3)

comment:1 Changed 2 days ago by cehoyos

  • Component changed from undetermined to avcodec
  • Priority changed from normal to wish
  • Version changed from unspecified to git-master

Please test this patch:

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 09ef423..2b44bda 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -79,6 +79,7 @@ typedef struct AOMEncoderContext {
     aom_superblock_size_t superblock_size;
     int uniform_tiles;
     int row_mt;
+    int lossless;
 } AOMContext;

 static const char *const ctlidstr[] = {
@@ -96,6 +97,9 @@ static const char *const ctlidstr[] = {
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
     [AV1E_SET_ROW_MT]           = "AV1E_SET_ROW_MT",
 #endif
+#ifdef AOM_CTRL_AV1E_SET_LOSSLESS
+    [AV1E_SET_LOSSLESS]         = "AV1E_SET_LOSSLESS",
+#endif
 };

 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -657,6 +661,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
     codecctl_int(avctx, AV1E_SET_ROW_MT, ctx->row_mt);
 #endif
+#ifdef AOM_CTRL_AV1E_SET_LOSSLESS
+    codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);
+#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,
@@ -992,6 +999,7 @@ static const AVOption options[] = {
     { "tile-columns",     "Log2 of number of tile columns to use", OFFSET(tile_cols_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
     { "tile-rows",        "Log2 of number of tile rows to use",    OFFSET(tile_rows_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
     { "row-mt",           "Enable row based multi-threading",      OFFSET(row_mt),         AV_OPT_TYPE_BOOL, {.i64 = 0},  0, 1, VE},
+    { "lossless",         "Lossless mode",                         OFFSET(lossless),       AV_OPT_TYPE_BOOL, {.i64 = 0},  0, 1, VE}
     { NULL }
 };

comment:2 Changed 2 days ago by jamrial

AOM_CTRL_AV1E_SET_LOSSLESS exists in libaom 1.0.0, so no need for preprocessor guards.

comment:3 Changed 2 days ago by cehoyos

Like this?

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 09ef423..9ec5c19 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -79,6 +79,7 @@ typedef struct AOMEncoderContext {
     aom_superblock_size_t superblock_size;
     int uniform_tiles;
     int row_mt;
+    int lossless;
 } AOMContext;

 static const char *const ctlidstr[] = {
@@ -96,6 +97,7 @@ static const char *const ctlidstr[] = {
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
     [AV1E_SET_ROW_MT]           = "AV1E_SET_ROW_MT",
 #endif
+    [AV1E_SET_LOSSLESS]         = "AV1E_SET_LOSSLESS",
 };

 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -657,6 +659,7 @@ static av_cold int aom_init(AVCodecContext *avctx,
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
     codecctl_int(avctx, AV1E_SET_ROW_MT, ctx->row_mt);
 #endif
+    codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);

     // provide dummy value to initialize wrapper, values will be updated each _encode()
     aom_img_wrap(&ctx->rawimg, img_fmt, avctx->width, avctx->height, 1,
@@ -992,6 +995,7 @@ static const AVOption options[] = {
     { "tile-columns",     "Log2 of number of tile columns to use", OFFSET(tile_cols_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
     { "tile-rows",        "Log2 of number of tile rows to use",    OFFSET(tile_rows_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
     { "row-mt",           "Enable row based multi-threading",      OFFSET(row_mt),         AV_OPT_TYPE_BOOL, {.i64 = 0},  0, 1, VE},
+    { "lossless",         "Lossless mode",                         OFFSET(lossless),       AV_OPT_TYPE_BOOL, {.i64 = 0},  0, 1, VE}
     { NULL }
 };


Note: See TracTickets for help on using tickets.