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

Ryo Hirafuji ryo.hirafuji at gmail.com
Tue Apr 7 21:03:53 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.
---
 libavcodec/libaomenc.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index a3c5ae8f54..2133abb1a7 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",
 };
@@ -587,6 +590,8 @@ 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) {
+        enccfg.rc_end_usage = AOM_Q;
     } else if (ctx->crf >= 0) {
         enccfg.rc_end_usage = AOM_CQ;
         if (!avctx->bit_rate)
@@ -717,9 +722,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