diff mbox series

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

Message ID 20200408001341.65204-2-ryo.hirafuji@gmail.com
State New
Headers show
Series [FFmpeg-devel,v4,1/2] libavcodec/libaomenc.c: Support gray input
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Ryo Hirafuji April 8, 2020, 12:13 a.m. UTC
From: Ryo Hirafuji <psi@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(-)

Comments

James Zern April 15, 2020, 12:59 a.m. UTC | #1
On Tue, Apr 7, 2020 at 5:14 PM Ryo Hirafuji <ryo.hirafuji@gmail.com> wrote:
>
> From: Ryo Hirafuji <psi@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(-)
>
> [...]
> @@ -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;

I saw the earlier comments around using crf=0 as the trigger for this.
libaom will behave differently with q vs cq mode. This also differs
from the -lossless in libvpxenc where this feature originated; mostly
we've been mapping options one to one with vpx/aomenc. Let me ask
around about the preference for lossless usage in libaom.
Ryo Hirafuji April 17, 2020, 4:50 p.m. UTC | #2
I see, Thanks.
I'm looking forward to the answer.

(If you are OK, please CC to me. I also would like to know about lossless
mode in libaom, because I also use my software)

2020年4月15日(水) 10:00 James Zern <jzern-at-google.com@ffmpeg.org>:

> On Tue, Apr 7, 2020 at 5:14 PM Ryo Hirafuji <ryo.hirafuji@gmail.com>
> wrote:
> >
> > From: Ryo Hirafuji <psi@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(-)
> >
> > [...]
> > @@ -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;
>
> I saw the earlier comments around using crf=0 as the trigger for this.
> libaom will behave differently with q vs cq mode. This also differs
> from the -lossless in libvpxenc where this feature originated; mostly
> we've been mapping options one to one with vpx/aomenc. Let me ask
> around about the preference for lossless usage in libaom.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
James Zern April 21, 2020, 9 p.m. UTC | #3
On Fri, Apr 17, 2020 at 9:57 AM Ryo Hirafuji <ryo.hirafuji@link-u.co.jp> wrote:
>
> I see, Thanks.
> I'm looking forward to the answer.
>

There is some benefit to using cq-level as many of the encoder
decisions are based on this (reference frame structure, speed
features, etc) and so it's better tuned than quality mode. In both
cases the output is lossless so either will work, but given the
structure of the options to the library it might make sense to match
vp9 in libvpxenc.c and use cq-level.

> (If you are OK, please CC to me. I also would like to know about lossless
> mode in libaom, because I also use my software)
>

Sorry, I missed this comment. I don't have any results that would be
visible publicly.

> 2020年4月15日(水) 10:00 James Zern <jzern-at-google.com@ffmpeg.org>:
>
> > On Tue, Apr 7, 2020 at 5:14 PM Ryo Hirafuji <ryo.hirafuji@gmail.com>
> > wrote:
> > >
> > > From: Ryo Hirafuji <psi@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(-)
> > >
> > > [...]
> > > @@ -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;
> >
> > I saw the earlier comments around using crf=0 as the trigger for this.
> > libaom will behave differently with q vs cq mode. This also differs
> > from the -lossless in libvpxenc where this feature originated; mostly
> > we've been mapping options one to one with vpx/aomenc. Let me ask
> > around about the preference for lossless usage in libaom.
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Kieran O Leary June 6, 2020, 7:25 p.m. UTC | #4
Hi all - just wondering about the status of this. I was doing some tests
with just -crf 0 with mixed results before I saw this thread.
http://ffmpeg.org/pipermail/ffmpeg-user/2020-June/048885.html

K
diff mbox series

Patch

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);