diff mbox series

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

Message ID 20200404095643.128435-2-ryo.hirafuji@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,1/2] libavcodec/libaomenc.c: Support gray input | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Ryo Hirafuji April 4, 2020, 9:56 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(-)

Comments

Carl Eugen Hoyos April 4, 2020, 9:58 a.m. UTC | #1
Am Sa., 4. Apr. 2020 um 11:57 Uhr schrieb Ryo Hirafuji <ryo.hirafuji@gmail.com>:
>
> 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 --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},

Is it possible to use "cfr 0" instead?

Carl Eugen
Ryo Hirafuji April 4, 2020, 10:09 a.m. UTC | #2
> Is it possible to use "cfr 0" instead?

Unfortunately, crf=0 is not lossless.
"lossless" flag uses "quantisation matrices", which is different from the
default quantizer determined by "-crf", to achieve lossless encoding.


2020年4月4日(土) 18:59 Carl Eugen Hoyos <ceffmpeg@gmail.com>:

> Am Sa., 4. Apr. 2020 um 11:57 Uhr schrieb Ryo Hirafuji <
> ryo.hirafuji@gmail.com>:
> >
> > 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 --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},
>
> Is it possible to use "cfr 0" instead?
>
> Carl Eugen
> _______________________________________________
> 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".
Carl Eugen Hoyos April 4, 2020, 10:28 a.m. UTC | #3
Am Sa., 4. Apr. 2020 um 12:16 Uhr schrieb Ryo Hirafuji
<ryo.hirafuji@link-u.co.jp>:
>
> > Is it possible to use "cfr 0" instead?
>
> Unfortunately, crf=0 is not lossless.
> "lossless" flag uses "quantisation matrices", which is different from the
> default quantizer determined by "-crf", to achieve lossless encoding.

So "crf 0" already has a meaning different from all other crf values?

Thank you, Carl Eugen
Ryo Hirafuji April 4, 2020, 11:16 a.m. UTC | #4
> So "crf 0" already has a meaning different from all other crf values?

No. "crf 0" has the same meanings. It just makes the quality better than
"crf 1".

I read libaom again, and I apologize for my wrong explanation:
  I found that if certain conditions are met, "crf 0" also generates
lossless videos.

If these conditions are not met, "-crf 0" will be lossless:

<<FFmpeg options>>
  "-bit_rate 0" (which means, enccfg.rc_end_usage = AOM_Q)
  "-aq-mode none"
  "-enable_restoration 0"

<<the libaom settings which can't be configured from FFmpeg yet>>
  AV1E_SET_ENABLE_CHROMA_DELTAQ must be 0
  AV1E_SET_ENABLE_SUPERRES must be 0

Thus, at least, "-lossless" does have a different meaning from "-crf 0",
so I think it would be useful to add "-lossless" flags.


2020年4月4日(土) 19:29 Carl Eugen Hoyos <ceffmpeg@gmail.com>:

> Am Sa., 4. Apr. 2020 um 12:16 Uhr schrieb Ryo Hirafuji
> <ryo.hirafuji@link-u.co.jp>:
> >
> > > Is it possible to use "cfr 0" instead?
> >
> > Unfortunately, crf=0 is not lossless.
> > "lossless" flag uses "quantisation matrices", which is different from the
> > default quantizer determined by "-crf", to achieve lossless encoding.
>
> So "crf 0" already has a meaning different from all other crf values?
>
> Thank you, Carl Eugen
> _______________________________________________
> 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".
Carl Eugen Hoyos April 4, 2020, 3:34 p.m. UTC | #5
Am Sa., 4. Apr. 2020 um 13:17 Uhr schrieb Ryo Hirafuji
<ryo.hirafuji@link-u.co.jp>:
>
> > So "crf 0" already has a meaning different from all other crf values?
>
> No. "crf 0" has the same meanings. It just makes the quality better than
> "crf 1".

That was my question, sorry for being unclear.

> I read libaom again, and I apologize for my wrong explanation:
> I found that if certain conditions are met, "crf 0" also generates
> lossless videos.
>
> If these conditions are not met, "-crf 0" will be lossless:
>
> <<FFmpeg options>>
>   "-bit_rate 0" (which means, enccfg.rc_end_usage = AOM_Q)
>   "-aq-mode none"
>   "-enable_restoration 0"
>
> <<the libaom settings which can't be configured from FFmpeg yet>>
>   AV1E_SET_ENABLE_CHROMA_DELTAQ must be 0
>   AV1E_SET_ENABLE_SUPERRES must be 0
>
> Thus, at least, "-lossless" does have a different meaning from "-crf 0",
> so I think it would be useful to add "-lossless" flags.

In an ideal world, crf 0 would force all other settings for a lossless
encoding.

Carl Eugen
Ryo Hirafuji April 4, 2020, 4:46 p.m. UTC | #6
> In an ideal world, crf 0 would force all other settings for a lossless
encoding.

I forgot to say that if "-lossless 1" is set, "crf" will also be 0 (in
libaom, internally).

All those conditions will be forced (ot at least checked by libaom) if we
execute this line:

> codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);

So, how about executing this line if the "-crf 0" is set?
libaom changes so fast, so this might be a more robust way to ensure
lossless encoding, rather than setting those settings by hand.

If it's okay, I will make an additional patch.

2020年4月5日(日) 0:34 Carl Eugen Hoyos <ceffmpeg@gmail.com>:

> Am Sa., 4. Apr. 2020 um 13:17 Uhr schrieb Ryo Hirafuji
> <ryo.hirafuji@link-u.co.jp>:
> >
> > > So "crf 0" already has a meaning different from all other crf values?
> >
> > No. "crf 0" has the same meanings. It just makes the quality better than
> > "crf 1".
>
> That was my question, sorry for being unclear.
>
> > I read libaom again, and I apologize for my wrong explanation:
> > I found that if certain conditions are met, "crf 0" also generates
> > lossless videos.
> >
> > If these conditions are not met, "-crf 0" will be lossless:
> >
> > <<FFmpeg options>>
> >   "-bit_rate 0" (which means, enccfg.rc_end_usage = AOM_Q)
> >   "-aq-mode none"
> >   "-enable_restoration 0"
> >
> > <<the libaom settings which can't be configured from FFmpeg yet>>
> >   AV1E_SET_ENABLE_CHROMA_DELTAQ must be 0
> >   AV1E_SET_ENABLE_SUPERRES must be 0
> >
> > Thus, at least, "-lossless" does have a different meaning from "-crf 0",
> > so I think it would be useful to add "-lossless" flags.
>
> In an ideal world, crf 0 would force all other settings for a lossless
> encoding.
>
> Carl Eugen
> _______________________________________________
> 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".
Carl Eugen Hoyos April 5, 2020, 9:05 a.m. UTC | #7
Am Sa., 4. Apr. 2020 um 18:46 Uhr schrieb Ryo Hirafuji
<ryo.hirafuji@link-u.co.jp>:
>
> > In an ideal world, crf 0 would force all other settings for a lossless
> > encoding.
>
> I forgot to say that if "-lossless 1" is set, "crf" will also be 0 (in
> libaom, internally).
>
> All those conditions will be forced (ot at least checked by libaom) if we
> execute this line:
>
> > codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);
>
> So, how about executing this line if the "-crf 0" is set?

I would prefer this but I am not the maintainer.

See also:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/CAB0OVGr6o6yR3bVAgJix7R7mZCRRVruw=jqA7wGJb+hQ2BvZUQ@mail.gmail.com/

Carl Eugen
Ryo Hirafuji April 5, 2020, 10:39 a.m. UTC | #8
> I would prefer this but I am not the maintainer.

Oh, I see.

Hi, Rostislav Pehlivanov, please tell me your idea.
(How can I address him/her in ML...?)

I think it is more useful to execute this line when "-crf 0" is set:

> codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);

It could let users force lossless video more easily and robustly, because
libaom prepared such an option.

It is true the following settings will enable lossless encoding, but these
conditions may change with libaom change:

> If these conditions are not met, "-crf 0" will be lossless:
>
> <<FFmpeg options>>
>   "-bit_rate 0" (which means, enccfg.rc_end_usage = AOM_Q)
>   "-aq-mode none"
>   "-enable_restoration 0"
>
> <<the libaom settings which can't be configured from FFmpeg yet>>
>   AV1E_SET_ENABLE_CHROMA_DELTAQ must be 0
>   AV1E_SET_ENABLE_SUPERRES must be 0


2020年4月5日(日) 18:06 Carl Eugen Hoyos <ceffmpeg@gmail.com>:

> Am Sa., 4. Apr. 2020 um 18:46 Uhr schrieb Ryo Hirafuji
> <ryo.hirafuji@link-u.co.jp>:
> >
> > > In an ideal world, crf 0 would force all other settings for a lossless
> > > encoding.
> >
> > I forgot to say that if "-lossless 1" is set, "crf" will also be 0 (in
> > libaom, internally).
> >
> > All those conditions will be forced (ot at least checked by libaom) if we
> > execute this line:
> >
> > > codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);
> >
> > So, how about executing this line if the "-crf 0" is set?
>
> I would prefer this but I am not the maintainer.
>
> See also:
>
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/CAB0OVGr6o6yR3bVAgJix7R7mZCRRVruw=jqA7wGJb+hQ2BvZUQ@mail.gmail.com/
>
> Carl Eugen
> _______________________________________________
> 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".
Ryo Hirafuji April 5, 2020, 10:57 a.m. UTC | #9
Lynne, could you tell me your idea?

2020年4月5日(日) 19:39 Ryo Hirafuji <ryo.hirafuji@link-u.co.jp>:

> > I would prefer this but I am not the maintainer.
>
> Oh, I see.
>
> Hi, Rostislav Pehlivanov, please tell me your idea.
> (How can I address him/her in ML...?)
>
> I think it is more useful to execute this line when "-crf 0" is set:
>
> > codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);
>
> It could let users force lossless video more easily and robustly, because
> libaom prepared such an option.
>
> It is true the following settings will enable lossless encoding, but these
> conditions may change with libaom change:
>
> > If these conditions are not met, "-crf 0" will be lossless:
> >
> > <<FFmpeg options>>
> >   "-bit_rate 0" (which means, enccfg.rc_end_usage = AOM_Q)
> >   "-aq-mode none"
> >   "-enable_restoration 0"
> >
> > <<the libaom settings which can't be configured from FFmpeg yet>>
> >   AV1E_SET_ENABLE_CHROMA_DELTAQ must be 0
> >   AV1E_SET_ENABLE_SUPERRES must be 0
>
>
> 2020年4月5日(日) 18:06 Carl Eugen Hoyos <ceffmpeg@gmail.com>:
>
>> Am Sa., 4. Apr. 2020 um 18:46 Uhr schrieb Ryo Hirafuji
>> <ryo.hirafuji@link-u.co.jp>:
>> >
>> > > In an ideal world, crf 0 would force all other settings for a lossless
>> > > encoding.
>> >
>> > I forgot to say that if "-lossless 1" is set, "crf" will also be 0 (in
>> > libaom, internally).
>> >
>> > All those conditions will be forced (ot at least checked by libaom) if
>> we
>> > execute this line:
>> >
>> > > codecctl_int(avctx, AV1E_SET_LOSSLESS, ctx->lossless);
>> >
>> > So, how about executing this line if the "-crf 0" is set?
>>
>> I would prefer this but I am not the maintainer.
>>
>> See also:
>>
>> https://patchwork.ffmpeg.org/project/ffmpeg/patch/CAB0OVGr6o6yR3bVAgJix7R7mZCRRVruw=jqA7wGJb+hQ2BvZUQ@mail.gmail.com/
>>
>> Carl Eugen
>> _______________________________________________
>> 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".
>
>
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 },
 };