[FFmpeg-devel] [PATCH 1/2] libavcodec/libaomenc.c: Support gray input

2020-04-04 Thread Ryo Hirafuji
AV1 decoders, libaomdec and libdav1d, both support grayscale image.
However, libaomenc does not support it yet.
In this patch, I add a grayscale image support also to libaomenc.

---
 libavcodec/libaomenc.c | 48 --
 1 file changed, 42 insertions(+), 6 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..fb61ce82e2 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -276,6 +276,25 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
 AOMContext av_unused *ctx = avctx->priv_data;
 enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
 switch (avctx->pix_fmt) {
+case AV_PIX_FMT_GRAY8:
+enccfg->monochrome = 1u;
+enccfg->g_profile = FF_PROFILE_AV1_MAIN;
+*img_fmt = AOM_IMG_FMT_I420;
+return 0;
+case AV_PIX_FMT_GRAY10:
+case AV_PIX_FMT_GRAY12:
+if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
+enccfg->monochrome = 1u;
+enccfg->g_profile = 
+avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? FF_PROFILE_AV1_MAIN
+: 
FF_PROFILE_AV1_PROFESSIONAL;
+enccfg->g_bit_depth = enccfg->g_input_bit_depth =
+avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? 10 : 12;
+*img_fmt = AOM_IMG_FMT_I420;
+*flags |= AOM_CODEC_USE_HIGHBITDEPTH;
+return 0;
+}
+break;
 case AV_PIX_FMT_YUV420P:
 enccfg->g_profile = FF_PROFILE_AV1_MAIN;
 *img_fmt = AOM_IMG_FMT_I420;
@@ -979,12 +998,25 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 
 if (frame) {
 rawimg  = &ctx->rawimg;
-rawimg->planes[AOM_PLANE_Y] = frame->data[0];
-rawimg->planes[AOM_PLANE_U] = frame->data[1];
-rawimg->planes[AOM_PLANE_V] = frame->data[2];
-rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
-rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
-rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
+if (frame->format == AV_PIX_FMT_GRAY8 ||
+frame->format == AV_PIX_FMT_GRAY10 ||
+frame->format == AV_PIX_FMT_GRAY12) {
+rawimg->monochrome = 1;
+rawimg->planes[AOM_PLANE_Y] = frame->data[0];
+rawimg->planes[AOM_PLANE_U] = frame->data[0];
+rawimg->planes[AOM_PLANE_V] = frame->data[0];
+rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[0];
+} else {
+rawimg->monochrome = 0;
+rawimg->planes[AOM_PLANE_Y] = frame->data[0];
+rawimg->planes[AOM_PLANE_U] = frame->data[1];
+rawimg->planes[AOM_PLANE_V] = frame->data[2];
+rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
+}
 timestamp   = frame->pts;
 switch (frame->color_range) {
 case AVCOL_RANGE_MPEG:
@@ -1025,6 +1057,7 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 }
 
 static const enum AVPixelFormat av1_pix_fmts[] = {
+AV_PIX_FMT_GRAY8,
 AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_YUV422P,
 AV_PIX_FMT_YUV444P,
@@ -1032,6 +1065,9 @@ static const enum AVPixelFormat av1_pix_fmts[] = {
 };
 
 static const enum AVPixelFormat av1_pix_fmts_highbd[] = {
+AV_PIX_FMT_GRAY8,
+AV_PIX_FMT_GRAY10,
+AV_PIX_FMT_GRAY12,
 AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_YUV422P,
 AV_PIX_FMT_YUV444P,
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-04 Thread Ryo Hirafuji
From: Ryo Hirafuji 

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},
 { NULL },
 };
 
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-04 Thread Ryo Hirafuji
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},
 { NULL },
 };
 
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-04 Thread Ryo Hirafuji
From: Ryo Hirafuji 

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},
 { NULL },
 };
 
-- 
2.20.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-04 Thread Ryo Hirafuji
> 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 :

> Am Sa., 4. Apr. 2020 um 11:57 Uhr schrieb Ryo Hirafuji <
> ryo.hiraf...@gmail.com>:
> >
> > From: Ryo Hirafuji 
> >
> > 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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-04 Thread Ryo Hirafuji
> 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:

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

<>
  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 :

> Am Sa., 4. Apr. 2020 um 12:16 Uhr schrieb Ryo Hirafuji
> :
> >
> > > 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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-04 Thread Ryo Hirafuji
> 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 :

> Am Sa., 4. Apr. 2020 um 13:17 Uhr schrieb Ryo Hirafuji
> :
> >
> > > 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:
> >
> > <>
> >   "-bit_rate 0" (which means, enccfg.rc_end_usage = AOM_Q)
> >   "-aq-mode none"
> >   "-enable_restoration 0"
> >
> > <>
> >   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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-05 Thread Ryo Hirafuji
> 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:
>
> <>
>   "-bit_rate 0" (which means, enccfg.rc_end_usage = AOM_Q)
>   "-aq-mode none"
>   "-enable_restoration 0"
>
> <>
>   AV1E_SET_ENABLE_CHROMA_DELTAQ must be 0
>   AV1E_SET_ENABLE_SUPERRES must be 0


2020年4月5日(日) 18:06 Carl Eugen Hoyos :

> Am Sa., 4. Apr. 2020 um 18:46 Uhr schrieb Ryo Hirafuji
> :
> >
> > > 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+hq2bv...@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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-05 Thread Ryo Hirafuji
Hi, Moritz.

Yeah, you are right! And sorry.

After the discussion, I will move this change from "lossless patch" to
"gray patch".

Thanks.

2020年4月5日(日) 19:28 Moritz Barsnick :

> On Sat, Apr 04, 2020 at 18:53:41 +0900, Ryo Hirafuji wrote:
> > AV1 support lossless encoding.
> > In this patch, I added a command line flag to enable it.
>
> > @@ -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,
>
> Shouldn't this be part of the gray patch?
>
> Moritz
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-05 Thread Ryo Hirafuji
OK, I will.
Thanks!

2020年4月5日(日) 19:45 Carl Eugen Hoyos :

> Am So., 5. Apr. 2020 um 12:42 Uhr schrieb Ryo Hirafuji
> :
> >
> > Hi, Moritz.
> >
> > Yeah, you are right! And sorry.
> >
> > After the discussion, I will move this change from "lossless patch" to
> > "gray patch".
>
> And please mention "Fixes ticket #7599" for the gray patch,
> "Fixes ticket #7600" for the lossless patch.
>
> 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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-05 Thread Ryo Hirafuji
Lynne, could you tell me your idea?

2020年4月5日(日) 19:39 Ryo Hirafuji :

> > 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:
> >
> > <>
> >   "-bit_rate 0" (which means, enccfg.rc_end_usage = AOM_Q)
> >   "-aq-mode none"
> >   "-enable_restoration 0"
> >
> > <>
> >   AV1E_SET_ENABLE_CHROMA_DELTAQ must be 0
> >   AV1E_SET_ENABLE_SUPERRES must be 0
>
>
> 2020年4月5日(日) 18:06 Carl Eugen Hoyos :
>
>> Am Sa., 4. Apr. 2020 um 18:46 Uhr schrieb Ryo Hirafuji
>> :
>> >
>> > > 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+hq2bv...@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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2 1/2] libavcodec/libaomenc.c: Support gray input

2020-04-07 Thread Ryo Hirafuji
From: Ryo Hirafuji 

AV1 decoders, libaomdec and libdav1d, both support grayscale image.
However, libaomenc does not support it yet.
In this patch, I add a grayscale image support also to libaomenc.
---
 libavcodec/libaomenc.c | 51 --
 1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..a3c5ae8f54 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -154,7 +154,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 +163,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,
@@ -276,6 +277,25 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
 AOMContext av_unused *ctx = avctx->priv_data;
 enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
 switch (avctx->pix_fmt) {
+case AV_PIX_FMT_GRAY8:
+enccfg->monochrome = 1u;
+enccfg->g_profile = FF_PROFILE_AV1_MAIN;
+*img_fmt = AOM_IMG_FMT_I420;
+return 0;
+case AV_PIX_FMT_GRAY10:
+case AV_PIX_FMT_GRAY12:
+if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
+enccfg->monochrome = 1u;
+enccfg->g_profile =
+avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? FF_PROFILE_AV1_MAIN
+: 
FF_PROFILE_AV1_PROFESSIONAL;
+enccfg->g_bit_depth = enccfg->g_input_bit_depth =
+avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? 10 : 12;
+*img_fmt = AOM_IMG_FMT_I42016;
+*flags |= AOM_CODEC_USE_HIGHBITDEPTH;
+return 0;
+}
+break;
 case AV_PIX_FMT_YUV420P:
 enccfg->g_profile = FF_PROFILE_AV1_MAIN;
 *img_fmt = AOM_IMG_FMT_I420;
@@ -979,12 +999,25 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 
 if (frame) {
 rawimg  = &ctx->rawimg;
-rawimg->planes[AOM_PLANE_Y] = frame->data[0];
-rawimg->planes[AOM_PLANE_U] = frame->data[1];
-rawimg->planes[AOM_PLANE_V] = frame->data[2];
-rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
-rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
-rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
+if (frame->format == AV_PIX_FMT_GRAY8 ||
+frame->format == AV_PIX_FMT_GRAY10 ||
+frame->format == AV_PIX_FMT_GRAY12) {
+rawimg->monochrome = 1;
+rawimg->planes[AOM_PLANE_Y] = frame->data[0];
+rawimg->planes[AOM_PLANE_U] = frame->data[0];
+rawimg->planes[AOM_PLANE_V] = frame->data[0];
+rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[0];
+} else {
+rawimg->monochrome = 0;
+rawimg->planes[AOM_PLANE_Y] = frame->data[0];
+rawimg->planes[AOM_PLANE_U] = frame->data[1];
+rawimg->planes[AOM_PLANE_V] = frame->data[2];
+rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
+}
 timestamp   = frame->pts;
 switch (frame->color_range) {
 case AVCOL_RANGE_MPEG:
@@ -1025,6 +1058,7 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 }
 
 static const enum AVPixelFormat av1_pix_fmts[] = {
+AV_PIX_FMT_GRAY8,
 AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_YUV422P,
 AV_PIX_FMT_YUV444P,
@@ -1032,6 +1066,9 @@ static const enum AVPixelFormat av1_pix_fmts[] = {
 };
 
 static const enum AVPixelFormat av1_pix_fmts_hi

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

2020-04-07 Thread Ryo Hirafuji
From: Ryo Hirafuji 

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

Fixes ticket #7600
---
 libavcodec/libaomenc.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index a3c5ae8f54..0cc5afdb7a 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

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v3 1/2] libavcodec/libaomenc.c: Support gray input

2020-04-07 Thread Ryo Hirafuji
From: Ryo Hirafuji 

AV1 decoders, libaomdec and libdav1d, both support grayscale image.
However, libaomenc does not support it yet.
In this patch, I add a grayscale image support also to libaomenc.

Fixes ticket #7599
---
 libavcodec/libaomenc.c | 51 --
 1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..a3c5ae8f54 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -154,7 +154,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 +163,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,
@@ -276,6 +277,25 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
 AOMContext av_unused *ctx = avctx->priv_data;
 enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
 switch (avctx->pix_fmt) {
+case AV_PIX_FMT_GRAY8:
+enccfg->monochrome = 1u;
+enccfg->g_profile = FF_PROFILE_AV1_MAIN;
+*img_fmt = AOM_IMG_FMT_I420;
+return 0;
+case AV_PIX_FMT_GRAY10:
+case AV_PIX_FMT_GRAY12:
+if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
+enccfg->monochrome = 1u;
+enccfg->g_profile =
+avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? FF_PROFILE_AV1_MAIN
+: 
FF_PROFILE_AV1_PROFESSIONAL;
+enccfg->g_bit_depth = enccfg->g_input_bit_depth =
+avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? 10 : 12;
+*img_fmt = AOM_IMG_FMT_I42016;
+*flags |= AOM_CODEC_USE_HIGHBITDEPTH;
+return 0;
+}
+break;
 case AV_PIX_FMT_YUV420P:
 enccfg->g_profile = FF_PROFILE_AV1_MAIN;
 *img_fmt = AOM_IMG_FMT_I420;
@@ -979,12 +999,25 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 
 if (frame) {
 rawimg  = &ctx->rawimg;
-rawimg->planes[AOM_PLANE_Y] = frame->data[0];
-rawimg->planes[AOM_PLANE_U] = frame->data[1];
-rawimg->planes[AOM_PLANE_V] = frame->data[2];
-rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
-rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
-rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
+if (frame->format == AV_PIX_FMT_GRAY8 ||
+frame->format == AV_PIX_FMT_GRAY10 ||
+frame->format == AV_PIX_FMT_GRAY12) {
+rawimg->monochrome = 1;
+rawimg->planes[AOM_PLANE_Y] = frame->data[0];
+rawimg->planes[AOM_PLANE_U] = frame->data[0];
+rawimg->planes[AOM_PLANE_V] = frame->data[0];
+rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[0];
+} else {
+rawimg->monochrome = 0;
+rawimg->planes[AOM_PLANE_Y] = frame->data[0];
+rawimg->planes[AOM_PLANE_U] = frame->data[1];
+rawimg->planes[AOM_PLANE_V] = frame->data[2];
+rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
+}
 timestamp   = frame->pts;
 switch (frame->color_range) {
 case AVCOL_RANGE_MPEG:
@@ -1025,6 +1058,7 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 }
 
 static const enum AVPixelFormat av1_pix_fmts[] = {
+AV_PIX_FMT_GRAY8,
 AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_YUV422P,
 AV_PIX_FMT_YUV444P,
@@ -1032,6 +1066,9 @@ static const enum AVPixelFormat av1_pix_fmts[] = {
 };
 
 static const enum AVPixelF

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

2020-04-07 Thread Ryo Hirafuji
From: Ryo Hirafuji 

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

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v2 1/2] libavcodec/libaomenc.c: Support gray input

2020-04-07 Thread Ryo Hirafuji
Sorry, I forgot to add "Fixes ticket ..."

I will send again as v3.

2020年4月8日(水) 3:04 Ryo Hirafuji :

> From: Ryo Hirafuji 
>
> AV1 decoders, libaomdec and libdav1d, both support grayscale image.
> However, libaomenc does not support it yet.
> In this patch, I add a grayscale image support also to libaomenc.
> ---
>  libavcodec/libaomenc.c | 51 --
>  1 file changed, 44 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index 096aadbe1c..a3c5ae8f54 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -154,7 +154,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 +163,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,
> @@ -276,6 +277,25 @@ static int set_pix_fmt(AVCodecContext *avctx,
> aom_codec_caps_t codec_caps,
>  AOMContext av_unused *ctx = avctx->priv_data;
>  enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
>  switch (avctx->pix_fmt) {
> +case AV_PIX_FMT_GRAY8:
> +enccfg->monochrome = 1u;
> +enccfg->g_profile = FF_PROFILE_AV1_MAIN;
> +*img_fmt = AOM_IMG_FMT_I420;
> +return 0;
> +case AV_PIX_FMT_GRAY10:
> +case AV_PIX_FMT_GRAY12:
> +if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
> +enccfg->monochrome = 1u;
> +enccfg->g_profile =
> +avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? FF_PROFILE_AV1_MAIN
> +:
> FF_PROFILE_AV1_PROFESSIONAL;
> +enccfg->g_bit_depth = enccfg->g_input_bit_depth =
> +avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? 10 : 12;
> +*img_fmt = AOM_IMG_FMT_I42016;
> +*flags |= AOM_CODEC_USE_HIGHBITDEPTH;
> +return 0;
> +}
> +break;
>  case AV_PIX_FMT_YUV420P:
>  enccfg->g_profile = FF_PROFILE_AV1_MAIN;
>  *img_fmt = AOM_IMG_FMT_I420;
> @@ -979,12 +999,25 @@ static int aom_encode(AVCodecContext *avctx,
> AVPacket *pkt,
>
>  if (frame) {
>  rawimg  = &ctx->rawimg;
> -rawimg->planes[AOM_PLANE_Y] = frame->data[0];
> -rawimg->planes[AOM_PLANE_U] = frame->data[1];
> -rawimg->planes[AOM_PLANE_V] = frame->data[2];
> -rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
> -rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
> -rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
> +if (frame->format == AV_PIX_FMT_GRAY8 ||
> +frame->format == AV_PIX_FMT_GRAY10 ||
> +frame->format == AV_PIX_FMT_GRAY12) {
> +rawimg->monochrome = 1;
> +rawimg->planes[AOM_PLANE_Y] = frame->data[0];
> +rawimg->planes[AOM_PLANE_U] = frame->data[0];
> +rawimg->planes[AOM_PLANE_V] = frame->data[0];
> +rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
> +rawimg->stride[AOM_PLANE_U] = frame->linesize[0];
> +rawimg->stride[AOM_PLANE_V] = frame->linesize[0];
> +} else {
> +rawimg->monochrome = 0;
> +rawimg->planes[AOM_PLANE_Y] = frame->data[0];
> +rawimg->planes[AOM_PLANE_U] = frame->data[1];
> +rawimg->planes[AOM_PLANE_V] = frame->data[2];
> +rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
> +rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
> +  

Re: [FFmpeg-devel] [PATCH v3 1/2] libavcodec/libaomenc.c: Support gray input

2020-04-07 Thread Ryo Hirafuji
James, thank you for your review!


> You can merge these with the AV_PIX_FMT_YUV420P* cases below, doing
> something like
> enccfg->monochrome = avctx->pix_fmt == AV_PIX_FMT_GRAY8;
> and
> enccfg->monochrome = avctx->pix_fmt == AV_PIX_FMT_GRAY10 ||
>  avctx->pix_fmt == AV_PIX_FMT_GRAY12;
> to enable monochrome in the gray cases.


It sounds great. Thanks, I will change in patch v4.

 Are these meant to all point to the Y plane, or can they be NULL/0? If
> so, then leaving this chunk as it was should AFAIK work.


U plane and V plane will be ignored when "monochorme=1", but it crashes
with SIGSEGV when U plane or V plane is NULL.
So we have to set some valid pointers.
If aom_image is allocated by aom_img_alloc function, U plane and V plane
are allocated.
But we use aom_img_wrap function, so we have to prepare some valid pointers
ourselves.

> +rawimg->planes[AOM_PLANE_Y] = frame->data[0];
> +rawimg->planes[AOM_PLANE_U] = frame->data[1];
> +rawimg->planes[AOM_PLANE_V] = frame->data[2];
> +rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
> +rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
> +rawimg->stride[AOM_PLANE_V] = frame->linesize[2];

I also tested with this code before, but frame->data[1] or frame->[2]
sometimes becomes NULL or (maybe) invalid pointer for gray data.
(gray doesn't have U and V, so I think it's not strange.)

2020年4月8日(水) 3:23 James Almer :

> On 4/7/2020 3:11 PM, Ryo Hirafuji wrote:
> > From: Ryo Hirafuji 
> >
> > AV1 decoders, libaomdec and libdav1d, both support grayscale image.
> > However, libaomenc does not support it yet.
> > In this patch, I add a grayscale image support also to libaomenc.
> >
> > Fixes ticket #7599
> > ---
> >  libavcodec/libaomenc.c | 51 --
> >  1 file changed, 44 insertions(+), 7 deletions(-)
> >
> > diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> > index 096aadbe1c..a3c5ae8f54 100644
> > --- a/libavcodec/libaomenc.c
> > +++ b/libavcodec/libaomenc.c
> > @@ -154,7 +154,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 +163,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,
> > @@ -276,6 +277,25 @@ static int set_pix_fmt(AVCodecContext *avctx,
> aom_codec_caps_t codec_caps,
> >  AOMContext av_unused *ctx = avctx->priv_data;
> >  enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
> >  switch (avctx->pix_fmt) {
> > +case AV_PIX_FMT_GRAY8:
> > +enccfg->monochrome = 1u;
> > +enccfg->g_profile = FF_PROFILE_AV1_MAIN;
> > +*img_fmt = AOM_IMG_FMT_I420;
> > +return 0;
> > +case AV_PIX_FMT_GRAY10:
> > +case AV_PIX_FMT_GRAY12:
> > +if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
> > +enccfg->monochrome = 1u;
> > +enccfg->g_profile =
> > +avctx->pix_fmt == AV_PIX_FMT_GRAY10 ?
> FF_PROFILE_AV1_MAIN
> > +:
> FF_PROFILE_AV1_PROFESSIONAL;
> > +enccfg->g_bit_depth = enccfg->g_input_bit_depth =
> > +avctx->pix_fmt == AV_PIX_FMT_GRAY10 ? 10 : 12;
> > +*img_fmt = AOM_IMG_FMT_I42016;
> > +*flags |= AOM_CODEC_USE_HIGHBITDEPTH;
> > +return 0;
> > +}
> > +  

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

2020-04-07 Thread Ryo Hirafuji
From: Ryo Hirafuji 

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

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v4 1/2] libavcodec/libaomenc.c: Support gray input

2020-04-07 Thread Ryo Hirafuji
From: Ryo Hirafuji 

AV1 decoders, libaomdec and libdav1d, both support grayscale image.
However, libaomenc does not support it yet.
In this patch, I add a grayscale image support also to libaomenc.

Fixes ticket #7599
---
 libavcodec/libaomenc.c | 40 +---
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..ff79c0af9f 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -154,7 +154,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 +163,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,
@@ -276,7 +277,9 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
 AOMContext av_unused *ctx = avctx->priv_data;
 enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
 switch (avctx->pix_fmt) {
+case AV_PIX_FMT_GRAY8:
 case AV_PIX_FMT_YUV420P:
+enccfg->monochrome = avctx->pix_fmt == AV_PIX_FMT_GRAY8;
 enccfg->g_profile = FF_PROFILE_AV1_MAIN;
 *img_fmt = AOM_IMG_FMT_I420;
 return 0;
@@ -288,9 +291,13 @@ static int set_pix_fmt(AVCodecContext *avctx, 
aom_codec_caps_t codec_caps,
 enccfg->g_profile = FF_PROFILE_AV1_HIGH;
 *img_fmt = AOM_IMG_FMT_I444;
 return 0;
+case AV_PIX_FMT_GRAY10:
+case AV_PIX_FMT_GRAY12:
 case AV_PIX_FMT_YUV420P10:
 case AV_PIX_FMT_YUV420P12:
 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
+enccfg->monochrome = avctx->pix_fmt == AV_PIX_FMT_GRAY10 ||
+ avctx->pix_fmt == AV_PIX_FMT_GRAY12;
 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
 avctx->pix_fmt == AV_PIX_FMT_YUV420P10 ? 10 : 12;
 enccfg->g_profile =
@@ -979,12 +986,27 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 
 if (frame) {
 rawimg  = &ctx->rawimg;
-rawimg->planes[AOM_PLANE_Y] = frame->data[0];
-rawimg->planes[AOM_PLANE_U] = frame->data[1];
-rawimg->planes[AOM_PLANE_V] = frame->data[2];
-rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
-rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
-rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
+if (frame->format == AV_PIX_FMT_GRAY8 ||
+frame->format == AV_PIX_FMT_GRAY10 ||
+frame->format == AV_PIX_FMT_GRAY12) {
+rawimg->monochrome = 1;
+// Information of U and V planes are ignored,
+// but must point some valid pointer to avoid SIGSEGV of libaom.
+rawimg->planes[AOM_PLANE_Y] = frame->data[0];
+rawimg->planes[AOM_PLANE_U] = frame->data[0];
+rawimg->planes[AOM_PLANE_V] = frame->data[0];
+rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[0];
+} else {
+rawimg->monochrome = 0;
+rawimg->planes[AOM_PLANE_Y] = frame->data[0];
+rawimg->planes[AOM_PLANE_U] = frame->data[1];
+rawimg->planes[AOM_PLANE_V] = frame->data[2];
+rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
+}
 timestamp   = frame->pts;
 switch (frame->color_range) {
 case AVCOL_RANGE_MPEG:
@@ -1025,6 +1047,7 @@ static int aom_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 }
 
 static const enum AVPixelFormat av1_pix_fmts[] = {
+AV_PIX_FMT_GRAY8,

Re: [FFmpeg-devel] [PATCH v4 1/2] libavcodec/libaomenc.c: Support gray input

2020-04-11 Thread Ryo Hirafuji
Hi!

I would like to discuss this patch, but I can't find who is the maintainer
of this codec.
https://github.com/FFmpeg/FFmpeg/blob/master/MAINTAINERS
Does anyone know?

If something was BAD, I would like to rewrite it better.
If splitting this patch into gray support and lossless support patch is
better, I will do so.

Best,
Ryo.

2020年4月8日(水) 9:14 Ryo Hirafuji :

> From: Ryo Hirafuji 
>
> AV1 decoders, libaomdec and libdav1d, both support grayscale image.
> However, libaomenc does not support it yet.
> In this patch, I add a grayscale image support also to libaomenc.
>
> Fixes ticket #7599
> ---
>  libavcodec/libaomenc.c | 40 +---
>  1 file changed, 33 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index 096aadbe1c..ff79c0af9f 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -154,7 +154,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 +163,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,
> @@ -276,7 +277,9 @@ static int set_pix_fmt(AVCodecContext *avctx,
> aom_codec_caps_t codec_caps,
>  AOMContext av_unused *ctx = avctx->priv_data;
>  enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
>  switch (avctx->pix_fmt) {
> +case AV_PIX_FMT_GRAY8:
>  case AV_PIX_FMT_YUV420P:
> +enccfg->monochrome = avctx->pix_fmt == AV_PIX_FMT_GRAY8;
>  enccfg->g_profile = FF_PROFILE_AV1_MAIN;
>  *img_fmt = AOM_IMG_FMT_I420;
>  return 0;
> @@ -288,9 +291,13 @@ static int set_pix_fmt(AVCodecContext *avctx,
> aom_codec_caps_t codec_caps,
>  enccfg->g_profile = FF_PROFILE_AV1_HIGH;
>  *img_fmt = AOM_IMG_FMT_I444;
>  return 0;
> +case AV_PIX_FMT_GRAY10:
> +case AV_PIX_FMT_GRAY12:
>  case AV_PIX_FMT_YUV420P10:
>  case AV_PIX_FMT_YUV420P12:
>  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
> +enccfg->monochrome = avctx->pix_fmt == AV_PIX_FMT_GRAY10 ||
> + avctx->pix_fmt == AV_PIX_FMT_GRAY12;
>  enccfg->g_bit_depth = enccfg->g_input_bit_depth =
>  avctx->pix_fmt == AV_PIX_FMT_YUV420P10 ? 10 : 12;
>  enccfg->g_profile =
> @@ -979,12 +986,27 @@ static int aom_encode(AVCodecContext *avctx,
> AVPacket *pkt,
>
>  if (frame) {
>  rawimg  = &ctx->rawimg;
> -rawimg->planes[AOM_PLANE_Y] = frame->data[0];
> -rawimg->planes[AOM_PLANE_U] = frame->data[1];
> -rawimg->planes[AOM_PLANE_V] = frame->data[2];
> -rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
> -rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
> -rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
> +if (frame->format == AV_PIX_FMT_GRAY8 ||
> +frame->format == AV_PIX_FMT_GRAY10 ||
> +frame->format == AV_PIX_FMT_GRAY12) {
> +rawimg->monochrome = 1;
> +// Information of U and V planes are ignored,
> +// but must point some valid pointer to avoid SIGSEGV of
> libaom.
> +rawimg->planes[AOM_PLANE_Y] = frame->data[0];
> +rawimg->planes[AOM_PLANE_U] = frame->data[0];
> +rawimg->planes[AOM_PLANE_V] = frame->data[0];
> +rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
> +rawimg->stride[AOM_PLANE_U] = frame->linesize[0];
> +rawimg->stride[AOM_PLANE_V] = frame->linesize[0];
&g

Re: [FFmpeg-devel] [PATCH v4 1/2] libavcodec/libaomenc.c: Support gray input

2020-04-14 Thread Ryo Hirafuji
Thanks for the review!

This should bump the micro version number in libavcodec/version.h.


OK, I will bump up the version when the problem below is solved.


> That's annoying. I filed a bug to track [1]. The monochrome flag
> itself seems unnecessary for the library rather than just an image
> format, but that's another discussion.
>

 Thanks for creating the issue.

You might be right.
I just need this line to set  the monochrome flag to 1 in Sequence Header
OBU:
> enccfg->monochrome = 1u;

This reads a little strangely to me, maybe something like: U and V
> information is ignored, but must point to valid buffers...?
> [1] https://crbug.com/aomedia/2639


I pasted the stack trace when V plane and U plane are NULL and ffmpeg
crashes:
https://bugs.chromium.org/p/aomedia/issues/detail?id=2639#c1
(ryoh@... is also my account)

If we allocate aom_image with aom_img_alloc function, allocated V plane and
U plane are filled with 0 (not 128, 512 or 2048).
And I don't have to fill them to 128 to obtain a gray image.
(I tried it in https://github.com/link-u/cavif )
So I think these planes are just ignored (but not sure).

2020年4月14日(火) 6:25 James Zern :

> Hi,
>
> On Tue, Apr 7, 2020 at 5:14 PM Ryo Hirafuji 
> wrote:
> >
> > From: Ryo Hirafuji 
> >
> > AV1 decoders, libaomdec and libdav1d, both support grayscale image.
> > However, libaomenc does not support it yet.
> > In this patch, I add a grayscale image support also to libaomenc.
> >
> > Fixes ticket #7599
> > ---
> >  libavcodec/libaomenc.c | 40 +---
> >  1 file changed, 33 insertions(+), 7 deletions(-)
> >
>
> This should bump the micro version number in libavcodec/version.h.
>
> > [...]
> > @@ -979,12 +986,27 @@ static int aom_encode(AVCodecContext *avctx,
> AVPacket *pkt,
> >
> >  if (frame) {
> >  rawimg  = &ctx->rawimg;
> > -rawimg->planes[AOM_PLANE_Y] = frame->data[0];
> > -rawimg->planes[AOM_PLANE_U] = frame->data[1];
> > -rawimg->planes[AOM_PLANE_V] = frame->data[2];
> > -rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
> > -rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
> > -rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
> > +if (frame->format == AV_PIX_FMT_GRAY8 ||
> > +frame->format == AV_PIX_FMT_GRAY10 ||
> > +frame->format == AV_PIX_FMT_GRAY12) {
> > +rawimg->monochrome = 1;
> > +// Information of U and V planes are ignored,
> > +// but must point some valid pointer to avoid SIGSEGV of
> libaom.
>
> That's annoying. I filed a bug to track [1]. The monochrome flag
> itself seems unnecessary for the library rather than just an image
> format, but that's another discussion.
> This reads a little strangely to me, maybe something like: U and V
> information is ignored, but must point to valid buffers...?
>
> [1] https://crbug.com/aomedia/2639
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

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

2020-04-17 Thread Ryo Hirafuji
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 :

> On Tue, Apr 7, 2020 at 5:14 PM Ryo Hirafuji 
> wrote:
> >
> > From: Ryo Hirafuji 
> >
> > 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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v4 1/2] libavcodec/libaomenc.c: Support gray input

2020-05-09 Thread Ryo Hirafuji
Hi.

https://crbug.com/aomedia/2545

This bug is resolved and we no longer need these lines to avoid crash in
libaom.

> -rawimg->planes[AOM_PLANE_U] = frame->data[1];
> -rawimg->planes[AOM_PLANE_V] = frame->data[2];
> -rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
> -rawimg->stride[AOM_PLANE_V] = frame->linesize[2];

I can create and send a new patch without these workaround lines, but of
course, it will crash if the ffmpeg will be built with older versions of
libaom.
How should I resolve this backward compatibility issue? or I don't have to
consider it?

Please give me some advice.


2020年4月16日(木) 2:58 James Zern :

> On Wed, Apr 15, 2020 at 8:14 AM James Almer  wrote:
> >
> > On 4/14/2020 9:26 PM, James Zern wrote:
> > > On Tue, Apr 14, 2020 at 3:57 AM Ryo Hirafuji <
> ryo.hiraf...@link-u.co.jp> wrote:
> > >>
> > >> Thanks for the review!
> > >>
> > >> This should bump the micro version number in libavcodec/version.h.
> > >>
> > >>
> > >> OK, I will bump up the version when the problem below is solved.
> > >>
> > >
> > > If we want to go for compatibility with different versions of the
> > > library we could move forward with the patch as is, though it would be
> > > simpler to just treat this as a bug fix in libaom.
> >
> > Once a new version of libaom is tagged (Hopefully soon, since it's been
> > almost two years since 1.0.0), we could set it as the minimum
> > requirement and forget about 1.0.0, since that version is by now
> > essentially unusable.
> >
>
> Thanks, that was my hope. I just wasn't sure how long we wanted to
> wait before changing the minimum. You're right though, the only tags
> are old and were more for bitstream compatibility rather than encoder
> functionality. A full release should be coming soon [1] and with more
> regular frequency after that.
>
> [1] https://crbug.com/aomedia/2545
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v4 1/2] libavcodec/libaomenc.c: Support gray input

2020-05-09 Thread Ryo Hirafuji
Sorry,

Resolved bug is this:
https://bugs.chromium.org/p/aomedia/issues/detail?id=2639

and we no longer need these lines:

+rawimg->planes[AOM_PLANE_U] = frame->data[0];
+rawimg->planes[AOM_PLANE_V] = frame->data[0];
+rawimg->stride[AOM_PLANE_U] = frame->linesize[0];
+rawimg->stride[AOM_PLANE_V] = frame->linesize[0];

2020年5月10日(日) 0:59 Ryo Hirafuji :

> Hi.
>
> https://crbug.com/aomedia/2545
>
> This bug is resolved and we no longer need these lines to avoid crash in
> libaom.
>
> > -rawimg->planes[AOM_PLANE_U] = frame->data[1];
> > -rawimg->planes[AOM_PLANE_V] = frame->data[2];
> > -rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
> > -rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
>
> I can create and send a new patch without these workaround lines, but of
> course, it will crash if the ffmpeg will be built with older versions of
> libaom.
> How should I resolve this backward compatibility issue? or I don't have to
> consider it?
>
> Please give me some advice.
>
>
> 2020年4月16日(木) 2:58 James Zern :
>
>> On Wed, Apr 15, 2020 at 8:14 AM James Almer  wrote:
>> >
>> > On 4/14/2020 9:26 PM, James Zern wrote:
>> > > On Tue, Apr 14, 2020 at 3:57 AM Ryo Hirafuji <
>> ryo.hiraf...@link-u.co.jp> wrote:
>> > >>
>> > >> Thanks for the review!
>> > >>
>> > >> This should bump the micro version number in libavcodec/version.h.
>> > >>
>> > >>
>> > >> OK, I will bump up the version when the problem below is solved.
>> > >>
>> > >
>> > > If we want to go for compatibility with different versions of the
>> > > library we could move forward with the patch as is, though it would be
>> > > simpler to just treat this as a bug fix in libaom.
>> >
>> > Once a new version of libaom is tagged (Hopefully soon, since it's been
>> > almost two years since 1.0.0), we could set it as the minimum
>> > requirement and forget about 1.0.0, since that version is by now
>> > essentially unusable.
>> >
>>
>> Thanks, that was my hope. I just wasn't sure how long we wanted to
>> wait before changing the minimum. You're right though, the only tags
>> are old and were more for bitstream compatibility rather than encoder
>> functionality. A full release should be coming soon [1] and with more
>> regular frequency after that.
>>
>> [1] https://crbug.com/aomedia/2545
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".