diff mbox series

[FFmpeg-devel,2/2] lavc/libaomenc: Support lossless encoding

Message ID 20200404093015.63848-2-ryo.hirafuji@gmail.com
State New
Headers show
Series Untitled series #758
Related show

Commit Message

Ryo Hirafuji April 4, 2020, 9:30 a.m. UTC
From: Ryo Hirafuji <ryo.hirafuji@link-u.co.jp>

AV1 support lossless encoding.
In this patch, I added a command line flag to enable it.

---
 libavcodec/libaomenc.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index fb61ce82e2..4a7f4b662a 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -94,6 +94,7 @@  typedef struct AOMEncoderContext {
     int enable_intrabc;
     int enable_restoration;
     int usage;
+    int lossless;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -130,6 +131,9 @@  static const char *const ctlidstr[] = {
 #endif
 #ifdef AOM_CTRL_AV1E_SET_ENABLE_INTRABC
     [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
+#endif
+#ifdef AOM_CTRL_AV1E_SET_LOSSLESS
+    [AV1E_SET_LOSSLESS]   = "AOM_CTRL_AV1E_SET_LOSSLESS",
 #endif
     [AV1E_SET_ENABLE_CDEF]      = "AV1E_SET_ENABLE_CDEF",
 };
@@ -154,7 +158,7 @@  static av_cold void dump_enc_cfg(AVCodecContext *avctx,
     av_log(avctx, level, "aom_codec_enc_cfg\n");
     av_log(avctx, level, "generic settings\n"
                          "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n"
-                         "  %*s%u\n  %*s%u\n"
+                         "  %*s%u\n  %*s%u\n  %*s%u\n"
                          "  %*s{%u/%u}\n  %*s%u\n  %*s%d\n  %*s%u\n",
            width, "g_usage:",           cfg->g_usage,
            width, "g_threads:",         cfg->g_threads,
@@ -163,6 +167,7 @@  static av_cold void dump_enc_cfg(AVCodecContext *avctx,
            width, "g_h:",               cfg->g_h,
            width, "g_bit_depth:",       cfg->g_bit_depth,
            width, "g_input_bit_depth:", cfg->g_input_bit_depth,
+           width, "monochrome:",        cfg->monochrome,
            width, "g_timebase:",        cfg->g_timebase.num, cfg->g_timebase.den,
            width, "g_error_resilient:", cfg->g_error_resilient,
            width, "g_pass:",            cfg->g_pass,
@@ -751,6 +756,10 @@  static av_cold int aom_init(AVCodecContext *avctx,
         codecctl_int(avctx, AV1E_SET_MAX_REFERENCE_FRAMES, avctx->refs);
     }
 #endif
+#ifdef AOM_CTRL_AV1E_SET_LOSSLESS
+    if (ctx->lossless >= 0)
+        codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);
+#endif
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
     if (ctx->row_mt >= 0)
         codecctl_int(avctx, AV1E_SET_ROW_MT, ctx->row_mt);
@@ -1132,6 +1141,7 @@  static const AVOption options[] = {
     { "usage",           "Quality and compression efficiency vs speed tradeof", OFFSET(usage), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "usage"},
     { "good",            "Good quality",      0, AV_OPT_TYPE_CONST, {.i64 = 0 /* AOM_USAGE_GOOD_QUALITY */}, 0, 0, VE, "usage"},
     { "realtime",        "Realtime encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 1 /* AOM_USAGE_REALTIME */},     0, 0, VE, "usage"},
+    { "lossless",        "Lossless encoding", OFFSET(lossless), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
     { NULL },
 };