[FFmpeg-devel] [PATCH v4 2/2] libavcodec/libaomenc.c: Support lossless encoding

Ryo Hirafuji ryo.hirafuji at gmail.com
Wed Apr 8 03:13:41 EEST 2020


From: Ryo Hirafuji <psi at 7io.org>

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

Fixes ticket #7600
---
 libavcodec/libaomenc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index ff79c0af9f..cc50ffc11b 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -130,6 +130,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",
 };
@@ -574,7 +577,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
     if (avctx->rc_min_rate == avctx->rc_max_rate &&
         avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) {
         enccfg.rc_end_usage = AOM_CBR;
-    } else if (ctx->crf >= 0) {
+    } else if (ctx->crf == 0) {
+        enccfg.rc_end_usage = AOM_Q;
+    } else if (ctx->crf > 0) {
         enccfg.rc_end_usage = AOM_CQ;
         if (!avctx->bit_rate)
             enccfg.rc_end_usage = AOM_Q;
@@ -704,9 +709,12 @@ static av_cold int aom_init(AVCodecContext *avctx,
         codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION, ctx->enable_restoration);
 
     codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
-    if (ctx->crf >= 0)
+    if (ctx->crf >= 0) {
         codecctl_int(avctx, AOME_SET_CQ_LEVEL,          ctx->crf);
-
+#ifdef AOM_CTRL_AV1E_SET_LOSSLESS
+        codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->crf == 0);
+#endif
+    }
     codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
     codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
     codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, avctx->color_trc);
-- 
2.20.1



More information about the ffmpeg-devel mailing list