Re: [FFmpeg-devel] [PATCH] avfilter/alimiter:add latency compensation

2022-05-10 Thread Wang Cao
On Thu, May 5, 2022 at 2:14 PM Wang Cao  wrote:

> Also added 2 FATE tests to verify delay is compenated correctly
>
> Signed-off-by: Wang Cao 
> ---
>  doc/filters.texi|  5 +++
>  libavfilter/af_alimiter.c   | 90 +
>  tests/fate/filter-audio.mak | 24 --
>  3 files changed, 116 insertions(+), 3 deletions(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index a161754233..75a43edd88 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -1978,6 +1978,11 @@ in release time while 1 produces higher release
> times.
>  @item level
>  Auto level output signal. Default is enabled.
>  This normalizes audio back to 0dB if enabled.
> +
> +@item latency
> +Compensate the delay introduced by using the lookahead buffer set with
> attack
> +parameter. Also flush the valid audio data in the lookahead buffer when
> the
> +stream hits EOF
>  @end table
>
>  Depending on picked setting it is recommended to upsample input 2x or 4x
> times
> diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
> index 133f98f165..01265758d7 100644
> --- a/libavfilter/af_alimiter.c
> +++ b/libavfilter/af_alimiter.c
> @@ -26,6 +26,7 @@
>
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/common.h"
> +#include "libavutil/fifo.h"
>  #include "libavutil/opt.h"
>
>  #include "audio.h"
> @@ -33,6 +34,11 @@
>  #include "formats.h"
>  #include "internal.h"
>
> +typedef struct MetaItem {
> +int64_t pts;
> +int nb_samples;
> +} MetaItem;
> +
>  typedef struct AudioLimiterContext {
>  const AVClass *class;
>
> @@ -55,6 +61,14 @@ typedef struct AudioLimiterContext {
>  int *nextpos;
>  double *nextdelta;
>
> +int in_trim;
> +int out_pad;
> +int64_t next_in_pts;
> +int64_t next_out_pts;
> +int latency;
> +
> +AVFifo *fifo;
> +
>  double delta;
>  int nextiter;
>  int nextlen;
> @@ -73,6 +87,7 @@ static const AVOption alimiter_options[] = {
>  { "asc",   "enable asc",   OFFSET(auto_release),
> AV_OPT_TYPE_BOOL,   {.i64=0},  0,1, AF },
>  { "asc_level", "set asc level",OFFSET(asc_coeff),
> AV_OPT_TYPE_DOUBLE, {.dbl=0.5},0,1, AF },
>  { "level", "auto level",   OFFSET(auto_level),
>  AV_OPT_TYPE_BOOL,   {.i64=1},  0,1, AF },
> +{ "latency",   "compensate delay", OFFSET(latency),
> AV_OPT_TYPE_BOOL,   {.i64=0},  0,1, AF },
>  { NULL }
>  };
>
> @@ -129,6 +144,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> *in)
>  AVFrame *out;
>  double *buf;
>  int n, c, i;
> +int new_out_samples;
> +int64_t out_duration;
> +int64_t in_duration;
> +int64_t in_pts;
> +MetaItem meta;
>
>  if (av_frame_is_writable(in)) {
>  out = in;
> @@ -269,12 +289,69 @@ static int filter_frame(AVFilterLink *inlink,
> AVFrame *in)
>  dst += channels;
>  }
>
> +in_duration = av_rescale_q(in->nb_samples,  inlink->time_base,
> av_make_q(1,  in->sample_rate));
> +in_pts = in->pts;
> +meta = (MetaItem){ in->pts, in->nb_samples };
> +av_fifo_write(s->fifo, , 1);
>  if (in != out)
>  av_frame_free();
>
> +new_out_samples = out->nb_samples;
> +if (s->in_trim > 0) {
> +int trim = FFMIN(new_out_samples, s->in_trim);
> +new_out_samples -= trim;
> +s->in_trim -= trim;
> +}
> +
> +if (new_out_samples <= 0) {
> +av_frame_free();
> +return 0;
> +} else if (new_out_samples < out->nb_samples) {
> +int offset = out->nb_samples - new_out_samples;
> +memmove(out->extended_data[0], out->extended_data[0] +
> sizeof(double) * offset * out->ch_layout.nb_channels,
> +sizeof(double) * new_out_samples *
> out->ch_layout.nb_channels);
> +out->nb_samples = new_out_samples;
> +s->in_trim = 0;
> +}
> +
> +av_fifo_read(s->fifo, , 1);
> +
> +out_duration = av_rescale_q(out->nb_samples, inlink->time_base,
> av_make_q(1, out->sample_rate));
> +in_duration  = av_rescale_q(meta.nb_samples, inlink->time_base,
> av_make_q(1, out->sample_rate));
> +in_pts   = meta.pts;
> +
> +if (s->next_out_pts != AV_NOPTS_VALUE && out->pts != s->next_out_pts
> &&
> +s->next_in_pts  != AV_NOPTS_VALUE && in_pts   == s-

Re: [FFmpeg-devel] [PATCH] avfilter/alimiter: Add an option "comp_delay" that removes the delay introduced by lookahead buffer

2022-05-05 Thread Wang Cao
On Mon, May 2, 2022 at 1:24 AM Paul B Mahol  wrote:

> On Fri, Apr 29, 2022 at 10:49 PM Wang Cao <
> wangcao-at-google@ffmpeg.org>
> wrote:
>
> > On Fri, Apr 15, 2022 at 11:50 AM Wang Cao  wrote:
> >
> > > 1. The option also flushes all the valid audio samples in the lookahead
> > >buffer so the audio integrity is preserved. Previously the the
> output
> > >audio will lose the amount of audio samples equal to the size of
> > >lookahead buffer
> > > 2. Add a FATE test to verify that when the filter is working as
> > >passthrough filter, all audio samples are properly handled from the
> > >input to the output.
> > >
> > > Signed-off-by: Wang Cao 
> > > ---
> > >  doc/filters.texi|  5 +++
> > >  libavfilter/af_alimiter.c   | 74 +
> > >  tests/fate/filter-audio.mak | 12 ++
> > >  3 files changed, 91 insertions(+)
> > >
> > > diff --git a/doc/filters.texi b/doc/filters.texi
> > > index a161754233..2af0953c89 100644
> > > --- a/doc/filters.texi
> > > +++ b/doc/filters.texi
> > > @@ -1978,6 +1978,11 @@ in release time while 1 produces higher release
> > > times.
> > >  @item level
> > >  Auto level output signal. Default is enabled.
> > >  This normalizes audio back to 0dB if enabled.
> > > +
> > > +@item comp_delay
> > > +Compensate the delay introduced by using the lookahead buffer set with
> > > attack
> > > +parameter. Also flush the valid audio data in the lookahead buffer
> when
> > > the
> > > +stream hits EOF.
> > >  @end table
> > >
> > >  Depending on picked setting it is recommended to upsample input 2x or
> 4x
> > > times
> > > diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
> > > index 133f98f165..d10a90859b 100644
> > > --- a/libavfilter/af_alimiter.c
> > > +++ b/libavfilter/af_alimiter.c
> > > @@ -55,6 +55,12 @@ typedef struct AudioLimiterContext {
> > >  int *nextpos;
> > >  double *nextdelta;
> > >
> > > +int lookahead_delay_samples;
> > > +int lookahead_flush_samples;
> > > +int64_t output_pts;
> > > +int64_t next_output_pts;
> > > +int comp_delay;
> > > +
> > >  double delta;
> > >  int nextiter;
> > >  int nextlen;
> > > @@ -73,6 +79,7 @@ static const AVOption alimiter_options[] = {
> > >  { "asc",   "enable asc",   OFFSET(auto_release),
> > > AV_OPT_TYPE_BOOL,   {.i64=0},  0,1, AF },
> > >  { "asc_level", "set asc level",OFFSET(asc_coeff),
> > > AV_OPT_TYPE_DOUBLE, {.dbl=0.5},0,1, AF },
> > >  { "level", "auto level",   OFFSET(auto_level),
> > >  AV_OPT_TYPE_BOOL,   {.i64=1},  0,1, AF },
> > > +{ "comp_delay","compensate delay", OFFSET(comp_delay),
> > >  AV_OPT_TYPE_BOOL,   {.i64=0},  0,1, AF },
> > >  { NULL }
> > >  };
> > >
> > > @@ -129,6 +136,8 @@ static int filter_frame(AVFilterLink *inlink,
> AVFrame
> > > *in)
> > >  AVFrame *out;
> > >  double *buf;
> > >  int n, c, i;
> > > +int num_output_samples = in->nb_samples;
> > > +int trim_offset;
> > >
> > >  if (av_frame_is_writable(in)) {
> > >  out = in;
> > > @@ -271,10 +280,71 @@ static int filter_frame(AVFilterLink *inlink,
> > > AVFrame *in)
> > >
> > >  if (in != out)
> > >  av_frame_free();
> > > +
> > > +if (!s->comp_delay) {
> > > +return ff_filter_frame(outlink, out);
> > > +}
> > > +
> > > +if (s->output_pts == AV_NOPTS_VALUE) {
> > > +s->output_pts = in->pts;
> > > +}
> > > +
> > > +if (s->lookahead_delay_samples > 0) {
> > > +// The current output frame is completely silence
> > > +if (s->lookahead_delay_samples >= in->nb_samples) {
> > > +s->lookahead_delay_samples -= in->nb_samples;
> > > +return 0;
> > > +}
> > > +
> > > +// Trim the silence part
> > > +trim_offset = av_samples_get_buffer_size(
> > > +NULL, inlink->ch_layout.nb_ch

[FFmpeg-devel] [PATCH] avfilter/alimiter:add latency compensation

2022-05-05 Thread Wang Cao
Also added 2 FATE tests to verify delay is compenated correctly

Signed-off-by: Wang Cao 
---
 doc/filters.texi|  5 +++
 libavfilter/af_alimiter.c   | 90 +
 tests/fate/filter-audio.mak | 24 --
 3 files changed, 116 insertions(+), 3 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index a161754233..75a43edd88 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1978,6 +1978,11 @@ in release time while 1 produces higher release times.
 @item level
 Auto level output signal. Default is enabled.
 This normalizes audio back to 0dB if enabled.
+
+@item latency
+Compensate the delay introduced by using the lookahead buffer set with attack
+parameter. Also flush the valid audio data in the lookahead buffer when the 
+stream hits EOF
 @end table
 
 Depending on picked setting it is recommended to upsample input 2x or 4x times
diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
index 133f98f165..01265758d7 100644
--- a/libavfilter/af_alimiter.c
+++ b/libavfilter/af_alimiter.c
@@ -26,6 +26,7 @@
 
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
+#include "libavutil/fifo.h"
 #include "libavutil/opt.h"
 
 #include "audio.h"
@@ -33,6 +34,11 @@
 #include "formats.h"
 #include "internal.h"
 
+typedef struct MetaItem {
+int64_t pts;
+int nb_samples;
+} MetaItem;
+
 typedef struct AudioLimiterContext {
 const AVClass *class;
 
@@ -55,6 +61,14 @@ typedef struct AudioLimiterContext {
 int *nextpos;
 double *nextdelta;
 
+int in_trim;
+int out_pad;
+int64_t next_in_pts;
+int64_t next_out_pts;
+int latency;
+
+AVFifo *fifo;
+
 double delta;
 int nextiter;
 int nextlen;
@@ -73,6 +87,7 @@ static const AVOption alimiter_options[] = {
 { "asc",   "enable asc",   OFFSET(auto_release), AV_OPT_TYPE_BOOL, 
  {.i64=0},  0,1, AF },
 { "asc_level", "set asc level",OFFSET(asc_coeff),
AV_OPT_TYPE_DOUBLE, {.dbl=0.5},0,1, AF },
 { "level", "auto level",   OFFSET(auto_level),   AV_OPT_TYPE_BOOL, 
  {.i64=1},  0,1, AF },
+{ "latency",   "compensate delay", OFFSET(latency),  AV_OPT_TYPE_BOOL, 
  {.i64=0},  0,1, AF },
 { NULL }
 };
 
@@ -129,6 +144,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFrame *out;
 double *buf;
 int n, c, i;
+int new_out_samples;
+int64_t out_duration;
+int64_t in_duration;
+int64_t in_pts;
+MetaItem meta;
 
 if (av_frame_is_writable(in)) {
 out = in;
@@ -269,12 +289,69 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 dst += channels;
 }
 
+in_duration = av_rescale_q(in->nb_samples,  inlink->time_base, 
av_make_q(1,  in->sample_rate));
+in_pts = in->pts;
+meta = (MetaItem){ in->pts, in->nb_samples };
+av_fifo_write(s->fifo, , 1);
 if (in != out)
 av_frame_free();
 
+new_out_samples = out->nb_samples;
+if (s->in_trim > 0) {
+int trim = FFMIN(new_out_samples, s->in_trim);
+new_out_samples -= trim;
+s->in_trim -= trim;
+}
+
+if (new_out_samples <= 0) {
+av_frame_free();
+return 0;
+} else if (new_out_samples < out->nb_samples) {
+int offset = out->nb_samples - new_out_samples;
+memmove(out->extended_data[0], out->extended_data[0] + sizeof(double) 
* offset * out->ch_layout.nb_channels,
+sizeof(double) * new_out_samples * out->ch_layout.nb_channels);
+out->nb_samples = new_out_samples;
+s->in_trim = 0;
+}
+
+av_fifo_read(s->fifo, , 1);
+
+out_duration = av_rescale_q(out->nb_samples, inlink->time_base, 
av_make_q(1, out->sample_rate));
+in_duration  = av_rescale_q(meta.nb_samples, inlink->time_base, 
av_make_q(1, out->sample_rate));
+in_pts   = meta.pts;
+
+if (s->next_out_pts != AV_NOPTS_VALUE && out->pts != s->next_out_pts &&
+s->next_in_pts  != AV_NOPTS_VALUE && in_pts   == s->next_in_pts) {
+out->pts = s->next_out_pts;
+} else {
+out->pts = in_pts;
+}
+s->next_in_pts  = in_pts   + in_duration;
+s->next_out_pts = out->pts + out_duration;
+
 return ff_filter_frame(outlink, out);
 }
 
+static int request_frame(AVFilterLink* outlink) 
+{
+AVFilterContext *ctx = outlink->src;
+AudioLimiterContext *s = (AudioLimiterContext*)ctx->priv;
+int ret;
+
+ret = ff_request_frame(ctx->inputs[0]);
+
+if (ret == AVERROR_EOF && s->out_pad > 0) {
+AVFrame *frame = ff_get_audio_buffer(outlink, FFMIN(1024, s->out_pad));
+if (!frame)
+return

Re: [FFmpeg-devel] [PATCH] avfilter/alimiter: Add an option "comp_delay" that removes the delay introduced by lookahead buffer

2022-04-29 Thread Wang Cao
On Fri, Apr 15, 2022 at 11:50 AM Wang Cao  wrote:

> 1. The option also flushes all the valid audio samples in the lookahead
>buffer so the audio integrity is preserved. Previously the the output
>audio will lose the amount of audio samples equal to the size of
>lookahead buffer
> 2. Add a FATE test to verify that when the filter is working as
>passthrough filter, all audio samples are properly handled from the
>input to the output.
>
> Signed-off-by: Wang Cao 
> ---
>  doc/filters.texi|  5 +++
>  libavfilter/af_alimiter.c   | 74 +
>  tests/fate/filter-audio.mak | 12 ++
>  3 files changed, 91 insertions(+)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index a161754233..2af0953c89 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -1978,6 +1978,11 @@ in release time while 1 produces higher release
> times.
>  @item level
>  Auto level output signal. Default is enabled.
>  This normalizes audio back to 0dB if enabled.
> +
> +@item comp_delay
> +Compensate the delay introduced by using the lookahead buffer set with
> attack
> +parameter. Also flush the valid audio data in the lookahead buffer when
> the
> +stream hits EOF.
>  @end table
>
>  Depending on picked setting it is recommended to upsample input 2x or 4x
> times
> diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
> index 133f98f165..d10a90859b 100644
> --- a/libavfilter/af_alimiter.c
> +++ b/libavfilter/af_alimiter.c
> @@ -55,6 +55,12 @@ typedef struct AudioLimiterContext {
>  int *nextpos;
>  double *nextdelta;
>
> +int lookahead_delay_samples;
> +int lookahead_flush_samples;
> +int64_t output_pts;
> +int64_t next_output_pts;
> +int comp_delay;
> +
>  double delta;
>  int nextiter;
>  int nextlen;
> @@ -73,6 +79,7 @@ static const AVOption alimiter_options[] = {
>  { "asc",   "enable asc",   OFFSET(auto_release),
> AV_OPT_TYPE_BOOL,   {.i64=0},  0,1, AF },
>  { "asc_level", "set asc level",OFFSET(asc_coeff),
> AV_OPT_TYPE_DOUBLE, {.dbl=0.5},0,1, AF },
>  { "level", "auto level",   OFFSET(auto_level),
>  AV_OPT_TYPE_BOOL,   {.i64=1},  0,1, AF },
> +{ "comp_delay","compensate delay", OFFSET(comp_delay),
>  AV_OPT_TYPE_BOOL,   {.i64=0},  0,1, AF },
>  { NULL }
>  };
>
> @@ -129,6 +136,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> *in)
>  AVFrame *out;
>  double *buf;
>  int n, c, i;
> +int num_output_samples = in->nb_samples;
> +int trim_offset;
>
>  if (av_frame_is_writable(in)) {
>  out = in;
> @@ -271,10 +280,71 @@ static int filter_frame(AVFilterLink *inlink,
> AVFrame *in)
>
>  if (in != out)
>  av_frame_free();
> +
> +if (!s->comp_delay) {
> +return ff_filter_frame(outlink, out);
> +}
> +
> +if (s->output_pts == AV_NOPTS_VALUE) {
> +s->output_pts = in->pts;
> +}
> +
> +if (s->lookahead_delay_samples > 0) {
> +// The current output frame is completely silence
> +if (s->lookahead_delay_samples >= in->nb_samples) {
> +s->lookahead_delay_samples -= in->nb_samples;
> +return 0;
> +}
> +
> +// Trim the silence part
> +trim_offset = av_samples_get_buffer_size(
> +NULL, inlink->ch_layout.nb_channels,
> s->lookahead_delay_samples,
> +(enum AVSampleFormat)out->format, 1);
> +out->data[0] += trim_offset;
> +out->nb_samples = in->nb_samples - s->lookahead_delay_samples;
> +s->lookahead_delay_samples = 0;
> +num_output_samples = out->nb_samples;
> +}
> +
> +if (s->lookahead_delay_samples < 0) {
> +return AVERROR_BUG;
> +}
> +
> +out->pts = s->output_pts;
> +s->next_output_pts = s->output_pts + num_output_samples;
> +s->output_pts = s->next_output_pts;
>
>  return ff_filter_frame(outlink, out);
>  }
>
> +static int request_frame(AVFilterLink* outlink)
> +{
> +AVFilterContext *ctx = outlink->src;
> +AudioLimiterContext *s = (AudioLimiterContext*)ctx->priv;
> +int ret;
> +AVFilterLink *inlink;
> +AVFrame *silence_frame;
> +
> +ret = ff_request_frame(ctx->inputs[0]);
> +
> +if (ret != AVERROR_EOF || s->lookahead_flush_samples == 0 ||
> !s->comp_delay) {
> +  // Not necessarily an error, just not EOF.
&

Re: [FFmpeg-devel] [PATCH] avfilter/alimiter: Add "flush_buffer" option to flush the remaining valid data to the output

2022-04-15 Thread Wang Cao
On Tue, Apr 12, 2022 at 12:40 PM Paul B Mahol  wrote:

> On Mon, Apr 11, 2022 at 10:59 PM Wang Cao <
> wangcao-at-google@ffmpeg.org>
> wrote:
>
> > On Sat, Apr 9, 2022 at 5:35 AM Paul B Mahol  wrote:
> >
> > > On Fri, Apr 8, 2022 at 10:41 PM Wang Cao <
> > wangcao-at-google@ffmpeg.org
> > > >
> > > wrote:
> > >
> > > > On Fri, Apr 8, 2022 at 11:40 AM Paul B Mahol 
> wrote:
> > > >
> > > > > On Thu, Apr 7, 2022 at 11:56 PM Wang Cao <
> > > > wangcao-at-google@ffmpeg.org
> > > > > >
> > > > > wrote:
> > > > >
> > > > > > On Thu, Apr 7, 2022 at 12:44 AM Paul B Mahol 
> > > wrote:
> > > > > >
> > > > > > > On Wed, Apr 6, 2022 at 1:49 PM Paul B Mahol 
> > > > wrote:
> > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > On Tue, Apr 5, 2022 at 8:57 PM Wang Cao <
> > > > > > > wangcao-at-google@ffmpeg.org>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > >> On Mon, Apr 4, 2022 at 3:28 PM Marton Balint  >
> > > > wrote:
> > > > > > > >>
> > > > > > > >> >
> > > > > > > >> >
> > > > > > > >> > On Mon, 4 Apr 2022, Paul B Mahol wrote:
> > > > > > > >> >
> > > > > > > >> > > On Sun, Mar 27, 2022 at 11:41 PM Marton Balint <
> > > c...@passwd.hu
> > > > >
> > > > > > > wrote:
> > > > > > > >> > >
> > > > > > > >> > >>
> > > > > > > >> > >>
> > > > > > > >> > >> On Sat, 26 Mar 2022, Wang Cao wrote:
> > > > > > > >> > >>
> > > > > > > >> > >>> The change in the commit will add some samples to the
> > end
> > > of
> > > > > the
> > > > > > > >> audio
> > > > > > > >> > >>> stream. The intention is to add a "zero_delay" option
> > > > > eventually
> > > > > > > to
> > > > > > > >> not
> > > > > > > >> > >>> have the delay in the begining the output from
> alimiter
> > > due
> > > > to
> > > > > > > >> > >>> lookahead.
> > > > > > > >> > >>
> > > > > > > >> > >> I was very much suprised to see that the alimiter
> filter
> > > > > actually
> > > > > > > >> delays
> > > > > > > >> > >> the audio - as in extra samples are inserted in the
> > > beginning
> > > > > and
> > > > > > > >> some
> > > > > > > >> > >> samples are cut in the end. This trashes A-V sync, so
> it
> > > is a
> > > > > bug
> > > > > > > >> IMHO.
> > > > > > > >> > >>
> > > > > > > >> > >> So unless somebody has some valid usecase for the
> legacy
> > > way
> > > > of
> > > > > > > >> > operation
> > > > > > > >> > >> I'd just simply change it to be "zero delay" without
> any
> > > > > > additional
> > > > > > > >> user
> > > > > > > >> > >> option, in a single patch.
> > > > > > > >> > >>
> > > > > > > >> > >
> > > > > > > >> > >
> > > > > > > >> > > This is done by this patch in very complicated way and
> > also
> > > it
> > > > > > > really
> > > > > > > >> > > should be optional.
> > > > > > > >> >
> > > > > > > >> > But why does it make sense to keep the current (IMHO
> buggy)
> > > > > > > operational
> > > > > > > >> > mode which adds silence in the beginning and trims the
> end?
> > I
> > > &

[FFmpeg-devel] [PATCH] avfilter/alimiter: Add an option "comp_delay" that removes the delay introduced by lookahead buffer

2022-04-15 Thread Wang Cao
1. The option also flushes all the valid audio samples in the lookahead
   buffer so the audio integrity is preserved. Previously the the output
   audio will lose the amount of audio samples equal to the size of
   lookahead buffer
2. Add a FATE test to verify that when the filter is working as
   passthrough filter, all audio samples are properly handled from the
   input to the output.

Signed-off-by: Wang Cao 
---
 doc/filters.texi|  5 +++
 libavfilter/af_alimiter.c   | 74 +
 tests/fate/filter-audio.mak | 12 ++
 3 files changed, 91 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index a161754233..2af0953c89 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1978,6 +1978,11 @@ in release time while 1 produces higher release times.
 @item level
 Auto level output signal. Default is enabled.
 This normalizes audio back to 0dB if enabled.
+
+@item comp_delay
+Compensate the delay introduced by using the lookahead buffer set with attack
+parameter. Also flush the valid audio data in the lookahead buffer when the 
+stream hits EOF.
 @end table
 
 Depending on picked setting it is recommended to upsample input 2x or 4x times
diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
index 133f98f165..d10a90859b 100644
--- a/libavfilter/af_alimiter.c
+++ b/libavfilter/af_alimiter.c
@@ -55,6 +55,12 @@ typedef struct AudioLimiterContext {
 int *nextpos;
 double *nextdelta;
 
+int lookahead_delay_samples;
+int lookahead_flush_samples;
+int64_t output_pts;
+int64_t next_output_pts;
+int comp_delay;
+
 double delta;
 int nextiter;
 int nextlen;
@@ -73,6 +79,7 @@ static const AVOption alimiter_options[] = {
 { "asc",   "enable asc",   OFFSET(auto_release), AV_OPT_TYPE_BOOL, 
  {.i64=0},  0,1, AF },
 { "asc_level", "set asc level",OFFSET(asc_coeff),
AV_OPT_TYPE_DOUBLE, {.dbl=0.5},0,1, AF },
 { "level", "auto level",   OFFSET(auto_level),   AV_OPT_TYPE_BOOL, 
  {.i64=1},  0,1, AF },
+{ "comp_delay","compensate delay", OFFSET(comp_delay),   AV_OPT_TYPE_BOOL, 
  {.i64=0},  0,1, AF },
 { NULL }
 };
 
@@ -129,6 +136,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFrame *out;
 double *buf;
 int n, c, i;
+int num_output_samples = in->nb_samples;
+int trim_offset;
 
 if (av_frame_is_writable(in)) {
 out = in;
@@ -271,10 +280,71 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 if (in != out)
 av_frame_free();
+
+if (!s->comp_delay) {
+return ff_filter_frame(outlink, out);
+}
+
+if (s->output_pts == AV_NOPTS_VALUE) {
+s->output_pts = in->pts;
+}
+
+if (s->lookahead_delay_samples > 0) {
+// The current output frame is completely silence
+if (s->lookahead_delay_samples >= in->nb_samples) {
+s->lookahead_delay_samples -= in->nb_samples;
+return 0;
+}
+
+// Trim the silence part
+trim_offset = av_samples_get_buffer_size(
+NULL, inlink->ch_layout.nb_channels, s->lookahead_delay_samples,
+(enum AVSampleFormat)out->format, 1);
+out->data[0] += trim_offset;
+out->nb_samples = in->nb_samples - s->lookahead_delay_samples;
+s->lookahead_delay_samples = 0;
+num_output_samples = out->nb_samples;
+}
+
+if (s->lookahead_delay_samples < 0) {
+return AVERROR_BUG;
+}
+
+out->pts = s->output_pts;
+s->next_output_pts = s->output_pts + num_output_samples;
+s->output_pts = s->next_output_pts;

 return ff_filter_frame(outlink, out);
 }

+static int request_frame(AVFilterLink* outlink)
+{
+AVFilterContext *ctx = outlink->src;
+AudioLimiterContext *s = (AudioLimiterContext*)ctx->priv;
+int ret;
+AVFilterLink *inlink;
+AVFrame *silence_frame;
+
+ret = ff_request_frame(ctx->inputs[0]);
+
+if (ret != AVERROR_EOF || s->lookahead_flush_samples == 0 || 
!s->comp_delay) {
+  // Not necessarily an error, just not EOF.
+  return ret;
+}
+
+// We reach here when input filters have finished producing data (i.e. 
EOF),
+// but because of the attack param, s->buffer still has meaningful
+// audio content that needs flushing.
+inlink = ctx->inputs[0];
+// Pushes silence frame to flush valid audio in the s->buffer
+silence_frame = ff_get_audio_buffer(inlink, s->lookahead_flush_samples);
+ret = filter_frame(inlink, silence_frame);
+if (ret < 0) {
+  return ret;
+}
+return AVERROR_EOF;
+}
+
 static int config_input(AVFilterLink *inlink)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -294,6 +364,9 @@ static int config_input

Re: [FFmpeg-devel] [PATCH] avfilter/alimiter: Add "flush_buffer" option to flush the remaining valid data to the output

2022-04-12 Thread Wang Cao
On Tue, Apr 12, 2022 at 12:40 PM Paul B Mahol  wrote:

> On Mon, Apr 11, 2022 at 10:59 PM Wang Cao <
> wangcao-at-google@ffmpeg.org>
> wrote:
>
> > On Sat, Apr 9, 2022 at 5:35 AM Paul B Mahol  wrote:
> >
> > > On Fri, Apr 8, 2022 at 10:41 PM Wang Cao <
> > wangcao-at-google@ffmpeg.org
> > > >
> > > wrote:
> > >
> > > > On Fri, Apr 8, 2022 at 11:40 AM Paul B Mahol 
> wrote:
> > > >
> > > > > On Thu, Apr 7, 2022 at 11:56 PM Wang Cao <
> > > > wangcao-at-google@ffmpeg.org
> > > > > >
> > > > > wrote:
> > > > >
> > > > > > On Thu, Apr 7, 2022 at 12:44 AM Paul B Mahol 
> > > wrote:
> > > > > >
> > > > > > > On Wed, Apr 6, 2022 at 1:49 PM Paul B Mahol 
> > > > wrote:
> > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > On Tue, Apr 5, 2022 at 8:57 PM Wang Cao <
> > > > > > > wangcao-at-google@ffmpeg.org>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > >> On Mon, Apr 4, 2022 at 3:28 PM Marton Balint  >
> > > > wrote:
> > > > > > > >>
> > > > > > > >> >
> > > > > > > >> >
> > > > > > > >> > On Mon, 4 Apr 2022, Paul B Mahol wrote:
> > > > > > > >> >
> > > > > > > >> > > On Sun, Mar 27, 2022 at 11:41 PM Marton Balint <
> > > c...@passwd.hu
> > > > >
> > > > > > > wrote:
> > > > > > > >> > >
> > > > > > > >> > >>
> > > > > > > >> > >>
> > > > > > > >> > >> On Sat, 26 Mar 2022, Wang Cao wrote:
> > > > > > > >> > >>
> > > > > > > >> > >>> The change in the commit will add some samples to the
> > end
> > > of
> > > > > the
> > > > > > > >> audio
> > > > > > > >> > >>> stream. The intention is to add a "zero_delay" option
> > > > > eventually
> > > > > > > to
> > > > > > > >> not
> > > > > > > >> > >>> have the delay in the begining the output from
> alimiter
> > > due
> > > > to
> > > > > > > >> > >>> lookahead.
> > > > > > > >> > >>
> > > > > > > >> > >> I was very much suprised to see that the alimiter
> filter
> > > > > actually
> > > > > > > >> delays
> > > > > > > >> > >> the audio - as in extra samples are inserted in the
> > > beginning
> > > > > and
> > > > > > > >> some
> > > > > > > >> > >> samples are cut in the end. This trashes A-V sync, so
> it
> > > is a
> > > > > bug
> > > > > > > >> IMHO.
> > > > > > > >> > >>
> > > > > > > >> > >> So unless somebody has some valid usecase for the
> legacy
> > > way
> > > > of
> > > > > > > >> > operation
> > > > > > > >> > >> I'd just simply change it to be "zero delay" without
> any
> > > > > > additional
> > > > > > > >> user
> > > > > > > >> > >> option, in a single patch.
> > > > > > > >> > >>
> > > > > > > >> > >
> > > > > > > >> > >
> > > > > > > >> > > This is done by this patch in very complicated way and
> > also
> > > it
> > > > > > > really
> > > > > > > >> > > should be optional.
> > > > > > > >> >
> > > > > > > >> > But why does it make sense to keep the current (IMHO
> buggy)
> > > > > > > operational
> > > > > > > >> > mode which adds silence in the beginning and trims the
> end?
> > I
> > > &

Re: [FFmpeg-devel] [PATCH] avfilter/alimiter: Add "flush_buffer" option to flush the remaining valid data to the output

2022-04-11 Thread Wang Cao
On Sat, Apr 9, 2022 at 5:35 AM Paul B Mahol  wrote:

> On Fri, Apr 8, 2022 at 10:41 PM Wang Cao  >
> wrote:
>
> > On Fri, Apr 8, 2022 at 11:40 AM Paul B Mahol  wrote:
> >
> > > On Thu, Apr 7, 2022 at 11:56 PM Wang Cao <
> > wangcao-at-google@ffmpeg.org
> > > >
> > > wrote:
> > >
> > > > On Thu, Apr 7, 2022 at 12:44 AM Paul B Mahol 
> wrote:
> > > >
> > > > > On Wed, Apr 6, 2022 at 1:49 PM Paul B Mahol 
> > wrote:
> > > > >
> > > > > >
> > > > > >
> > > > > > On Tue, Apr 5, 2022 at 8:57 PM Wang Cao <
> > > > > wangcao-at-google@ffmpeg.org>
> > > > > > wrote:
> > > > > >
> > > > > >> On Mon, Apr 4, 2022 at 3:28 PM Marton Balint 
> > wrote:
> > > > > >>
> > > > > >> >
> > > > > >> >
> > > > > >> > On Mon, 4 Apr 2022, Paul B Mahol wrote:
> > > > > >> >
> > > > > >> > > On Sun, Mar 27, 2022 at 11:41 PM Marton Balint <
> c...@passwd.hu
> > >
> > > > > wrote:
> > > > > >> > >
> > > > > >> > >>
> > > > > >> > >>
> > > > > >> > >> On Sat, 26 Mar 2022, Wang Cao wrote:
> > > > > >> > >>
> > > > > >> > >>> The change in the commit will add some samples to the end
> of
> > > the
> > > > > >> audio
> > > > > >> > >>> stream. The intention is to add a "zero_delay" option
> > > eventually
> > > > > to
> > > > > >> not
> > > > > >> > >>> have the delay in the begining the output from alimiter
> due
> > to
> > > > > >> > >>> lookahead.
> > > > > >> > >>
> > > > > >> > >> I was very much suprised to see that the alimiter filter
> > > actually
> > > > > >> delays
> > > > > >> > >> the audio - as in extra samples are inserted in the
> beginning
> > > and
> > > > > >> some
> > > > > >> > >> samples are cut in the end. This trashes A-V sync, so it
> is a
> > > bug
> > > > > >> IMHO.
> > > > > >> > >>
> > > > > >> > >> So unless somebody has some valid usecase for the legacy
> way
> > of
> > > > > >> > operation
> > > > > >> > >> I'd just simply change it to be "zero delay" without any
> > > > additional
> > > > > >> user
> > > > > >> > >> option, in a single patch.
> > > > > >> > >>
> > > > > >> > >
> > > > > >> > >
> > > > > >> > > This is done by this patch in very complicated way and also
> it
> > > > > really
> > > > > >> > > should be optional.
> > > > > >> >
> > > > > >> > But why does it make sense to keep the current (IMHO buggy)
> > > > > operational
> > > > > >> > mode which adds silence in the beginning and trims the end? I
> > > > > understand
> > > > > >> > that the original implementation worked like this, but
> > libavfilter
> > > > has
> > > > > >> > packet timestamps and N:M filtering so there is absolutely no
> > > reason
> > > > > to
> > > > > >> > use an 1:1 implementation and live with its limitations.
> > > > > >> >
> > > > > >> Hello Paul and Marton, thank you so much for taking time to
> review
> > > my
> > > > > >> patch.
> > > > > >> I totally understand that my patch may seem a little bit
> > complicated
> > > > > but I
> > > > > >> can
> > > > > >> show with a FATE test that if we set the alimiter to behave as a
> > > > > >> passthrough filter,
> > > > > >> the output frames will be the same from "framecrc" with my
> patch.
> > > The
> > > > > >> existing
> > >

Re: [FFmpeg-devel] [PATCH] avfilter/alimiter: Add "flush_buffer" option to flush the remaining valid data to the output

2022-04-08 Thread Wang Cao
On Fri, Apr 8, 2022 at 11:40 AM Paul B Mahol  wrote:

> On Thu, Apr 7, 2022 at 11:56 PM Wang Cao  >
> wrote:
>
> > On Thu, Apr 7, 2022 at 12:44 AM Paul B Mahol  wrote:
> >
> > > On Wed, Apr 6, 2022 at 1:49 PM Paul B Mahol  wrote:
> > >
> > > >
> > > >
> > > > On Tue, Apr 5, 2022 at 8:57 PM Wang Cao <
> > > wangcao-at-google@ffmpeg.org>
> > > > wrote:
> > > >
> > > >> On Mon, Apr 4, 2022 at 3:28 PM Marton Balint  wrote:
> > > >>
> > > >> >
> > > >> >
> > > >> > On Mon, 4 Apr 2022, Paul B Mahol wrote:
> > > >> >
> > > >> > > On Sun, Mar 27, 2022 at 11:41 PM Marton Balint 
> > > wrote:
> > > >> > >
> > > >> > >>
> > > >> > >>
> > > >> > >> On Sat, 26 Mar 2022, Wang Cao wrote:
> > > >> > >>
> > > >> > >>> The change in the commit will add some samples to the end of
> the
> > > >> audio
> > > >> > >>> stream. The intention is to add a "zero_delay" option
> eventually
> > > to
> > > >> not
> > > >> > >>> have the delay in the begining the output from alimiter due to
> > > >> > >>> lookahead.
> > > >> > >>
> > > >> > >> I was very much suprised to see that the alimiter filter
> actually
> > > >> delays
> > > >> > >> the audio - as in extra samples are inserted in the beginning
> and
> > > >> some
> > > >> > >> samples are cut in the end. This trashes A-V sync, so it is a
> bug
> > > >> IMHO.
> > > >> > >>
> > > >> > >> So unless somebody has some valid usecase for the legacy way of
> > > >> > operation
> > > >> > >> I'd just simply change it to be "zero delay" without any
> > additional
> > > >> user
> > > >> > >> option, in a single patch.
> > > >> > >>
> > > >> > >
> > > >> > >
> > > >> > > This is done by this patch in very complicated way and also it
> > > really
> > > >> > > should be optional.
> > > >> >
> > > >> > But why does it make sense to keep the current (IMHO buggy)
> > > operational
> > > >> > mode which adds silence in the beginning and trims the end? I
> > > understand
> > > >> > that the original implementation worked like this, but libavfilter
> > has
> > > >> > packet timestamps and N:M filtering so there is absolutely no
> reason
> > > to
> > > >> > use an 1:1 implementation and live with its limitations.
> > > >> >
> > > >> Hello Paul and Marton, thank you so much for taking time to review
> my
> > > >> patch.
> > > >> I totally understand that my patch may seem a little bit complicated
> > > but I
> > > >> can
> > > >> show with a FATE test that if we set the alimiter to behave as a
> > > >> passthrough filter,
> > > >> the output frames will be the same from "framecrc" with my patch.
> The
> > > >> existing
> > > >> behavior will not work for all gapless audio processing.
> > > >>
> > > >> The complete patch to fix this issue is at
> > > >>
> > > >>
> > >
> >
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220330210314.2055201-1-wang...@google.com/
> > > >>
> > > >> Regarding Paul's concern, I personally don't have any preference
> > whether
> > > >> to
> > > >> put
> > > >> the patch as an extra option or not. With respect to the
> > implementation,
> > > >> the patch
> > > >> is the best I can think of by preserving as much information as
> > possible
> > > >> from input
> > > >> frames. I also understand it may break concept that "filter_frame"
> > > outputs
> > > >> one frame
> > > >> at a time. For alimiter with my patch, depending on the size of the
> > > >> lookahead buffer,
> > > >> it may take a few frames before one output fr

Re: [FFmpeg-devel] [PATCH] avfilter/alimiter: Add "flush_buffer" option to flush the remaining valid data to the output

2022-04-07 Thread Wang Cao
On Thu, Apr 7, 2022 at 12:44 AM Paul B Mahol  wrote:

> On Wed, Apr 6, 2022 at 1:49 PM Paul B Mahol  wrote:
>
> >
> >
> > On Tue, Apr 5, 2022 at 8:57 PM Wang Cao <
> wangcao-at-google@ffmpeg.org>
> > wrote:
> >
> >> On Mon, Apr 4, 2022 at 3:28 PM Marton Balint  wrote:
> >>
> >> >
> >> >
> >> > On Mon, 4 Apr 2022, Paul B Mahol wrote:
> >> >
> >> > > On Sun, Mar 27, 2022 at 11:41 PM Marton Balint 
> wrote:
> >> > >
> >> > >>
> >> > >>
> >> > >> On Sat, 26 Mar 2022, Wang Cao wrote:
> >> > >>
> >> > >>> The change in the commit will add some samples to the end of the
> >> audio
> >> > >>> stream. The intention is to add a "zero_delay" option eventually
> to
> >> not
> >> > >>> have the delay in the begining the output from alimiter due to
> >> > >>> lookahead.
> >> > >>
> >> > >> I was very much suprised to see that the alimiter filter actually
> >> delays
> >> > >> the audio - as in extra samples are inserted in the beginning and
> >> some
> >> > >> samples are cut in the end. This trashes A-V sync, so it is a bug
> >> IMHO.
> >> > >>
> >> > >> So unless somebody has some valid usecase for the legacy way of
> >> > operation
> >> > >> I'd just simply change it to be "zero delay" without any additional
> >> user
> >> > >> option, in a single patch.
> >> > >>
> >> > >
> >> > >
> >> > > This is done by this patch in very complicated way and also it
> really
> >> > > should be optional.
> >> >
> >> > But why does it make sense to keep the current (IMHO buggy)
> operational
> >> > mode which adds silence in the beginning and trims the end? I
> understand
> >> > that the original implementation worked like this, but libavfilter has
> >> > packet timestamps and N:M filtering so there is absolutely no reason
> to
> >> > use an 1:1 implementation and live with its limitations.
> >> >
> >> Hello Paul and Marton, thank you so much for taking time to review my
> >> patch.
> >> I totally understand that my patch may seem a little bit complicated
> but I
> >> can
> >> show with a FATE test that if we set the alimiter to behave as a
> >> passthrough filter,
> >> the output frames will be the same from "framecrc" with my patch. The
> >> existing
> >> behavior will not work for all gapless audio processing.
> >>
> >> The complete patch to fix this issue is at
> >>
> >>
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220330210314.2055201-1-wang...@google.com/
> >>
> >> Regarding Paul's concern, I personally don't have any preference whether
> >> to
> >> put
> >> the patch as an extra option or not. With respect to the implementation,
> >> the patch
> >> is the best I can think of by preserving as much information as possible
> >> from input
> >> frames. I also understand it may break concept that "filter_frame"
> outputs
> >> one frame
> >> at a time. For alimiter with my patch, depending on the size of the
> >> lookahead buffer,
> >> it may take a few frames before one output frame can be generated. This
> is
> >> inevitable
> >> to compensate for the delay of the lookahead buffer.
> >>
> >> Thanks again for reviewing my patch and I'm looking forward to hearing
> >> from
> >> you :)
> >>
> >
> > Better than (because its no more 1 frame X nb_samples in, 1 frame X
> > nb_samples out) to replace .filter_frame/.request_frame with .activate
> > logic.
> >
> > And make this output delay compensation filtering optional.
> >
> > In this process make sure that output PTS frame timestamps are unchanged
> > from input one, by keeping reference of needed frames in filter queue.
> >
> > Look how speechnorm/dynaudnorm does it.
> >
>
>
> Alternatively, use current logic in ladspa filter, (also add option with
> same name).
>
> This would need less code, and probably better approach, as there is no
> extra latency introduced.
>
> Than mapping 1:1 between same number of samples per frame is not hold any
> more

Re: [FFmpeg-devel] [PATCH] avfilter/alimiter: Add "flush_buffer" option to flush the remaining valid data to the output

2022-04-05 Thread Wang Cao
On Mon, Apr 4, 2022 at 3:28 PM Marton Balint  wrote:

>
>
> On Mon, 4 Apr 2022, Paul B Mahol wrote:
>
> > On Sun, Mar 27, 2022 at 11:41 PM Marton Balint  wrote:
> >
> >>
> >>
> >> On Sat, 26 Mar 2022, Wang Cao wrote:
> >>
> >>> The change in the commit will add some samples to the end of the audio
> >>> stream. The intention is to add a "zero_delay" option eventually to not
> >>> have the delay in the begining the output from alimiter due to
> >>> lookahead.
> >>
> >> I was very much suprised to see that the alimiter filter actually delays
> >> the audio - as in extra samples are inserted in the beginning and some
> >> samples are cut in the end. This trashes A-V sync, so it is a bug IMHO.
> >>
> >> So unless somebody has some valid usecase for the legacy way of
> operation
> >> I'd just simply change it to be "zero delay" without any additional user
> >> option, in a single patch.
> >>
> >
> >
> > This is done by this patch in very complicated way and also it really
> > should be optional.
>
> But why does it make sense to keep the current (IMHO buggy) operational
> mode which adds silence in the beginning and trims the end? I understand
> that the original implementation worked like this, but libavfilter has
> packet timestamps and N:M filtering so there is absolutely no reason to
> use an 1:1 implementation and live with its limitations.
>
Hello Paul and Marton, thank you so much for taking time to review my
patch.
I totally understand that my patch may seem a little bit complicated but I
can
show with a FATE test that if we set the alimiter to behave as a
passthrough filter,
the output frames will be the same from "framecrc" with my patch. The
existing
behavior will not work for all gapless audio processing.

The complete patch to fix this issue is at
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220330210314.2055201-1-wang...@google.com/

Regarding Paul's concern, I personally don't have any preference whether to
put
the patch as an extra option or not. With respect to the implementation,
the patch
is the best I can think of by preserving as much information as possible
from input
frames. I also understand it may break concept that "filter_frame" outputs
one frame
at a time. For alimiter with my patch, depending on the size of the
lookahead buffer,
it may take a few frames before one output frame can be generated. This is
inevitable
to compensate for the delay of the lookahead buffer.

Thanks again for reviewing my patch and I'm looking forward to hearing from
you :)
-- 

Wang Cao |  Software Engineer |  wang...@google.com |  650-203-7807
<(650)%20203-7807>
___
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] avfilter/alimiter: Remove the delay introduced by lookahead buffer

2022-03-30 Thread Wang Cao
The change essentially removes the delay introduces by lookahead buffer.
The valid audio data in the internal buffer is also flushed to ensure
the integrity of output.

Signed-off-by: Wang Cao 
---
 doc/filters.texi   |   2 -
 libavfilter/af_alimiter.c  |  97 +-
 tests/ref/fate/filter-alimiter | 518 -
 3 files changed, 344 insertions(+), 273 deletions(-)

Thanks a lot for your time to review my patch. I have made "zero_delay"
option to default. Now the output samples will only be written after the
lookahead buffer is full. We also uses "request_frame" to flush the
internal buffers so that all valid input audio samples are written.

diff --git a/doc/filters.texi b/doc/filters.texi
index d70ac3e237..5d1adf88e1 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1943,8 +1943,6 @@ aiir=z=1.3057 0 0 0:p=1.3057 2.3892 2.1860 1:f=sf:r=d
 
 The limiter prevents an input signal from rising over a desired threshold.
 This limiter uses lookahead technology to prevent your signal from distorting.
-It means that there is a small delay after the signal is processed. Keep in 
mind
-that the delay it produces is the attack time you set.
 
 The filter accepts the following options:
 
diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
index 133f98f165..e1fcf98574 100644
--- a/libavfilter/af_alimiter.c
+++ b/libavfilter/af_alimiter.c
@@ -30,6 +30,7 @@
 
 #include "audio.h"
 #include "avfilter.h"
+#include "bufferqueue.h"
 #include "formats.h"
 #include "internal.h"
 
@@ -55,6 +56,13 @@ typedef struct AudioLimiterContext {
 int *nextpos;
 double *nextdelta;
 
+int total_samples_to_flush;
+int lookahead_buffer_full;
+
+struct FFBufQueue output_frame_queue;
+int output_sample_pos;
+int output_frame_pos;
+
 double delta;
 int nextiter;
 int nextlen;
@@ -129,6 +137,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFrame *out;
 double *buf;
 int n, c, i;
+int can_free_input_frame = 0;
+double peak = 0;
 
 if (av_frame_is_writable(in)) {
 out = in;
@@ -138,12 +148,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 av_frame_free();
 return AVERROR(ENOMEM);
 }
+can_free_input_frame = 1;
 av_frame_copy_props(out, in);
 }
-dst = (double *)out->data[0];
+
+if (ff_bufqueue_is_full(>output_frame_queue)) {
+// In the runtime, the total number of frames in the queue is bounded 
by
+// attack_time, sample rate and frame size.
+return AVERROR_BUG;
+}
+
+ff_bufqueue_add(ctx, >output_frame_queue, out);
 
 for (n = 0; n < in->nb_samples; n++) {
-double peak = 0;
+out = ff_bufqueue_peek(>output_frame_queue, s->output_frame_pos);
+dst = (double *)out->data[0];
+dst += s->output_sample_pos * channels;
+peak = 0;
 
 for (c = 0; c < channels; c++) {
 double sample = src[c] * level_in;
@@ -213,8 +234,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 s->att += s->delta;
 
-for (c = 0; c < channels; c++)
-dst[c] = buf[c] * s->att;
+// Checks lookahead buffer (s->buffer) has been filled
+if (!s->lookahead_buffer_full && (s->pos + channels) % buffer_size == 
0) {
+s->lookahead_buffer_full = 1;
+}
+if (s->lookahead_buffer_full) {
+for (c = 0; c < channels; c++) {
+dst[c] = buf[c] * s->att;
+dst[c] = av_clipd(dst[c], -limit, limit) * level * level_out;
+}
+s->output_sample_pos++;
+if (s->output_sample_pos == out->nb_samples) {
+s->output_frame_pos++;
+s->output_sample_pos = 0;
+}
+}
 
 if ((s->pos + channels) % buffer_size == nextpos[s->nextiter]) {
 if (s->auto_release) {
@@ -261,18 +295,55 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 if (s->delta != 0. && fabs(s->delta) < 0.01)
 s->delta = 0.;
 
-for (c = 0; c < channels; c++)
-dst[c] = av_clipd(dst[c], -limit, limit) * level * level_out;
-
 s->pos = (s->pos + channels) % buffer_size;
 src += channels;
-dst += channels;
 }
-
-if (in != out)
+if (can_free_input_frame) {
 av_frame_free();
+}
 
-return ff_filter_frame(outlink, out);
+if (s->output_frame_pos > 0) {
+s->output_frame_pos--;
+out = ff_bufqueue_get(>output_frame_queue);
+return ff_filter_frame(outlink, out);
+}
+return 0;
+}
+
+static int request_frame(AVFilterLink* outlink) 
+{
+AVFilterContext *ctx = out

[FFmpeg-devel] [PATCH] avfilter/alimiter: Add "flush_buffer" option to flush the remaining valid data to the output

2022-03-27 Thread Wang Cao
The change in the commit will add some samples to the end of the audio
stream. The intention is to add a "zero_delay" option eventually to not
have the delay in the begining the output from alimiter due to
lookahead.

Signed-off-by: Wang Cao 
---
 doc/filters.texi  |  5 
 libavfilter/af_alimiter.c | 57 ---
 2 files changed, 53 insertions(+), 9 deletions(-)

If the intention is clear to you, do you prefer us add the "zero_delay"
option to the same patch or it needs to go in a separate patch? Thanks!

diff --git a/doc/filters.texi b/doc/filters.texi
index d70ac3e237..bb8f7c1a0b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1978,6 +1978,11 @@ in release time while 1 produces higher release times.
 @item level
 Auto level output signal. Default is enabled.
 This normalizes audio back to 0dB if enabled.
+
+@item flush_buffer
+Flushes the internal buffer so that all the input audio samples to the limiter 
+will appear to the output. Currently due to lookahead buffer, the total number 
+of output samples will be larger than the input.
 @end table
 
 Depending on picked setting it is recommended to upsample input 2x or 4x times
diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
index 133f98f165..ba0a1361ac 100644
--- a/libavfilter/af_alimiter.c
+++ b/libavfilter/af_alimiter.c
@@ -55,6 +55,9 @@ typedef struct AudioLimiterContext {
 int *nextpos;
 double *nextdelta;
 
+int flush_buffer;
+int total_samples_to_flush;
+
 double delta;
 int nextiter;
 int nextlen;
@@ -65,14 +68,15 @@ typedef struct AudioLimiterContext {
 #define AF AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | 
AV_OPT_FLAG_RUNTIME_PARAM
 
 static const AVOption alimiter_options[] = {
-{ "level_in",  "set input level",  OFFSET(level_in), 
AV_OPT_TYPE_DOUBLE, {.dbl=1},.015625,   64, AF },
-{ "level_out", "set output level", OFFSET(level_out),
AV_OPT_TYPE_DOUBLE, {.dbl=1},.015625,   64, AF },
-{ "limit", "set limit",OFFSET(limit),
AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.0625,1, AF },
-{ "attack","set attack",   OFFSET(attack),   
AV_OPT_TYPE_DOUBLE, {.dbl=5},0.1,   80, AF },
-{ "release",   "set release",  OFFSET(release),  
AV_OPT_TYPE_DOUBLE, {.dbl=50}, 1, 8000, AF },
-{ "asc",   "enable asc",   OFFSET(auto_release), AV_OPT_TYPE_BOOL, 
  {.i64=0},  0,1, AF },
-{ "asc_level", "set asc level",OFFSET(asc_coeff),
AV_OPT_TYPE_DOUBLE, {.dbl=0.5},0,1, AF },
-{ "level", "auto level",   OFFSET(auto_level),   AV_OPT_TYPE_BOOL, 
  {.i64=1},  0,1, AF },
+{ "level_in",  "set input level",  
OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1},.015625,   64, AF },
+{ "level_out", "set output level", 
OFFSET(level_out),AV_OPT_TYPE_DOUBLE, {.dbl=1},.015625,   64, AF },
+{ "limit", "set limit",
OFFSET(limit),AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.0625,1, AF },
+{ "attack","set attack",   
OFFSET(attack),   AV_OPT_TYPE_DOUBLE, {.dbl=5},0.1,   80, AF },
+{ "release",   "set release",  
OFFSET(release),  AV_OPT_TYPE_DOUBLE, {.dbl=50}, 1, 8000, AF },
+{ "asc",   "enable asc",   
OFFSET(auto_release), AV_OPT_TYPE_BOOL,   {.i64=0},  0,1, AF },
+{ "asc_level", "set asc level",
OFFSET(asc_coeff),AV_OPT_TYPE_DOUBLE, {.dbl=0.5},0,1, AF },
+{ "level", "auto level",   
OFFSET(auto_level),   AV_OPT_TYPE_BOOL,   {.i64=1},  0,1, AF },
+{ "flush_buffer","flush the samples in the lookahead buffer",  
OFFSET(flush_buffer),   AV_OPT_TYPE_BOOL, {.i64=0},  0,1, AF },
 { NULL }
 };
 
@@ -275,6 +279,39 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 return ff_filter_frame(outlink, out);
 }
 
+
+static int request_frame(AVFilterLink* outlink) {
+  AVFilterContext* ctx = outlink->src;
+  AudioLimiterContext* s = (AudioLimiterContext*)ctx->priv;
+  int ret;
+  AVFilterLink *inlink;
+  AVFrame *silence_frame;
+
+  ret = ff_request_frame(ctx->inputs[0]);
+
+  if (!s->flush_buffer) {
+  return 0;
+  }
+
+  if (ret != AVERROR_EOF || s->total_samples_to_flush) {
+// Not necessarily an error, just not EOF.s
+return ret;
+  }
+
+  // We reach here when input filters have finished producing data (i.e. E

[FFmpeg-devel] [PATCH v2 1/2] libavcodec/libaomenc.c: Add command-line options for tx tools.

2020-07-22 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 20 
 libavcodec/libaomenc.c | 30 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 23542c8a62..ecdfacbd69 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1629,6 +1629,26 @@ Enable paeth predictor in intra prediction. Default is 
true.
 @item enable-palette (@emph{boolean}) (Requires libaom >= v2.0.0)
 Enable palette prediction mode. Default is true.
 
+@item enable-flip-idtx (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable extended transform type, including FLIPADST_DCT, DCT_FLIPADST,
+FLIPADST_FLIPADST, ADST_FLIPADST, FLIPADST_ADST, IDTX, V_DCT, H_DCT,
+V_ADST, H_ADST, V_FLIPADST, H_FLIPADST. Default is true.
+
+@item enable-tx64 (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable 64-pt transform. Default is true.
+
+@item reduced-tx-type-set (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use reduced set of transform types. Default is false.
+
+@item use-intra-dct-only (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use DCT only for INTRA modes. Default is false.
+
+@item use-inter-dct-only (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use DCT only for INTER modes. Default is false.
+
+@item use-intra-default-tx-only (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use Default-transform only for INTRA modes. Default is false.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index b65e491824..d731f566d2 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -106,6 +106,12 @@ typedef struct AOMEncoderContext {
 int enable_intra_edge_filter;
 int enable_palette;
 int enable_filter_intra;
+int enable_flip_idtx;
+int enable_tx64;
+int reduced_tx_type_set;
+int use_intra_dct_only;
+int use_inter_dct_only;
+int use_intra_default_tx_only;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -156,6 +162,12 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_PAETH_INTRA]   = "AV1E_SET_ENABLE_PAETH_INTRA",
 [AV1E_SET_ENABLE_SMOOTH_INTRA]  = "AV1E_SET_ENABLE_SMOOTH_INTRA",
 [AV1E_SET_ENABLE_PALETTE]   = "AV1E_SET_ENABLE_PALETTE",
+[AV1E_SET_ENABLE_FLIP_IDTX]  = "AV1E_SET_ENABLE_FLIP_IDTX",
+[AV1E_SET_ENABLE_TX64]   = "AV1E_SET_ENABLE_TX64",
+[AV1E_SET_INTRA_DCT_ONLY]= "AV1E_SET_INTRA_DCT_ONLY",
+[AV1E_SET_INTER_DCT_ONLY]= "AV1E_SET_INTER_DCT_ONLY",
+[AV1E_SET_INTRA_DEFAULT_TX_ONLY] = "AV1E_SET_INTRA_DEFAULT_TX_ONLY",
+[AV1E_SET_REDUCED_TX_TYPE_SET]   = "AV1E_SET_REDUCED_TX_TYPE_SET",
 #endif
 };
 
@@ -740,6 +752,18 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA, 
ctx->enable_smooth_intra);
 if (ctx->enable_palette >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_PALETTE, ctx->enable_palette);
+if (ctx->enable_tx64 >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_TX64, ctx->enable_tx64);
+if (ctx->enable_flip_idtx >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_FLIP_IDTX, ctx->enable_flip_idtx);
+if (ctx->use_intra_dct_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTRA_DCT_ONLY, ctx->use_intra_dct_only);
+if (ctx->use_inter_dct_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTER_DCT_ONLY, ctx->use_inter_dct_only);
+if (ctx->use_intra_default_tx_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY, 
ctx->use_intra_default_tx_only);
+if (ctx->reduced_tx_type_set >= 0)
+codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET, 
ctx->reduced_tx_type_set);
 #endif
 
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
@@ -1171,6 +1195,12 @@ static const AVOption options[] = {
 { "enable-smooth-intra",  "Enable smooth intra prediction mode",   
 OFFSET(enable_smooth_intra),  AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 
1, VE},
 { "enable-paeth-intra",   "Enable paeth predictor in intra 
prediction", OFFSET(enable_paeth_intra),   AV_OPT_TYPE_BOOL, {.i64 
= -1}, -1, 1, VE},
 { "enable-palette",   "Enable palette prediction mode",
 OFFSET(enable_palette),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 
1, VE},
+{ "enable-flip-idtx",  "Enable extended transform type",   
  OFFSET(enable_flip_idtx),  AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+{ "enable-tx64",   "Enable 64-pt transform",   
  OFFSET(enable_tx64),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -

[FFmpeg-devel] [PATCH v2 2/2] libavcodec/libaomenc.c: Add command-line options for inter-coding tools

2020-07-22 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 36 +
 libavcodec/libaomenc.c | 60 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index ecdfacbd69..ed8ef63784 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1649,6 +1649,42 @@ Use DCT only for INTER modes. Default is false.
 @item use-intra-default-tx-only (@emph{boolean}) (Requires libaom >= v2.0.0)
 Use Default-transform only for INTRA modes. Default is false.
 
+@item enable-ref-frame-mvs (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable temporal mv prediction. Default is true.
+
+@item enable-reduced-reference-set (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use reduced set of single and compound references. Default is false.
+
+@item enable-obmc (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable obmc. Default is true.
+
+@item enable-dual-filter (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable dual filter. Default is true.
+
+@item enable-diff-wtd-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable difference-weighted compound. Default is true.
+
+@item enable-dist-wtd-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable distance-weighted compound. Default is true.
+
+@item enable-onesided-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable one sided compound. Default is true.
+
+@item enable-interinter-wedge (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable interinter wedge compound. Default is true.
+
+@item enable-interintra-wedge (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable interintra wedge compound. Default is true.
+
+@item enable-masked-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable masked compound. Default is true.
+
+@item enable-interintra-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable interintra compound. Default is true.
+
+@item enable-smooth-interintra (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable smooth interintra mode. Default is true.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index d731f566d2..18afa20a2e 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -112,6 +112,18 @@ typedef struct AOMEncoderContext {
 int use_intra_dct_only;
 int use_inter_dct_only;
 int use_intra_default_tx_only;
+int enable_ref_frame_mvs;
+int enable_interinter_wedge;
+int enable_interintra_wedge;
+int enable_interintra_comp;
+int enable_masked_comp;
+int enable_obmc;
+int enable_onesided_comp;
+int enable_reduced_reference_set;
+int enable_smooth_interintra;
+int enable_diff_wtd_comp;
+int enable_dist_wtd_comp;
+int enable_dual_filter;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -168,6 +180,18 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_INTER_DCT_ONLY]= "AV1E_SET_INTER_DCT_ONLY",
 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] = "AV1E_SET_INTRA_DEFAULT_TX_ONLY",
 [AV1E_SET_REDUCED_TX_TYPE_SET]   = "AV1E_SET_REDUCED_TX_TYPE_SET",
+[AV1E_SET_ENABLE_DIFF_WTD_COMP] = "AV1E_SET_ENABLE_DIFF_WTD_COMP",
+[AV1E_SET_ENABLE_DIST_WTD_COMP] = "AV1E_SET_ENABLE_DIST_WTD_COMP",
+[AV1E_SET_ENABLE_DUAL_FILTER]   = "AV1E_SET_ENABLE_DUAL_FILTER",
+[AV1E_SET_ENABLE_INTERINTER_WEDGE]  = "AV1E_SET_ENABLE_INTERINTER_WEDGE",
+[AV1E_SET_ENABLE_INTERINTRA_WEDGE]  = "AV1E_SET_ENABLE_INTERINTRA_WEDGE",
+[AV1E_SET_ENABLE_MASKED_COMP]   = "AV1E_SET_ENABLE_MASKED_COMP",
+[AV1E_SET_ENABLE_INTERINTRA_COMP]   = "AV1E_SET_ENABLE_INTERINTRA_COMP",
+[AV1E_SET_ENABLE_OBMC]  = "AV1E_SET_ENABLE_OBMC",
+[AV1E_SET_ENABLE_ONESIDED_COMP] = "AV1E_SET_ENABLE_ONESIDED_COMP",
+[AV1E_SET_REDUCED_REFERENCE_SET]= "AV1E_SET_REDUCED_REFERENCE_SET",
+[AV1E_SET_ENABLE_SMOOTH_INTERINTRA] = "AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
+[AV1E_SET_ENABLE_REF_FRAME_MVS] = "AV1E_SET_ENABLE_REF_FRAME_MVS",
 #endif
 };
 
@@ -764,6 +788,30 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY, 
ctx->use_intra_default_tx_only);
 if (ctx->reduced_tx_type_set >= 0)
 codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET, 
ctx->reduced_tx_type_set);
+if (ctx->enable_ref_frame_mvs >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_REF_FRAME_MVS, 
ctx->enable_ref_frame_mvs);
+if (ctx->enable_reduced_reference_set >= 0)
+codecctl_int(avctx, AV1E_SET_REDUCED_REFERENCE_SET, 
ctx->enable_reduced_reference_set);
+if (ctx->enable_diff_wtd_comp >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_DIFF_WTD_COMP, 
ctx->enable_diff_wtd_comp

Re: [FFmpeg-devel] [PATCH 1/2] fftools/ffmpeg.c: Use the streams from the first output in print_final_stats.

2020-07-17 Thread Wang Cao
Hi,

I am wondering if this is a change that would make unpredictable impact on
the stats report for ffmpeg. If this is the case, can you take a look at my
next patch in the series? It adds an option to print stats for each output
file when enabled. Thank you!

Best,
Wang
___
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 2/2] libavcodec/libaomenc.c: Add command-line options for inter-coding tools

2020-07-14 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 36 +
 libavcodec/libaomenc.c | 60 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e6ef401a9a..1a4dbedff3 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1649,6 +1649,42 @@ Use DCT only for INTER modes. Default is false.
 @item use-intra-default-tx-only (@emph{boolean}) (Requires libaom >= v2.0.0)
 Use Default-transform only for INTRA modes. Default is false.
 
+@item enable-ref-frame-mvs (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable temporal mv prediction. Default is true.
+
+@item enable-reduced-reference-set (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use reduced set of single and compound references. Default is false.
+
+@item enable-obmc (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable obmc. Default is true.
+
+@item enable-dual-filter (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable dual filter. Default is true.
+
+@item enable-diff-wtd-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable difference-weighted compound. Default is true.
+
+@item enable-dist-wtd-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable distance-weighted compound. Default is true.
+
+@item enable-onesided-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable one sided compound. Default is true.
+
+@item enable-interinter-wedge (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable interinter wedge compound. Default is true.
+
+@item enable-interintra-wedge (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable interintra wedge compound. Default is true.
+
+@item enable-masked-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable masked compound. Default is true.
+
+@item enable-interintra-comp (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable interintra compound. Default is true.
+
+@item enable-smooth-interintra (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable smooth interintra mode. Default is true.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index b01e6c7283..745acc7d94 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -112,6 +112,18 @@ typedef struct AOMEncoderContext {
 int use_intra_dct_only;
 int use_inter_dct_only;
 int use_intra_default_tx_only;
+int enable_ref_frame_mvs;
+int enable_interinter_wedge;
+int enable_interintra_wedge;
+int enable_interintra_comp;
+int enable_masked_comp;
+int enable_obmc;
+int enable_onesided_comp;
+int enable_reduced_reference_set;
+int enable_smooth_interintra;
+int enable_diff_wtd_comp;
+int enable_dist_wtd_comp;
+int enable_dual_filter;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -168,6 +180,18 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_INTER_DCT_ONLY]= "AV1E_SET_INTER_DCT_ONLY",
 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] = "AV1E_SET_INTRA_DEFAULT_TX_ONLY",
 [AV1E_SET_REDUCED_TX_TYPE_SET]   = "AV1E_SET_REDUCED_TX_TYPE_SET",
+[AV1E_SET_ENABLE_DIFF_WTD_COMP] = "AV1E_SET_ENABLE_DIFF_WTD_COMP",
+[AV1E_SET_ENABLE_DIST_WTD_COMP] = "AV1E_SET_ENABLE_DIST_WTD_COMP",
+[AV1E_SET_ENABLE_DUAL_FILTER]   = "AV1E_SET_ENABLE_DUAL_FILTER",
+[AV1E_SET_ENABLE_INTERINTER_WEDGE]  = "AV1E_SET_ENABLE_INTERINTER_WEDGE",
+[AV1E_SET_ENABLE_INTERINTRA_WEDGE]  = "AV1E_SET_ENABLE_INTERINTRA_WEDGE",
+[AV1E_SET_ENABLE_MASKED_COMP]   = "AV1E_SET_ENABLE_MASKED_COMP",
+[AV1E_SET_ENABLE_INTERINTRA_COMP]   = "AV1E_SET_ENABLE_INTERINTRA_COMP",
+[AV1E_SET_ENABLE_OBMC]  = "AV1E_SET_ENABLE_OBMC",
+[AV1E_SET_ENABLE_ONESIDED_COMP] = "AV1E_SET_ENABLE_ONESIDED_COMP",
+[AV1E_SET_REDUCED_REFERENCE_SET]= "AV1E_SET_REDUCED_REFERENCE_SET",
+[AV1E_SET_ENABLE_SMOOTH_INTERINTRA] = "AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
+[AV1E_SET_ENABLE_REF_FRAME_MVS] = "AV1E_SET_ENABLE_REF_FRAME_MVS",
 #endif
 };
 
@@ -765,6 +789,30 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY, 
ctx->use_intra_default_tx_only);
 if (ctx->reduced_tx_type_set >= 0)
 codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET, 
ctx->reduced_tx_type_set);
+if (ctx->enable_ref_frame_mvs >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_REF_FRAME_MVS, 
ctx->enable_ref_frame_mvs);
+if (ctx->enable_reduced_reference_set >= 0)
+codecctl_int(avctx, AV1E_SET_REDUCED_REFERENCE_SET, 
ctx->enable_reduced_reference_set);
+if (ctx->enable_diff_wtd_comp >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_DIFF_WTD_COMP, 
ctx->enable_diff_wtd_comp

[FFmpeg-devel] [PATCH v2 1/2] libavcodec/libaomenc.c: Add command-line options for tx tools.

2020-07-14 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 20 
 libavcodec/libaomenc.c | 32 
 libavcodec/version.h   |  2 +-
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 5406d20c00..e6ef401a9a 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1629,6 +1629,26 @@ Enable paeth predictor in intra prediction. Default is 
true.
 @item enable-palette (@emph{boolean}) (Requires libaom >= v2.0.0)
 Enable palette prediction mode. Default is true.
 
+@item enable-flip-idtx (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable extended transform type, including FLIPADST_DCT, DCT_FLIPADST,
+FLIPADST_FLIPADST, ADST_FLIPADST, FLIPADST_ADST, IDTX, V_DCT, H_DCT,
+V_ADST, H_ADST, V_FLIPADST, H_FLIPADST. Default is true.
+
+@item enable-tx64 (@emph{boolean}) (Requires libaom >= v2.0.0)
+Enable 64-pt transform. Default is true.
+
+@item reduced-tx-type-set (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use reduced set of transform types. Default is false.
+
+@item use-intra-dct-only (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use DCT only for INTRA modes. Default is false.
+
+@item use-inter-dct-only (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use DCT only for INTER modes. Default is false.
+
+@item use-intra-default-tx-only (@emph{boolean}) (Requires libaom >= v2.0.0)
+Use Default-transform only for INTRA modes. Default is false.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 2ecb3de3a7..b01e6c7283 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -106,6 +106,12 @@ typedef struct AOMEncoderContext {
 int enable_intra_edge_filter;
 int enable_palette;
 int enable_filter_intra;
+int enable_flip_idtx;
+int enable_tx64;
+int reduced_tx_type_set;
+int use_intra_dct_only;
+int use_inter_dct_only;
+int use_intra_default_tx_only;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -156,6 +162,12 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_PAETH_INTRA]   = "AV1E_SET_ENABLE_PAETH_INTRA",
 [AV1E_SET_ENABLE_SMOOTH_INTRA]  = "AV1E_SET_ENABLE_SMOOTH_INTRA",
 [AV1E_SET_ENABLE_PALETTE]   = "AV1E_SET_ENABLE_PALETTE",
+[AV1E_SET_ENABLE_FLIP_IDTX]  = "AV1E_SET_ENABLE_FLIP_IDTX",
+[AV1E_SET_ENABLE_TX64]   = "AV1E_SET_ENABLE_TX64",
+[AV1E_SET_INTRA_DCT_ONLY]= "AV1E_SET_INTRA_DCT_ONLY",
+[AV1E_SET_INTER_DCT_ONLY]= "AV1E_SET_INTER_DCT_ONLY",
+[AV1E_SET_INTRA_DEFAULT_TX_ONLY] = "AV1E_SET_INTRA_DEFAULT_TX_ONLY",
+[AV1E_SET_REDUCED_TX_TYPE_SET]   = "AV1E_SET_REDUCED_TX_TYPE_SET",
 #endif
 };
 
@@ -741,6 +753,18 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA, 
ctx->enable_smooth_intra);
 if (ctx->enable_palette >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_PALETTE, ctx->enable_palette);
+if (ctx->enable_tx64 >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_TX64, ctx->enable_tx64);
+if (ctx->enable_flip_idtx >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_FLIP_IDTX, ctx->enable_flip_idtx);
+if (ctx->use_intra_dct_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTRA_DCT_ONLY, ctx->use_intra_dct_only);
+if (ctx->use_inter_dct_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTER_DCT_ONLY, ctx->use_inter_dct_only);
+if (ctx->use_intra_default_tx_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY, 
ctx->use_intra_default_tx_only);
+if (ctx->reduced_tx_type_set >= 0)
+codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET, 
ctx->reduced_tx_type_set);
 #endif
 
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
@@ -1152,6 +1176,7 @@ static const AVOption options[] = {
 { "psnr",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
 { "ssim",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
 FF_AV1_PROFILE_OPTS
+#if AOM_ENCODER_ABI_VERSION >= 22
 { "enable-rect-partitions", "Enable rectangular partitions", 
OFFSET(enable_rect_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-1to4-partitions", "Enable 1:4/4:1 partitions", 
OFFSET(enable_1to4_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-ab-partitions",   "Enable ab shape partitions",
OFFSET(enable_ab_partitions),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
@@ -1162,6 +1187,13 @@ static const AVOption options[] = {
 { "enable-smooth-intra",  "Enable smooth in

Re: [FFmpeg-devel] [PATCH 1/2] fftools/ffmpeg.c: Use the streams from the first output in print_final_stats.

2020-07-07 Thread Wang Cao
Friendly ping here. Is there something I need to change for this patch set?
Any comments are welcome. Thank you!
___
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] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-06-30 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 36 +
 libavcodec/libaomenc.c | 46 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 17a0f4c821..80052763db 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1599,6 +1599,42 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item superres-mode (@emph{mode})
+Select super-resolution mode.
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed.
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved.
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index.
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames.
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}.
+Valid value ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames when
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode}
+is @option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index fe98449fa1..83ccf07fab 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -23,6 +23,7 @@
  * AV1 encoder support via libaom
  */
 
+#include 
 #define AOM_DISABLE_CTRL_TYPECHECKS 1
 #include 
 #include 
@@ -96,6 +97,11 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -135,6 +141,7 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -204,6 +211,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",   cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:",cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -546,6 +560,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 8)
+enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 8)
+enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -688,6 +713,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 // codec control failures are currently treated only as warnings
 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+if (ctx->superres_mode > 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, 1);
 if (ctx->auto_alt_ref >= 0)
 codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
 if (ctx->arnr_max

[FFmpeg-devel] [PATCH v3] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-06-29 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
Check libaom ABI version to use SUPERRES enum in aom_encoder.h
 doc/encoders.texi  | 36 +
 libavcodec/libaomenc.c | 46 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 17a0f4c821..80052763db 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1599,6 +1599,42 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item superres-mode (@emph{mode})
+Select super-resolution mode.
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed.
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved.
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index.
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames.
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}.
+Valid value ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames when
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode}
+is @option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index fe98449fa1..4959f84c2c 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -23,6 +23,7 @@
  * AV1 encoder support via libaom
  */
 
+#include 
 #define AOM_DISABLE_CTRL_TYPECHECKS 1
 #include 
 #include 
@@ -96,6 +97,11 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -135,6 +141,7 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -204,6 +211,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",   cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:",cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -546,6 +560,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 8)
+enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 8)
+enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -688,6 +713,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 // codec control failures are currently treated only as warnings
 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+if (ctx->superres_mode > 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, 1);
 if (ctx->auto_alt_ref >= 0)
 codecctl_int(avctx, AOME_

[FFmpeg-devel] [PATCH 2/2] fftools/ffmpeg.c: Add an option "multiple_output_final_stats"

2020-06-26 Thread Wang Cao
From: Wang Cao 

* "multiple_output_final_stats" is used to display stats for each output when 
ffmpeg completes processing.
* Also refactor to add a new function to print verbose stats for input/output 
so that the behavior is same as before by default.

Signed-off-by: Wang Cao 
---
 doc/ffmpeg.texi  |  6 +
 fftools/ffmpeg.c | 53 +---
 fftools/ffmpeg.h |  1 +
 fftools/ffmpeg_opt.c |  3 +++
 4 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 70b8965d7f..6c88c97c60 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -734,6 +734,12 @@ ffmpeg -dump_attachment:t "" -i INPUT
 Technical note -- attachments are implemented as codec extradata, so this
 option can actually be used to extract extradata from any stream, not just
 attachments.
+
+@item -multiple_output_final_stats (@emph{global})
+Print final stats for each output when processing completes.
+@example
+ffmpeg -i INPUT -multiple_output_final_stats out0.mkv out1.mkv
+@end example
 @end table
 
 @section Video Options
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 07396204b6..1757899d7f 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1514,8 +1514,9 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats(int64_t total_size, int output_file_index)
 {
+OutputFile *of;
 AVFormatContext *oc;
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
@@ -1524,10 +1525,11 @@ static void print_final_stats(int64_t total_size)
 int i, j;
 int pass1_used = 1;
 
-oc = output_files[0]->ctx;
+of = output_files[output_file_index];
+oc = of->ctx;
 
 for (i = 0; i < oc->nb_streams; i++) {
-OutputStream *ost = output_streams[i];
+OutputStream *ost = output_streams[of->ost_index + i];
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1555,6 +1557,18 @@ static void print_final_stats(int64_t total_size)
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+if (video_size + data_size + audio_size + subtitle_size + extra_size == 0){
+av_log(NULL, AV_LOG_WARNING, "Output file is empty, nothing was 
encoded ");
+if (pass1_used) {
+av_log(NULL, AV_LOG_WARNING, "\n");
+} else {
+av_log(NULL, AV_LOG_WARNING, "(check -ss / -t / -frames parameters 
if used)\n");
+}
+}
+}
+
+static void print_verbose_input_output_stats() {
+int i, j;
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1624,20 +1638,14 @@ static void print_final_stats(int64_t total_size)
 av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" 
bytes) muxed\n",
total_packets, total_size);
 }
-if(video_size + data_size + audio_size + subtitle_size + extra_size == 0){
-av_log(NULL, AV_LOG_WARNING, "Output file is empty, nothing was 
encoded ");
-if (pass1_used) {
-av_log(NULL, AV_LOG_WARNING, "\n");
-} else {
-av_log(NULL, AV_LOG_WARNING, "(check -ss / -t / -frames parameters 
if used)\n");
-}
-}
 }
 
-static void print_report(int is_last_report, int64_t timer_start, int64_t 
cur_time)
+static void print_report(int is_last_report, int output_file_index,
+ int64_t timer_start, int64_t cur_time)
 {
 AVBPrint buf, buf_script;
 OutputStream *ost;
+OutputFile *of;
 AVFormatContext *oc;
 int64_t total_size;
 AVCodecContext *enc;
@@ -1668,7 +1676,8 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 t = (cur_time-timer_start) / 100.0;
 
 
-oc = output_files[0]->ctx;
+of = output_files[output_file_index];
+oc = of->ctx;
 
 total_size = avio_size(oc->pb);
 if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
@@ -1679,7 +1688,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 av_bprint_init(_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
 for (i = 0; i < oc->nb_streams; i++) {
 float q = -1;
-ost = output_streams[i];
+ost = output_streams[of->ost_index + i];
 enc = ost->enc_ctx;
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
@@ -1830,7 +1839,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 }
 
 if (is_last_report)
-print_final_stat

[FFmpeg-devel] [PATCH 1/2] fftools/ffmpeg.c: Use the streams from the first output in print_final_stats.

2020-06-26 Thread Wang Cao
From: Wang Cao 

It appears the initial intention was to print stats for the first
output. Currently all output streams are aggregated for the final stats
which is inconsistent with the "size" reported in print_report.

For example, when two outputs are specified, output 0 has size of 100 kB
and output 1 has size of 50 kB. The output would look like:

frame=  206 fps=3.6 q=0.0 LPSNR=Y:45.57 U:50.04 V:50.07 *:46.62 size=100kB 
time=00:00:07.10 bitrate=1362.7kbits/s speed=0.124x
video:140kB audio:79kB subtitle:0kB other streams:0kB global headers:0kB muxing 
overhead: 0.382502%

The "video" reported is larger than the previous line and this is
confusing.

Signed-off-by: Wang Cao 
---
 fftools/ffmpeg.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2e9448ea2b..07396204b6 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1516,6 +1516,7 @@ static int reap_filters(int flush)
 
 static void print_final_stats(int64_t total_size)
 {
+AVFormatContext *oc;
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
@@ -1523,7 +1524,9 @@ static void print_final_stats(int64_t total_size)
 int i, j;
 int pass1_used = 1;
 
-for (i = 0; i < nb_output_streams; i++) {
+oc = output_files[0]->ctx;
+
+for (i = 0; i < oc->nb_streams; i++) {
 OutputStream *ost = output_streams[i];
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
@@ -1674,7 +1677,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
-for (i = 0; i < nb_output_streams; i++) {
+for (i = 0; i < oc->nb_streams; i++) {
 float q = -1;
 ost = output_streams[i];
 enc = ost->enc_ctx;
-- 
2.27.0.212.ge8ba1cc988-goog

___
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/5] libavcodec/libaomenc: Add command-line options to control the use of partition tools.

2020-06-25 Thread Wang Cao
This patch adds the control for enabling rectangular partitions, 1:4/4:1
partitions and AB shape partitions.

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 10 ++
 libavcodec/libaomenc.c | 15 +++
 libavcodec/version.h   |  2 +-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 045535accb..6513f6c3ef 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1638,8 +1638,18 @@ is @option{qthresh}. Valid value ranges from 1 to 63.
 The q level threshold after which superres is used for key frames when
 @option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
 
+@item enable-rect-partitions (@emph{boolean})
+Enable rectangular partitions. Default is true.
+
+@item enable-1to4-partitions (@emph{boolean})
+Enable 1:4/4:1 partitions. Default is true.
+
+@item enable-ab-partitions (@emph{boolean})
+Enable AB shape partitions. Default is true.
+
 @end table
 
+
 @section libkvazaar
 
 Kvazaar H.265/HEVC encoder.
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 17e130d8ec..ab2f456518 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -102,6 +102,9 @@ typedef struct AOMEncoderContext {
 int superres_qthresh;
 int superres_kf_denominator;
 int superres_kf_qthresh;
+int enable_rect_partitions;
+int enable_1to4_partitions;
+int enable_ab_partitions;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -142,6 +145,9 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
 [AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
+[AV1E_SET_ENABLE_1TO4_PARTITIONS] = "AV1E_SET_ENABLE_1TO4_PARTITIONS",
+[AV1E_SET_ENABLE_AB_PARTITIONS]   = "AV1E_SET_ENABLE_AB_PARTITIONS",
+[AV1E_SET_ENABLE_RECT_PARTITIONS] = "AV1E_SET_ENABLE_RECT_PARTITIONS",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -725,6 +731,12 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, ctx->enable_cdef);
 if (ctx->enable_restoration >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION, 
ctx->enable_restoration);
+if (ctx->enable_rect_partitions >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_RECT_PARTITIONS, 
ctx->enable_rect_partitions);
+if (ctx->enable_1to4_partitions >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_1TO4_PARTITIONS, 
ctx->enable_1to4_partitions);
+if (ctx->enable_ab_partitions >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_AB_PARTITIONS, 
ctx->enable_ab_partitions);
 
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
@@ -1145,6 +1157,9 @@ static const AVOption options[] = {
 { "superres-qthresh","The q level threshold after which superres 
is used, range [1, 63]",OFFSET(superres_qthresh),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE},
 { "superres-kf-denominator", "The denominator for superres to use on key 
frames, range [8, 16]", OFFSET(superres_kf_denominator), 
AV_OPT_TYPE_INT, {.i64 = 8}, 8, 16, VE},
 { "superres-kf-qthresh", "The q level threshold after which superres 
is used for key frames, range [1, 63]", OFFSET(superres_kf_qthresh), 
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE},
+{ "enable-rect-partitions", "Enable rectangular partitions", 
OFFSET(enable_rect_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+{ "enable-1to4-partitions", "Enable 1:4/4:1 partitions", 
OFFSET(enable_1to4_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+{ "enable-ab-partitions",   "Enable ab shape partitions",
OFFSET(enable_ab_partitions),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { NULL },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 05f59901ff..c9ce7981b5 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  93
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MICRO 102
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.27.0.111.gc72c7da667-goog

___
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 4/5] libavcodec/libaomenc.c: Add command-line options for tx tools.

2020-06-25 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 21 +
 libavcodec/libaomenc.c | 31 +++
 libavcodec/version.h   |  2 +-
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index f052d68c46..329c887ce0 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1668,6 +1668,27 @@ Enable paeth predictor in intra prediction. Default is 
true.
 @item enable-palette (@emph{boolean})
 Enable palette prediction mode. Default is true.
 
+@item enable-flip-idtx (@emph{boolean})
+Enable extended transform type (0: false, 1: true (default))
+including FLIPADST_DCT, DCT_FLIPADST, FLIPADST_FLIPADST,
+ADST_FLIPADST, FLIPADST_ADST, IDTX, V_DCT, H_DCT, V_ADST,
+ H_ADST, V_FLIPADST, H_FLIPADST
+
+@item enable-tx64 (@emph{boolean})
+Enable 64-pt transform (0: false, 1: true (default))
+
+@item reduced-tx-type-set (@emph{boolean})
+Use reduced set of transform types. Default is false.
+
+@item use-intra-dct-only (@emph{boolean})
+Use DCT only for INTRA modes. Default is false.
+
+@item use-inter-dct-only (@emph{boolean})
+Use DCT only for INTER modes. Default is false.
+
+@item use-intra-default-tx-only (@emph{boolean})
+Use Default-transform only for INTRA modes. Default is false.
+
 @end table
 
 
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index d1615e75c6..745d7e09fc 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -112,6 +112,12 @@ typedef struct AOMEncoderContext {
 int enable_intra_edge_filter;
 int enable_palette;
 int enable_filter_intra;
+int enable_flip_idtx;
+int enable_tx64;
+int reduced_tx_type_set;
+int use_intra_dct_only;
+int use_inter_dct_only;
+int use_intra_default_tx_only;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -162,6 +168,12 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_PAETH_INTRA]   = "AV1E_SET_ENABLE_PAETH_INTRA",
 [AV1E_SET_ENABLE_SMOOTH_INTRA]  = "AV1E_SET_ENABLE_SMOOTH_INTRA",
 [AV1E_SET_ENABLE_PALETTE]   = "AV1E_SET_ENABLE_PALETTE",
+[AV1E_SET_ENABLE_FLIP_IDTX]  = "AV1E_SET_ENABLE_FLIP_IDTX",
+[AV1E_SET_ENABLE_TX64]   = "AV1E_SET_ENABLE_TX64",
+[AV1E_SET_INTRA_DCT_ONLY]= "AV1E_SET_INTRA_DCT_ONLY",
+[AV1E_SET_INTER_DCT_ONLY]= "AV1E_SET_INTER_DCT_ONLY",
+[AV1E_SET_INTRA_DEFAULT_TX_ONLY] = "AV1E_SET_INTRA_DEFAULT_TX_ONLY",
+[AV1E_SET_REDUCED_TX_TYPE_SET]   = "AV1E_SET_REDUCED_TX_TYPE_SET",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -765,6 +777,19 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA, 
ctx->enable_smooth_intra);
 if (ctx->enable_palette >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_PALETTE, ctx->enable_palette);
+if (ctx->enable_tx64 >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_TX64, ctx->enable_tx64);
+if (ctx->enable_flip_idtx >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_FLIP_IDTX, ctx->enable_flip_idtx);
+if (ctx->use_intra_dct_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTRA_DCT_ONLY, ctx->use_intra_dct_only);
+if (ctx->use_inter_dct_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTER_DCT_ONLY, ctx->use_inter_dct_only);
+if (ctx->use_intra_default_tx_only >= 0)
+codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY, 
ctx->use_intra_default_tx_only);
+if (ctx->reduced_tx_type_set >= 0)
+codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET, 
ctx->reduced_tx_type_set);
+
 
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
@@ -1195,6 +1220,12 @@ static const AVOption options[] = {
 { "enable-smooth-intra",  "Enable smooth intra prediction mode",   
 OFFSET(enable_smooth_intra),  AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 
1, VE},
 { "enable-paeth-intra",   "Enable paeth predictor in intra 
prediction", OFFSET(enable_paeth_intra),   AV_OPT_TYPE_BOOL, {.i64 
= -1}, -1, 1, VE},
 { "enable-palette",   "Enable palette prediction mode",
 OFFSET(enable_palette),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 
1, VE},
+{ "enable-flip-idtx",  "Enable extended transform type",   
OFFSET(enable_flip_idtx),  AV_OPT_TYPE_BOOL, {.i64 = -1}, 
-1, 1, VE},
+{ "enable-tx64",   "Enable 64-pt transform",   
OFFSET(enable_tx64),   AV_OPT_TYPE_BOOL, {.i64 = -1}, 
-1, 1, VE},
+{ "reduced-tx-type-set",   "Use reduced set of transform types. 
Default is false

[FFmpeg-devel] [PATCH 5/5] libavcodec/libaomenc.c: Add command-line options for inter-coding tools

2020-06-25 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 36 +
 libavcodec/libaomenc.c | 61 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 329c887ce0..c1c5a9c9ca 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1689,6 +1689,42 @@ Use DCT only for INTER modes. Default is false.
 @item use-intra-default-tx-only (@emph{boolean})
 Use Default-transform only for INTRA modes. Default is false.
 
+@item enable-ref-frame-mvs (@emph{boolean})
+Enable temporal mv prediction (default is 1)
+
+@item enable-reduced-reference-set (@emph{boolean})
+Use reduced set of single and compound references  (0: off (default), 1: on)
+
+@item enable-obmc (@emph{boolean})
+Enable obmc (0: false, 1: true (default))
+
+@item enable-dual-filter (@emph{boolean})
+Enable dual filter (0: false, 1: true (default))
+
+@item enable-diff-wtd-comp (@emph{boolean})
+Enable difference-weighted compound (0: false, 1: true (default))
+
+@item enable-dist-wtd-comp (@emph{boolean})
+Enable distance-weighted compound (0: false, 1: true (default))
+
+@item enable-onesided-comp (@emph{boolean})
+Enable one sided compound (0: false, 1: true (default))
+
+@item enable-interinter-wedge (@emph{boolean})
+Enable interinter wedge compound (0: false, 1: true (default))
+
+@item enable-interintra-wedge (@emph{boolean})
+Enable interintra wedge compound (0: false, 1: true (default))
+
+@item enable-masked-comp (@emph{boolean})
+Enable masked compound (0: false, 1: true (default))
+
+@item enable-interintra-comp (@emph{boolean})
+Enable interintra compound (0: false, 1: true (default))
+
+@item enable-smooth-interintra (@emph{boolean})
+Enable smooth interintra mode (0: false, 1: true (default))
+
 @end table
 
 
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 745d7e09fc..3eed019ef3 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -118,6 +118,18 @@ typedef struct AOMEncoderContext {
 int use_intra_dct_only;
 int use_inter_dct_only;
 int use_intra_default_tx_only;
+int enable_ref_frame_mvs;
+int enable_interinter_wedge;
+int enable_interintra_wedge;
+int enable_interintra_comp;
+int enable_masked_comp;
+int enable_obmc;
+int enable_onesided_comp;
+int enable_reduced_reference_set;
+int enable_smooth_interintra;
+int enable_diff_wtd_comp;
+int enable_dist_wtd_comp;
+int enable_dual_filter;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -174,6 +186,19 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_INTER_DCT_ONLY]= "AV1E_SET_INTER_DCT_ONLY",
 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] = "AV1E_SET_INTRA_DEFAULT_TX_ONLY",
 [AV1E_SET_REDUCED_TX_TYPE_SET]   = "AV1E_SET_REDUCED_TX_TYPE_SET",
+[AV1E_SET_ALLOW_WARPED_MOTION]  = "AV1E_SET_ALLOW_WARPED_MOTION",
+[AV1E_SET_ENABLE_DIFF_WTD_COMP] = "AV1E_SET_ENABLE_DIFF_WTD_COMP",
+[AV1E_SET_ENABLE_DIST_WTD_COMP] = "AV1E_SET_ENABLE_DIST_WTD_COMP",
+[AV1E_SET_ENABLE_DUAL_FILTER]   = "AV1E_SET_ENABLE_DUAL_FILTER",
+[AV1E_SET_ENABLE_INTERINTER_WEDGE]  = "AV1E_SET_ENABLE_INTERINTER_WEDGE",
+[AV1E_SET_ENABLE_INTERINTRA_WEDGE]  = "AV1E_SET_ENABLE_INTERINTRA_WEDGE",
+[AV1E_SET_ENABLE_MASKED_COMP]   = "AV1E_SET_ENABLE_MASKED_COMP",
+[AV1E_SET_ENABLE_INTERINTRA_COMP]   = "AV1E_SET_ENABLE_INTERINTRA_COMP",
+[AV1E_SET_ENABLE_OBMC]  = "AV1E_SET_ENABLE_OBMC",
+[AV1E_SET_ENABLE_ONESIDED_COMP] = "AV1E_SET_ENABLE_ONESIDED_COMP",
+[AV1E_SET_REDUCED_REFERENCE_SET]= "AV1E_SET_REDUCED_REFERENCE_SET",
+[AV1E_SET_ENABLE_SMOOTH_INTERINTRA] = "AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
+[AV1E_SET_ENABLE_REF_FRAME_MVS] = "AV1E_SET_ENABLE_REF_FRAME_MVS",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -789,6 +814,30 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY, 
ctx->use_intra_default_tx_only);
 if (ctx->reduced_tx_type_set >= 0)
 codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET, 
ctx->reduced_tx_type_set);
+if (ctx->enable_ref_frame_mvs >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_REF_FRAME_MVS, 
ctx->enable_ref_frame_mvs);
+if (ctx->enable_reduced_reference_set >= 0)
+codecctl_int(avctx, AV1E_SET_REDUCED_REFERENCE_SET, 
ctx->enable_reduced_reference_set);
+if (ctx->enable_diff_wtd_comp >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_DIFF_WTD_COMP, 
ctx->enable_diff_wtd_comp);
+if (ctx->enable_dist_wtd_comp >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_DIST_WTD_COMP, 
ctx->enable_dis

[FFmpeg-devel] [PATCH 3/5] libavcodec/libaomenc.c: Add command-line options for intra-coding tools

2020-06-25 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 21 +++
 libavcodec/libaomenc.c | 47 --
 libavcodec/version.h   |  2 +-
 3 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 6513f6c3ef..f052d68c46 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1647,6 +1647,27 @@ Enable 1:4/4:1 partitions. Default is true.
 @item enable-ab-partitions (@emph{boolean})
 Enable AB shape partitions. Default is true.
 
+@item enable-angle-delta (@emph{boolean})
+Enable angle delta intra prediction. Default is true.
+
+@item enable-cfl-intra (@emph{boolean})
+Enable chroma predicted from luma intra prediction. Default is true.
+
+@item enable-filter-intra (@emph{boolean})
+Enable filter intra predictor. Default is true.
+
+@item enable-intra-edge-filter (@emph{boolean})
+Enable intra edge filter. Default is true.
+
+@item enable-smooth-intra (@emph{boolean})
+Enable smooth intra prediction mode. Default is true.
+
+@item enable-paeth-intra (@emph{boolean})
+Enable paeth predictor in intra prediction. Default is true.
+
+@item enable-palette (@emph{boolean})
+Enable palette prediction mode. Default is true.
+
 @end table
 
 
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index ab2f456518..d1615e75c6 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -105,6 +105,13 @@ typedef struct AOMEncoderContext {
 int enable_rect_partitions;
 int enable_1to4_partitions;
 int enable_ab_partitions;
+int enable_angle_delta;
+int enable_cfl_intra;
+int enable_paeth_intra;
+int enable_smooth_intra;
+int enable_intra_edge_filter;
+int enable_palette;
+int enable_filter_intra;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -142,12 +149,19 @@ static const char *const ctlidstr[] = {
 #ifdef AOM_CTRL_AV1E_SET_ENABLE_INTRABC
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
-[AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
-[AOME_SET_TUNING]   = "AOME_SET_TUNING",
-[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
-[AV1E_SET_ENABLE_1TO4_PARTITIONS] = "AV1E_SET_ENABLE_1TO4_PARTITIONS",
-[AV1E_SET_ENABLE_AB_PARTITIONS]   = "AV1E_SET_ENABLE_AB_PARTITIONS",
-[AV1E_SET_ENABLE_RECT_PARTITIONS] = "AV1E_SET_ENABLE_RECT_PARTITIONS",
+[AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
+[AV1E_SET_ENABLE_1TO4_PARTITIONS]   = "AV1E_SET_ENABLE_1TO4_PARTITIONS",
+[AV1E_SET_ENABLE_AB_PARTITIONS] = "AV1E_SET_ENABLE_AB_PARTITIONS",
+[AV1E_SET_ENABLE_RECT_PARTITIONS]   = "AV1E_SET_ENABLE_RECT_PARTITIONS",
+[AV1E_SET_ENABLE_ANGLE_DELTA]   = "AV1E_SET_ENABLE_ANGLE_DELTA",
+[AV1E_SET_ENABLE_CFL_INTRA] = "AV1E_SET_ENABLE_CFL_INTRA",
+[AV1E_SET_ENABLE_FILTER_INTRA]  = "AV1E_SET_ENABLE_FILTER_INTRA",
+[AV1E_SET_ENABLE_INTRA_EDGE_FILTER] = "AV1E_SET_ENABLE_INTRA_EDGE_FILTER",
+[AV1E_SET_ENABLE_PAETH_INTRA]   = "AV1E_SET_ENABLE_PAETH_INTRA",
+[AV1E_SET_ENABLE_SMOOTH_INTRA]  = "AV1E_SET_ENABLE_SMOOTH_INTRA",
+[AV1E_SET_ENABLE_PALETTE]   = "AV1E_SET_ENABLE_PALETTE",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -737,6 +751,20 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AV1E_SET_ENABLE_1TO4_PARTITIONS, 
ctx->enable_1to4_partitions);
 if (ctx->enable_ab_partitions >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_AB_PARTITIONS, 
ctx->enable_ab_partitions);
+if (ctx->enable_angle_delta >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_ANGLE_DELTA, 
ctx->enable_angle_delta);
+if (ctx->enable_cfl_intra >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_CFL_INTRA, ctx->enable_cfl_intra);
+if (ctx->enable_filter_intra >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_FILTER_INTRA, 
ctx->enable_filter_intra);
+if (ctx->enable_intra_edge_filter >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_INTRA_EDGE_FILTER, 
ctx->enable_intra_edge_filter);
+if (ctx->enable_paeth_intra >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_PAETH_INTRA, 
ctx->enable_paeth_intra);
+if (ctx->enable_smooth_intra >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA, 
ctx->enable_smooth_intra);
+if (ctx->enable_palette >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_PALETTE, ctx->enable_palette);
 
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
@@ -1160,6 +1

[FFmpeg-devel] [PATCH 1/5] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-06-25 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 39 +++
 libavcodec/libaomenc.c | 38 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 17a0f4c821..045535accb 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1599,6 +1599,45 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item enable-superres (@emph{boolean})
+Enable super-resolution during the encoding process.
+
+@item superres-mode (@emph{mode})
+Select super-resolution mode.
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed.
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved.
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index.
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames.
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}.
+Valid value ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames when
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode}
+is @option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 1c78da719a..17e130d8ec 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -96,6 +96,12 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int enable_superres;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -135,6 +141,7 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -204,6 +211,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",   cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:",cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -546,6 +560,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 8)
+enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 8)
+enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -688,6 +713,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 // codec control failures are currently treated only as warnings
 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+if (ctx->enable_superres >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, ctx->enable_superres);
 if (ctx->auto_alt_ref >= 0)
 codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_al

[FFmpeg-devel] [PATCH v3] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-06-25 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
Updated to use the enum defined in libaom for super-resolution.
 doc/encoders.texi  | 39 +++
 libavcodec/libaomenc.c | 38 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 17a0f4c821..045535accb 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1599,6 +1599,45 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item enable-superres (@emph{boolean})
+Enable super-resolution during the encoding process.
+
+@item superres-mode (@emph{mode})
+Select super-resolution mode.
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed.
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved.
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index.
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames.
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}.
+Valid value ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames when
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode}
+is @option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 1c78da719a..17e130d8ec 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -96,6 +96,12 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int enable_superres;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -135,6 +141,7 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -204,6 +211,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",   cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:",cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -546,6 +560,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 8)
+enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 8)
+enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -688,6 +713,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 // codec control failures are currently treated only as warnings
 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+if (ctx->enable_superres >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, ctx->enable_superres);
 if (ctx->auto_alt_ref >= 0)
 codecctl_int(a

[FFmpeg-devel] [PATCH v2 2/2] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-04-03 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 39 +++
 libavcodec/libaomenc.c | 47 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 18bfe8f2eb..e32fecdca3 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1606,6 +1606,45 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item enable-superres (@emph{boolean})
+Enable super-resolution during the encoding process.
+
+@item superres-mode (@emph{mode})
+Select super-resolution mode.
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed.
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved.
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index.
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames.
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}. Valid value 
+ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames when 
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode} 
is 
+@option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when 
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 20b0e5c8e9..8552813a8a 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -95,6 +95,12 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int enable_superres;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -134,6 +140,16 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
+};
+
+enum AOMSuperresModes {
+AOM_SUPERRES_MODE_NONE= 0,
+AOM_SUPERRES_MODE_FIXED   = 1,
+AOM_SUPERRES_MODE_RANDOM  = 2,
+AOM_SUPERRES_MODE_QTHRESH = 3,
+AOM_SUPERRES_MODE_AUTO= 4,
+AOM_SUPERRES_MODE_NB
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -203,6 +219,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",   cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:",cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -545,6 +568,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 0)
+enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 0)
+enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -687,6 +721,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 // codec control failures are currently treated only as warnings
 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+if (ctx->enable

[FFmpeg-devel] [PATCH v2 1/2] avcodec/libaomenc.c: Add a libaom command-line option 'tune'

2020-04-03 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 9 +
 libavcodec/libaomenc.c | 7 +++
 libavcodec/version.h   | 2 +-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e23b6b32fe..18bfe8f2eb 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1508,6 +1508,15 @@ Complexity-based.
 Cyclic refresh.
 @end table
 
+@item tune (@emph{tune})
+Set the distortion metric the encoder is tuned with. Default is @code{psnr}.
+
+@table @samp
+@item psnr (@emph{0})
+
+@item ssim (@emph{1})
+@end table
+
 @item lag-in-frames
 Set the maximum number of frames which the encoder may keep in flight
 at any one time for lookahead purposes.  Defaults to the internal
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..20b0e5c8e9 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 tune;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -132,6 +133,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AOME_SET_TUNING]   = "AOME_SET_TUNING",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -699,6 +701,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
+if (ctx->tune >= 0)
+codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
@@ -1096,6 +1100,9 @@ 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"},
+{ "tune","The metric that encoder tunes. Automatically choosen 
by the encoder by default", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
AOM_TUNE_SSIM, VE, "tune"},
+{ "psnr",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
+{ "ssim",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
 { NULL },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index f4d1d4de21..dadca75430 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  77
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MICRO 102
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.26.0.292.g33ef6b2f38-goog

___
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 2/2] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-04-03 Thread Wang Cao
On Wed, Mar 18, 2020 at 6:38 AM James Zern  wrote:

> Hi,
>
> On Thu, Mar 5, 2020 at 6:20 PM Wang Cao  wrote:
> >
> > Signed-off-by: Wang Cao 
> > ---
> > The changes are made according to the code review
> > - Bump the MICRO version
> > - Use enum for Super resolution mode consts. The original enum in libaom
> >   is not public so a enum is defined and matched the original enum
> >  doc/encoders.texi  | 39 +++
> >  libavcodec/libaomenc.c | 47 ++
> >  libavcodec/version.h   |  2 +-
> >  3 files changed, 87 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/encoders.texi b/doc/encoders.texi
> > index 0a74ecce9b..04f05e7c9b 100644
> > --- a/doc/encoders.texi
> > +++ b/doc/encoders.texi
> > @@ -1608,6 +1608,45 @@ Enable the use of global motion for block
> prediction. Default is true.
> >  Enable block copy mode for intra block prediction. This mode is
> >  useful for screen content. Default is true.
> >
> > +@item enable-superres (@emph{boolean})
> > +Enable super-resolution during the encoding process.
> > +
>
> Funny aomenc in libaom doesn't have this option. It must assume the
> library defaults will take care of it, seems like a bug.
>
> Yes they use a default value "1" for this internally (
https://aomedia.googlesource.com/aom/+/master/av1/av1_cx_iface.c).

> > +@item superres-mode (@emph{mode})
> > +Select super-resultion mode.
> > +
>
> resolution
>
I will send a new patch to apply the changes you mentioned.
-- 

Wang Cao |  Software Engineer |  wang...@google.com |  650-203-7807
___
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: Add super-resolution options to libaom wrapper

2020-03-05 Thread Wang Cao
On Wed, Mar 4, 2020 at 1:38 AM Moritz Barsnick  wrote:

> On Wed, Mar 04, 2020 at 05:59:03 +0800, Wang Cao wrote:
> > Signed-off-by: Wang Cao 
> > ---
> >  doc/encoders.texi  | 39 +++
> >  libavcodec/libaomenc.c | 38 ++
>
> Again, I suggest bumping MICRO once more.
>
Done.

> > +@item superres_denominator
> > +The denominator for superres to use when @option{superres-mode} is
> @option{fixed}. Valid value
> > +ranges from 8 to 16.
> > +
> > +@item superres_kf_denominator
> > +The denominator for superres to use on key frames is fixed when
> > +@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to
> 16.
>
> I believe "is fixed " is not needed in this sentence, or even
> confusing.
>
Done.

> >  [AOME_SET_TUNING]   = "AOME_SET_TUNING",
> > +[AV1E_SET_ENABLE_SUPERRES] = "AV1E_SET_ENABLE_SUPERRES",
>
> The other '=' in this block are aligned.
>
> > +if (ctx->superres_mode >= 0)
> > +  enccfg.rc_superres_mode = ctx->superres_mode;
> > +if (ctx->superres_qthresh > 0)
> > +  enccfg.rc_superres_qthresh = ctx->superres_qthresh;
> > +if (ctx->superres_kf_qthresh > 0)
> > +  enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
> > +if (ctx->superres_denominator >= 0)
> > +  enccfg.rc_superres_denominator = ctx->superres_denominator;
> > +if (ctx->superres_kf_denominator >= 0)
> > +  enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
>
> It looks like indentation is off - ffmpeg uses four spaces.
>
> (Is this struct zero-initialized / memset()'d?)

Yes it is initialized before through aom_codec_enc_config_default

>
>
>  { "ssim","SSIM as distortion metric", 0,
> AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune"},
> > +{ "enable-superres", "Enable super-resolution mode",
> OFFSET(enable_superres), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> > +{ "superres-mode",   "Select super-resultion mode",
> OFFSET(superres_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4, VE,
> "superres_mode"},
> > +{ "none","No frame superres allowed", 0,
> AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "superres_mode"},
> > +{ "fixed",   "All frames are coded at the specified scale
> and super-resolved", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE,
> "superres_mode"},
> > +{ "random",  "All frames are coded at a random scale and
> super-resolved.", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE,
> "superres_mode"},
> > +{ "qthresh", "Superres scale for a frame is determined
> based on q_index",  0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE,
> "superres_mode"},
> > +{ "auto","Automatically select superres for appropriate
> frames",   0, AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0, VE,
> "superres_mode"},
>
> Several remarks:
> - The "none" entry should also be aligned, just like the entry "fixed"
>   and following... (starting at   "0, AV_OPT_TYPE_CONST", if you see
>   what I mean).
> - Is "auto" a value given by the library? I'm asking because
>   we tend to use "-1" for our internal "auto", and use that as a
>   default, if desired.
>   (From looking at libaom, they indeed use 4 for "auto".)
> - Can you directly use the enumerations provided as SUPERRES_MODE by
>   libaom, or are they not public?
> - If you cannot reuse said enum (and its resulting range
>   [-1, SUPERRES_MODES - 1]), you should define your own as enum
>   SuperresModes { AOM_SUPERRES_MODE_NONE, AOM_SUPERRES_MODE_FIXED, ,
>   AOM_SUPERRES_MODE_NB }, use these in the options definition above,
>   and set the allowed range to [-1, AOM_SUPERRES_MODE_NB - 1].
>
> This is a good approach to improve the readability. Done.

> Cheers,
> Moritz
>
Please find the changes in the updated patch. Thanks!
-- 

Wang Cao |  Software Engineer |  wang...@google.com |  650-203-7807
___
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] avcodec/libaomenc.c: Add a libaom command-line option 'tune'

2020-03-05 Thread Wang Cao
Signed-off-by: Wang Cao 
---
Made changes according to the review.
- Bump the MICRO version of libavcodec.
- Use enum for 'tune' option consts for better consistency

 doc/encoders.texi  | 11 +++
 libavcodec/libaomenc.c |  7 +++
 libavcodec/version.h   |  2 +-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e23b6b32fe..0a74ecce9b 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1508,6 +1508,17 @@ Complexity-based.
 Cyclic refresh.
 @end table
 
+@item tune (@emph{tune})
+Set the distortion metric the encoder is tune with. Default is @code{psnr}.
+
+@table @samp
+@item psnr (@emph{0})
+PSNR as distortion metric
+
+@item ssim (@emph{1})
+SSIM as distortion metric
+@end table
+
 @item lag-in-frames
 Set the maximum number of frames which the encoder may keep in flight
 at any one time for lookahead purposes.  Defaults to the internal
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..df7819b429 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 tune;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -132,6 +133,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AOME_SET_TUNING]   = "AOME_SET_TUNING",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -699,6 +701,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
+if (ctx->tune >= 0)
+codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
@@ -1096,6 +1100,9 @@ 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"},
+{ "tune","The metric that encoder tunes for. Automatically 
choosen by encoder by default", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 
AOM_TUNE_SSIM, VE, "tune"},
+{ "psnr","PSNR as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
+{ "ssim","SSIM as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
 { NULL },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 36536c3725..03d7f32f1c 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  73
-#define LIBAVCODEC_VERSION_MICRO 102
+#define LIBAVCODEC_VERSION_MICRO 103
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.25.0.265.gbab2e86ba0-goog

___
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 2/2] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper

2020-03-05 Thread Wang Cao
Signed-off-by: Wang Cao 
---
The changes are made according to the code review
- Bump the MICRO version
- Use enum for Super resolution mode consts. The original enum in libaom
  is not public so a enum is defined and matched the original enum
 doc/encoders.texi  | 39 +++
 libavcodec/libaomenc.c | 47 ++
 libavcodec/version.h   |  2 +-
 3 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 0a74ecce9b..04f05e7c9b 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1608,6 +1608,45 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item enable-superres (@emph{boolean})
+Enable super-resolution during the encoding process.
+
+@item superres-mode (@emph{mode})
+Select super-resultion mode.
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed.
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved.
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index.
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames.
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}. Valid value 
+ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames when 
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode} 
is 
+@option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when 
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index df7819b429..0f4c0377cc 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -95,6 +95,12 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int enable_superres;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -134,6 +140,16 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES]  = "AV1E_SET_ENABLE_SUPERRES",
+};
+
+enum AOMSuperresModes {
+AOM_SUPERRES_MODE_NONE= 0,
+AOM_SUPERRES_MODE_FIXED   = 1,
+AOM_SUPERRES_MODE_RANDOM  = 2,
+AOM_SUPERRES_MODE_QTHRESH = 3,
+AOM_SUPERRES_MODE_AUTO= 4,
+AOM_SUPERRES_MODE_NB
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -203,6 +219,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",   cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:",cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -545,6 +568,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 0)
+enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 0)
+enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -687,6 +721,8 @@ static av_cold int aom_init(AVCodecContext *avctx,

Re: [FFmpeg-devel] [PATCH 1/2] libavcodec/libaomenc.c: Add a libaom command-line opton 'tune'

2020-03-03 Thread Wang Cao
On Tue, Mar 3, 2020 at 3:53 PM Carl Eugen Hoyos  wrote:

> Am Mi., 4. März 2020 um 00:51 Uhr schrieb Wang Cao
> :
>
> [...]
>
> Please find out what "top-posting" means and avoid it here.
>
> Carl Eugen
>
I am very sorry about this my "top-posting" there. As soon as I hit "send"
I realized my mistake of being top-posting. I really apologize for replying
in this way.

-- 

Wang Cao |  Software Engineer |  wang...@google.com |  650-203-7807
<(650)%20203-7807>
___
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 1/2] libavcodec/libaomenc.c: Add a libaom command-line opton 'tune'

2020-03-03 Thread Wang Cao
Let me reply again with the correct posting form.
On Tue, Mar 3, 2020 at 2:50 PM Carl Eugen Hoyos  wrote:

> Am Di., 3. März 2020 um 22:43 Uhr schrieb Wang Cao :
>
> > +@item tune (@emph{tune})
> > +Set the distortion metric tuned with for encoder. Default is PSNR.
> > +
> > +@table @samp
> > +@item psnr (@emph{0})
> > +PSNR as distortion metric
> > +
> > +@item ssim (@emph{1})
> > +SSIM as distortion metric
> > +@end table
>
> My knowledge of video encoding is limited but I would have
> expected (actually I was sure) that the default would be
> "visual" or similar and not an artificial metric.
>
 Yes. I share the share hope as you do. The default should be a metric that
reflects actual human perception of a video. As far as I understand the
current status for now, PSNR and SSIM is the metric that libaom is by
default compiled with. Other metrics are being added support. For example,
VMAF and other metrics are also supported now as you can find them in
https://aomedia.googlesource.com/aom/+/refs/heads/master/aom/aomcx.h. I
added those two metrics trying to be conservative here because I don't know
if some require special configs.

> Does this mean libaom is only made to please automatic
> comparison tests?
>
> Carl Eugen
>
> As I mentioned above, libaom continues to add support for optimizing for
different metrics. I personally do not know if there is a perfect visual
quality metric for now. I will continue to add more options to ffmpeg if I
can make sure those metrics can be used in ffmpeg command-line easily.

-- 

Wang Cao |  Software Engineer |  wang...@google.com |  650-203-7807
___
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 1/2] libavcodec/libaomenc.c: Add a libaom command-line opton 'tune'

2020-03-03 Thread Wang Cao
It would be ideal to have the encoder optimizes visual quality. However,
the ideal of "visual" metric is subjective and the related research is
ongoing. Actually libaom has support for VMAF and other metrics but they
probably require a different config while compiling libaom. PSNR and SSIM
are two metrics that the library definitely has default support with.

On Tue, Mar 3, 2020 at 2:50 PM Carl Eugen Hoyos  wrote:

> Am Di., 3. März 2020 um 22:43 Uhr schrieb Wang Cao :
>
> > +@item tune (@emph{tune})
> > +Set the distortion metric tuned with for encoder. Default is PSNR.
> > +
> > +@table @samp
> > +@item psnr (@emph{0})
> > +PSNR as distortion metric
> > +
> > +@item ssim (@emph{1})
> > +SSIM as distortion metric
> > +@end table
>
> My knowledge of video encoding is limited but I would have
> expected (actually I was sure) that the default would be
> "visual" or similar and not an artificial metric.
>
> Does this mean libaom is only made to please automatic
> comparison tests?
>
> 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".



-- 

Wang Cao |  Software Engineer |  wang...@google.com |  650-203-7807
___
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 1/2] libavcodec/libaomenc.c: Add a libaom command-line opton 'tune'

2020-03-03 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 11 +++
 libavcodec/libaomenc.c |  7 +++
 2 files changed, 18 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e23b6b32fe..4215f237bd 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1508,6 +1508,17 @@ Complexity-based.
 Cyclic refresh.
 @end table
 
+@item tune (@emph{tune})
+Set the distortion metric tuned with for encoder. Default is PSNR.
+
+@table @samp
+@item psnr (@emph{0})
+PSNR as distortion metric
+
+@item ssim (@emph{1})
+SSIM as distortion metric
+@end table
+
 @item lag-in-frames
 Set the maximum number of frames which the encoder may keep in flight
 at any one time for lookahead purposes.  Defaults to the internal
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..7fd624c470 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 tune;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -132,6 +133,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AOME_SET_TUNING]   = "AOME_SET_TUNING",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -699,6 +701,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
+if (ctx->tune >= 0)
+codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
@@ -1096,6 +1100,9 @@ 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"},
+{ "tune","The metric that encoder tunes for", OFFSET(tune), 
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE, "tune"},
+{ "psnr","PSNR as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "tune"},
+{ "ssim","SSIM as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune"},
 { NULL },
 };
 
-- 
2.25.0.265.gbab2e86ba0-goog

___
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: Add super-resolution options to libaom wrapper

2020-03-03 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 39 +++
 libavcodec/libaomenc.c | 38 ++
 2 files changed, 77 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 4215f237bd..ac00c305d5 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1608,6 +1608,45 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item enable-superres (@emph{boolean})
+Enable super-resolution during the encoding process.
+
+@item superres-mode (@emph{mode})
+Select super-resultion mode
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}. Valid value 
+ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames is fixed when 
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode} 
is 
+@option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when 
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 7fd624c470..f1578db5e6 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -95,6 +95,12 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int enable_superres;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -134,6 +140,7 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES] = "AV1E_SET_ENABLE_SUPERRES",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -203,6 +210,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "%*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",  cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:", cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -545,6 +559,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+  enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+  enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+  enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 0)
+  enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 0)
+  enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -687,6 +712,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 // codec control failures are currently treated only as warnings
 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+if (ctx->enable_superres >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, ctx->enable_superres);
 if (ctx->auto_alt_ref >= 0)
 codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
 if (ctx->arnr_max_frames >= 0)
@@ -1103,6 +1130,17 @@ static const AVOption options[] = 

[FFmpeg-devel] [PATCH 1/2] libavcodec/libaomenc.c: Add a libaom command-line opton 'tune'

2020-03-03 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 11 +++
 libavcodec/libaomenc.c |  7 +++
 2 files changed, 18 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e23b6b32fe..4215f237bd 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1508,6 +1508,17 @@ Complexity-based.
 Cyclic refresh.
 @end table
 
+@item tune (@emph{tune})
+Set the distortion metric tuned with for encoder. Default is PSNR.
+
+@table @samp
+@item psnr (@emph{0})
+PSNR as distortion metric
+
+@item ssim (@emph{1})
+SSIM as distortion metric
+@end table
+
 @item lag-in-frames
 Set the maximum number of frames which the encoder may keep in flight
 at any one time for lookahead purposes.  Defaults to the internal
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..7fd624c470 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 tune;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -132,6 +133,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AOME_SET_TUNING]   = "AOME_SET_TUNING",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -699,6 +701,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
+if (ctx->tune >= 0)
+codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
@@ -1096,6 +1100,9 @@ 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"},
+{ "tune","The metric that encoder tunes for", OFFSET(tune), 
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE, "tune"},
+{ "psnr","PSNR as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "tune"},
+{ "ssim","SSIM as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune"},
 { NULL },
 };
 
-- 
2.25.0.265.gbab2e86ba0-goog

___
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 1/2] libavcodec/libaomenc.c: Add a libaom command-line opton 'tune'

2020-03-03 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 11 +++
 libavcodec/libaomenc.c |  7 +++
 2 files changed, 18 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e23b6b32fe..4215f237bd 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1508,6 +1508,17 @@ Complexity-based.
 Cyclic refresh.
 @end table
 
+@item tune (@emph{tune})
+Set the distortion metric tuned with for encoder. Default is PSNR.
+
+@table @samp
+@item psnr (@emph{0})
+PSNR as distortion metric
+
+@item ssim (@emph{1})
+SSIM as distortion metric
+@end table
+
 @item lag-in-frames
 Set the maximum number of frames which the encoder may keep in flight
 at any one time for lookahead purposes.  Defaults to the internal
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..7fd624c470 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 tune;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -132,6 +133,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AOME_SET_TUNING]   = "AOME_SET_TUNING",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -699,6 +701,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
+if (ctx->tune >= 0)
+codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
@@ -1096,6 +1100,9 @@ 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"},
+{ "tune","The metric that encoder tunes for", OFFSET(tune), 
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE, "tune"},
+{ "psnr","PSNR as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "tune"},
+{ "ssim","SSIM as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune"},
 { NULL },
 };
 
-- 
2.25.0.265.gbab2e86ba0-goog

___
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: Add super-resolution options to libaom wrapper

2020-03-03 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 39 +++
 libavcodec/libaomenc.c | 38 ++
 2 files changed, 77 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 4215f237bd..ac00c305d5 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1608,6 +1608,45 @@ Enable the use of global motion for block prediction. 
Default is true.
 Enable block copy mode for intra block prediction. This mode is
 useful for screen content. Default is true.
 
+@item enable-superres (@emph{boolean})
+Enable super-resolution during the encoding process.
+
+@item superres-mode (@emph{mode})
+Select super-resultion mode
+
+@table @option
+@item none (@emph{0})
+No frame superres allowed
+
+@item fixed (@emph{1})
+All frames are coded at the specified scale and super-resolved
+
+@item random (@emph{2})
+All frames are coded at a random scale and super-resolved.
+
+@item qthresh (@emph{3})
+Superres scale for a frame is determined based on q_index
+
+@item auto (@emph{4})
+Automatically select superres for appropriate frames
+@end table
+
+@item superres_denominator
+The denominator for superres to use when @option{superres-mode} is 
@option{fixed}. Valid value 
+ranges from 8 to 16.
+
+@item superres_kf_denominator
+The denominator for superres to use on key frames is fixed when 
+@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16.
+
+@item superres_qthresh
+The q level threshold after which superres is used when @option{superres-mode} 
is 
+@option{qthresh}. Valid value ranges from 1 to 63.
+
+@item superres_kf_qthresh
+The q level threshold after which superres is used for key frames when 
+@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63.
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 7fd624c470..f1578db5e6 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -95,6 +95,12 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int enable_superres;
+int superres_mode;
+int superres_denominator;
+int superres_qthresh;
+int superres_kf_denominator;
+int superres_kf_qthresh;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -134,6 +140,7 @@ static const char *const ctlidstr[] = {
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
 [AOME_SET_TUNING]   = "AOME_SET_TUNING",
+[AV1E_SET_ENABLE_SUPERRES] = "AV1E_SET_ENABLE_SUPERRES",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -203,6 +210,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
width, "tile_width_count:",  cfg->tile_width_count,
width, "tile_height_count:", cfg->tile_height_count);
 av_log(avctx, level, "\n");
+av_log(avctx, level, "super resolution settings\n"
+ "%*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  ",
+   width, "rc_superres_mode:",  cfg->rc_superres_mode,
+   width, "rc_superres_denominator:",cfg->rc_superres_denominator,
+   width, "rc_superres_qthresh:", cfg->rc_superres_qthresh,
+   width, "rc_superres_kf_denominator:", 
cfg->rc_superres_kf_denominator,
+   width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh);
 }
 
 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
@@ -545,6 +559,17 @@ static av_cold int aom_init(AVCodecContext *avctx,
 return AVERROR(EINVAL);
 }
 
+if (ctx->superres_mode >= 0)
+  enccfg.rc_superres_mode = ctx->superres_mode;
+if (ctx->superres_qthresh > 0)
+  enccfg.rc_superres_qthresh = ctx->superres_qthresh;
+if (ctx->superres_kf_qthresh > 0)
+  enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh;
+if (ctx->superres_denominator >= 0)
+  enccfg.rc_superres_denominator = ctx->superres_denominator;
+if (ctx->superres_kf_denominator >= 0)
+  enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator;
+
 dump_enc_cfg(avctx, );
 
 enccfg.g_w= avctx->width;
@@ -687,6 +712,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 // codec control failures are currently treated only as warnings
 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
+if (ctx->enable_superres >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, ctx->enable_superres);
 if (ctx->auto_alt_ref >= 0)
 codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
 if (ctx->arnr_max_frames >= 0)
@@ -1103,6 +1130,17 @@ static const AVOpti

[FFmpeg-devel] [PATCH] Add a libaom command-line opton 'tune'

2020-03-03 Thread Wang Cao
From: Wang Cao 

Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 11 +++
 libavcodec/libaomenc.c |  7 +++
 2 files changed, 18 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index e23b6b32fe..a9f5c9fd28 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1508,6 +1508,17 @@ Complexity-based.
 Cyclic refresh.
 @end table
 
+@item tune (@emph{tune}
+Set the distortion metric tuned with for encoder. Default is PSNR.
+
+@table @samp
+@item psnr (@emph{0})
+PSNR as distortion metric
+
+@item ssim (@emph{1})
+SSIM as distortion metric
+@end table
+
 @item lag-in-frames
 Set the maximum number of frames which the encoder may keep in flight
 at any one time for lookahead purposes.  Defaults to the internal
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 096aadbe1c..688201f0d6 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 tune;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -132,6 +133,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_ENABLE_INTRABC]   = "AV1E_SET_ENABLE_INTRABC",
 #endif
 [AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AOME_SET_TUNING] = "AOME_SET_TUNING",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -699,6 +701,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
+if (ctx->tune >= 0)
+codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
 
 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
@@ -1096,6 +1100,9 @@ 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"},
+{ "tune","The metric that encoder tunes for", OFFSET(tune), 
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE, "tune"},
+{ "psnr","PSNR as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "tune"},
+{ "ssim","SSIM as distortion metric", 0, 
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune"},
 { NULL },
 };
 
-- 
2.25.0.265.gbab2e86ba0-goog

___
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] Add a commandline option to control loop restoration for libaom

2019-12-23 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 doc/encoders.texi  | 3 +++
 libavcodec/libaomenc.c | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 4ee518a124..56b36c156b 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1587,6 +1587,9 @@ Enable row based multi-threading. Disabled by default.
 Enable Constrained Directional Enhancement Filter. The libaom-av1
 encoder enables CDEF by default.
 
+@item enable-restoration (@emph{boolean})
+Enable Loop Restoration Filter. Default is true for libaom-av1.
+
 @item enable-global-motion (@emph{boolean})
 Enable the use of global motion for block prediction. Default is true.
 
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index e06697c1bf..41a250302d 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -92,6 +92,7 @@ typedef struct AOMEncoderContext {
 int enable_cdef;
 int enable_global_motion;
 int enable_intrabc;
+int enable_restoration;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -110,6 +111,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_SUPERBLOCK_SIZE]  = "AV1E_SET_SUPERBLOCK_SIZE",
 [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
 [AV1E_SET_TILE_ROWS]= "AV1E_SET_TILE_ROWS",
+[AV1E_SET_ENABLE_RESTORATION] = "AV1E_SET_ENABLE_RESTORATION",
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
 [AV1E_SET_ROW_MT]   = "AV1E_SET_ROW_MT",
 #endif
@@ -688,6 +690,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_ARNR_STRENGTH,ctx->arnr_strength);
 if (ctx->enable_cdef >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, ctx->enable_cdef);
+if (ctx->enable_restoration >= 0)
+  codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION, 
ctx->enable_restoration);
+
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
@@ -1084,6 +1089,7 @@ static const AVOption options[] = {
 { "enable-cdef",  "Enable CDEF filtering", 
OFFSET(enable_cdef),AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-global-motion",  "Enable global motion", 
OFFSET(enable_global_motion), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-intrabc",  "Enable intra block copy prediction mode", 
OFFSET(enable_intrabc), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+{ "enable-restoration",  "Enable Loop Restoration filtering",  
   OFFSET(enable_restoration),AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { NULL },
 };
 
-- 
2.24.1.735.g03f4e72817-goog

___
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] Add a commandline option to control loop restoration for libaom

2019-12-18 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 libavcodec/libaomenc.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index e06697c1bf..41a250302d 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -92,6 +92,7 @@ typedef struct AOMEncoderContext {
 int enable_cdef;
 int enable_global_motion;
 int enable_intrabc;
+int enable_restoration;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
@@ -110,6 +111,7 @@ static const char *const ctlidstr[] = {
 [AV1E_SET_SUPERBLOCK_SIZE]  = "AV1E_SET_SUPERBLOCK_SIZE",
 [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
 [AV1E_SET_TILE_ROWS]= "AV1E_SET_TILE_ROWS",
+[AV1E_SET_ENABLE_RESTORATION] = "AV1E_SET_ENABLE_RESTORATION",
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
 [AV1E_SET_ROW_MT]   = "AV1E_SET_ROW_MT",
 #endif
@@ -688,6 +690,9 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_ARNR_STRENGTH,ctx->arnr_strength);
 if (ctx->enable_cdef >= 0)
 codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, ctx->enable_cdef);
+if (ctx->enable_restoration >= 0)
+  codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION, 
ctx->enable_restoration);
+
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if (ctx->crf >= 0)
 codecctl_int(avctx, AOME_SET_CQ_LEVEL,  ctx->crf);
@@ -1084,6 +1089,7 @@ static const AVOption options[] = {
 { "enable-cdef",  "Enable CDEF filtering", 
OFFSET(enable_cdef),AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-global-motion",  "Enable global motion", 
OFFSET(enable_global_motion), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-intrabc",  "Enable intra block copy prediction mode", 
OFFSET(enable_intrabc), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+{ "enable-restoration",  "Enable Loop Restoration filtering",  
   OFFSET(enable_restoration),AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { NULL },
 };
 
-- 
2.24.1.735.g03f4e72817-goog

___
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] ffmpeg.c: add an option "detail_stats" to allow ffmpeg to output stats for each stream

2018-11-12 Thread Wang Cao
Friendly ping!

On Tue, Oct 16, 2018 at 3:39 PM Wang Cao  wrote:

> From: Wang Cao 
>
> - Add an option "detail_stats" to ffmpeg to output stats for each
> video/audio streams and each ouptut file ffmpeg output log in print_report.
> - Make print_final_stats only output stats for one output instead of
> aggregate stats.
>
> Signed-off-by: Wang Cao 
> ---
> When creating multiple outputs, the original was to aggregate size of
> all output files together and I find this may not be intuitive to
> users and choose to output the stats for the first output file instead.
> Using -detail_stats to ouptut stats for other output files.
>
>  doc/ffmpeg.texi  |  4 +++
>  fftools/ffmpeg.c | 72 +++-
>  fftools/ffmpeg.h |  1 +
>  fftools/ffmpeg_opt.c |  4 ++-
>  4 files changed, 59 insertions(+), 22 deletions(-)
>
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index 3717f22d42..53a5be9791 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output
> formats to be rtp).
>  Allows discarding specific streams or frames of streams at the demuxer.
>  Not all demuxers support this.
>
> +@item -detail_stats (@emph{global})
> +Allows printing stats for each output stream and output file at the end of
> +processing.
> +
>  @table @option
>  @item none
>  Discard no frame.
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index da4259a9a8..7286e75c36 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -1530,17 +1530,31 @@ static int reap_filters(int flush)
>  return 0;
>  }
>
> -static void print_final_stats(int64_t total_size)
> +static void print_final_stats()
>  {
>  uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size =
> 0;
>  uint64_t subtitle_size = 0;
>  uint64_t data_size = 0;
> +int64_t total_size;
>  float percent = -1.0;
>  int i, j;
>  int pass1_used = 1;
> -
> -for (i = 0; i < nb_output_streams; i++) {
> +int nb_display_streams = 0;
> +AVFormatContext *oc;
> +
> +if (nb_output_streams > 0) {
> +nb_display_streams = enable_detail_stats ? nb_output_streams : 1;
> +}
> +for (i = 0; i < nb_display_streams; i++) {
>  OutputStream *ost = output_streams[i];
> +if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
> +video_size = 0;
> +audio_size = 0;
> +extra_size = 0;
> +other_size = 0;
> +subtitle_size = 0;
> +data_size = 0;
> +}
>  switch (ost->enc_ctx->codec_type) {
>  case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
>  case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
> @@ -1552,7 +1566,13 @@ static void print_final_stats(int64_t total_size)
>  if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 |
> AV_CODEC_FLAG_PASS2))
>  != AV_CODEC_FLAG_PASS1)
>  pass1_used = 0;
> -}
> +
> +// Print stats for each output file.
> +if (i == nb_display_streams-1 || ost->file_index !=
> output_streams[i+1]->file_index) {
> +oc = output_files[ost->file_index]->ctx;
> +total_size =  avio_size(oc->pb);
> +if (total_size <= 0) // FIXME improve avio_size() so it works
> with non seekable output too
> +total_size = avio_tell(oc->pb);
>
>  if (data_size && total_size>0 && total_size >= data_size)
>  percent = 100.0 * (total_size - data_size) / data_size;
> @@ -1568,6 +1588,8 @@ static void print_final_stats(int64_t total_size)
>  else
>  av_log(NULL, AV_LOG_INFO, "unknown");
>  av_log(NULL, AV_LOG_INFO, "\n");
> +}
> +}
>
>  /* print verbose per-stream stats */
>  for (i = 0; i < nb_input_files; i++) {
> @@ -1680,16 +1702,18 @@ static void print_report(int is_last_report,
> int64_t timer_start, int64_t cur_ti
>
>  t = (cur_time-timer_start) / 100.0;
>
> -
> -oc = output_files[0]->ctx;
> -
> -total_size = avio_size(oc->pb);
> -if (total_size <= 0) // FIXME improve avio_size() so it works with
> non seekable output too
> -total_size = avio_tell(oc->pb);
> -
>  vid = 0;
>  av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
>  av_bprint_init(_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
> +
> +/* need to collect final pts upfront because final stats depend on
> pts*/
> +for (i = 0; i &

[FFmpeg-devel] [PATCH] ffmpeg.c: add an option "detail_stats" to allow ffmpeg to output stats for each stream

2018-10-16 Thread Wang Cao
From: Wang Cao 

- Add an option "detail_stats" to ffmpeg to output stats for each
video/audio streams and each ouptut file ffmpeg output log in print_report.
- Make print_final_stats only output stats for one output instead of
aggregate stats.

Signed-off-by: Wang Cao 
---
When creating multiple outputs, the original was to aggregate size of
all output files together and I find this may not be intuitive to
users and choose to output the stats for the first output file instead.
Using -detail_stats to ouptut stats for other output files.

 doc/ffmpeg.texi  |  4 +++
 fftools/ffmpeg.c | 72 +++-
 fftools/ffmpeg.h |  1 +
 fftools/ffmpeg_opt.c |  4 ++-
 4 files changed, 59 insertions(+), 22 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 3717f22d42..53a5be9791 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output formats 
to be rtp).
 Allows discarding specific streams or frames of streams at the demuxer.
 Not all demuxers support this.
 
+@item -detail_stats (@emph{global})
+Allows printing stats for each output stream and output file at the end of
+processing.
+
 @table @option
 @item none
 Discard no frame.
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index da4259a9a8..7286e75c36 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1530,17 +1530,31 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats()
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
-
-for (i = 0; i < nb_output_streams; i++) {
+int nb_display_streams = 0;
+AVFormatContext *oc;
+
+if (nb_output_streams > 0) {
+nb_display_streams = enable_detail_stats ? nb_output_streams : 1;
+}
+for (i = 0; i < nb_display_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1552,7 +1566,13 @@ static void print_final_stats(int64_t total_size)
 if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
-}
+
+// Print stats for each output file.
+if (i == nb_display_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx;
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
 
 if (data_size && total_size>0 && total_size >= data_size)
 percent = 100.0 * (total_size - data_size) / data_size;
@@ -1568,6 +1588,8 @@ static void print_final_stats(int64_t total_size)
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+}
+}
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1680,16 +1702,18 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
+
+/* need to collect final pts upfront because final stats depend on pts*/
+for (i = 0; i < nb_output_streams; i++) {
+ost = output_streams[i];
+/* compute min output value */
+if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE)
+pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st),
+  ost->st->time_base, AV_TIME_BASE_Q));
+}
 for (i = 0; i < nb_output_streams; i++) {
 float q = -1;
 ost = output_streams[i];
@@ -1697,12 +1721,14 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-   

[FFmpeg-devel] [PATCH] ffmpeg.c: add an option "detail_stats" to allow ffmpeg to output stats for each stream

2018-08-28 Thread Wang Cao
From: Wang Cao 

Add an option "detail_stats" to ffmpeg to output stats for each video/audio 
streams and each ouptut file ffmpeg output log in print_report. The format of 
stats is unchanged.

Signed-off-by: Wang Cao 
---
Run after "make fate" and all tests passed.
 doc/ffmpeg.texi  |  4 
 fftools/ffmpeg.c | 56 +++-
 fftools/ffmpeg.h |  1 +
 fftools/ffmpeg_opt.c |  4 +++-
 4 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 3717f22d42..53a5be9791 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output formats 
to be rtp).
 Allows discarding specific streams or frames of streams at the demuxer.
 Not all demuxers support this.
 
+@item -detail_stats (@emph{global})
+Allows printing stats for each output stream and output file at the end of
+processing.
+
 @table @option
 @item none
 Discard no frame.
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2459374f08..c268be20d4 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1530,17 +1530,31 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats()
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
-
-for (i = 0; i < nb_output_streams; i++) {
+int nb_display_streams = 0;
+AVFormatContext *oc;
+
+if (nb_output_streams > 0) {
+nb_display_streams = enable_detail_stats ? nb_output_streams : 1;
+}
+for (i = 0; i < nb_display_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1552,7 +1566,13 @@ static void print_final_stats(int64_t total_size)
 if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
-}
+
+// Print stats for each output file.
+if (i == nb_output_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx;
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
 
 if (data_size && total_size>0 && total_size >= data_size)
 percent = 100.0 * (total_size - data_size) / data_size;
@@ -1568,6 +1588,8 @@ static void print_final_stats(int64_t total_size)
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+}
+}
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1680,13 +1702,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
@@ -1697,12 +1712,14 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 av_bprintf(, "q=%2.1f ", q);
 av_bprintf(_script, "stream_%d_%d_q=%.1f\n",
ost->file_index, ost->index, q);
 }
-if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+// Only print the stats for the first stream during processing
+if ((is_last_report && (enable_detail_stats && vid || !vid)) || 
!is_last_report && !vid) {
+if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 float fps;
 
 frame_number = ost->frame_number;
@@ -1761,7 +1778,9 @@ static void print_report(int is_las

[FFmpeg-devel] [PATCH] ffmpeg.c: add an option "detail_stats" to allow ffmpeg to output stats for each stream

2018-08-23 Thread Wang Cao
From: Wang Cao 

Add an option "detail_stats" to ffmpeg to output stats for each video/audio 
streams and each ouptut file ffmpeg output log in print_report. The format of 
stats is unchanged.

Signed-off-by: Wang Cao 
---
 doc/ffmpeg.texi  |  4 
 fftools/ffmpeg.c | 53 +++-
 fftools/ffmpeg.h |  1 +
 fftools/ffmpeg_opt.c |  4 +++-
 4 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 3717f22d42..53a5be9791 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1623,6 +1623,10 @@ rtp stream. (Requires at least one of the output formats 
to be rtp).
 Allows discarding specific streams or frames of streams at the demuxer.
 Not all demuxers support this.
 
+@item -detail_stats (@emph{global})
+Allows printing stats for each output stream and output file at the end of
+processing.
+
 @table @option
 @item none
 Discard no frame.
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 2459374f08..2bd057ace1 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1530,17 +1530,28 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats()
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
-
-for (i = 0; i < nb_output_streams; i++) {
+int nb_display_streams = enable_detail_stats ? nb_output_streams : 1;
+AVFormatContext *oc;
+
+for (i = 0; i < nb_display_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1552,7 +1563,13 @@ static void print_final_stats(int64_t total_size)
 if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
-}
+
+// Print stats for each output file.
+if (i == nb_output_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx;
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
 
 if (data_size && total_size>0 && total_size >= data_size)
 percent = 100.0 * (total_size - data_size) / data_size;
@@ -1568,6 +1585,8 @@ static void print_final_stats(int64_t total_size)
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+}
+}
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1680,13 +1699,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, AV_BPRINT_SIZE_AUTOMATIC);
@@ -1697,12 +1709,14 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 av_bprintf(, "q=%2.1f ", q);
 av_bprintf(_script, "stream_%d_%d_q=%.1f\n",
ost->file_index, ost->index, q);
 }
-if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+// Only print the stats for the first stream during processing
+if ((is_last_report && (enable_detail_stats && vid || !vid)) || 
!is_last_report && !vid) {
+if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 float fps;
 
 frame_number = ost->frame_number;
@@ -1761,7 +1775,9 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
   ost->st->time_base, AV_TIME_BASE_

Re: [FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-07-16 Thread Wang Cao
> if theres a file with 5 video streams it doesnt make sense to summarize
> teh file with the bitrate of 1 stream
> Also the user has no indication of this change, the number is just different
> theres nothing informing him that it is no longer the files bitrate

I was thinking to output stats for each video/audio stream one line by
another. It seems this would be a huge change to users who are not
aware. Keeping the old file bitrate looks good to me. Can I extend
this to output file bitrate for each output file?
-- 
Wang Cao
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-07-12 Thread Wang Cao
>
> I believe users will expect that "size" shows the file size, especially
> since this was done for more than a decade.

If this is the convention, I believe it should be kept as it was. On the
other hand, I believe
"bitrate" should be calculated through stream size not the file size.

On Thu, Jul 12, 2018 at 2:18 PM Carl Eugen Hoyos  wrote:

> 2018-07-12 20:56 GMT+02:00, Wang Cao :
>
> > After my change:
> >
> >> frame=3 fps=0.0 q=2.0 Lsize=  51kB time=00:00:00.12
> >> bitrate=3495.7kbits/s speed=  12x
> >
> > Before my change(master branch)
> >
> >> frame=3 fps=0.0 q=2.0 Lsize=  57kB time=00:00:00.12
> >> bitrate=3884.7kbits/s speed=11.2x
> >
> > The size is different (51 vs 57) because I display the stream
> > size instead of the total file size. I think stream size
> > is more suitable in this context with "frame, fps, time".
> > For bitrate, I use the stream size to calculate it and I think
> > it's more accurate.
>
> I believe users will expect that "size" shows the file size, especially
> since this was done for more than a decade.
>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


-- 
Wang Cao
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-07-12 Thread Wang Cao
Sorry I probably confused you a little bit. I was not suggesting removing
anything. I tried to convince you that
there is some issue with the bitrate calculation.

From your original comments:

> This changes the printed values
> ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -qscale 2  -vframes 3 -an
> test2.avi
> frame=3 fps=0.0 q=2.0 Lsize=  51kB time=00:00:00.12
> bitrate=3495.7kbits/s speed=  12x
> video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
> muxing overhead: 11.128063%
> vs.
> frame=3 fps=0.0 q=2.0 Lsize=  57kB time=00:00:00.12
> bitrate=3884.7kbits/s speed=11.2x
> video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
> muxing overhead: 11.128063%
> the file is the same


After my change:

> frame=3 fps=0.0 q=2.0 Lsize=  51kB time=00:00:00.12
> bitrate=3495.7kbits/s speed=  12x

Before my change(master branch)

> frame=3 fps=0.0 q=2.0 Lsize=  57kB time=00:00:00.12
> bitrate=3884.7kbits/s speed=11.2x

The size is different (51 vs 57) because I display the stream size instead
of the total file size. I think stream size
is more suitable in this context with "frame, fps, time".
For bitrate, I use the stream size to calculate it and I think it's more
accurate.


On Thu, Jul 12, 2018 at 5:01 AM Michael Niedermayer 
wrote:

> On Wed, Jul 11, 2018 at 03:47:45PM -0700, Wang Cao wrote:
> > >
> > > This changes the printed values
> > > ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -qscale 2  -vframes 3 -an
> > > test2.avi
> > > frame=3 fps=0.0 q=2.0 Lsize=  51kB time=00:00:00.12
> > > bitrate=3495.7kbits/s speed=  12x
> > > video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
> > > muxing overhead: 11.128063%
> > > vs.
> > > frame=3 fps=0.0 q=2.0 Lsize=  57kB time=00:00:00.12
> > > bitrate=3884.7kbits/s speed=11.2x
> > > video:51kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
> > > muxing overhead: 11.128063%
> > > the file is the same
> >
> >
> > Thanks for pointing this out! I have noticed the change in the stats but
> I
> > think the change is correct. Before my patch, the bitrate calculation is
> > based on total_size as in
> >
> > > oc = output_files[0]->ctx;
> > > total_size = avio_size(oc->pb);
> >
> > If I understand this correctly, the size of whole file will be used to
> > calculate the bitrate which considers probably header overhead.
> >
> > I changed it to
> >
> > > total_size = ost->data_size;
> >
> > Therefore only the size of the stream under consideration will be used
> for
> > calculation.
> >
> > Please correct me if my understanding is wrong. Thanks!
>
> Do i understand correctly that you suggest to remove the display of the
> filesize and file bitrate ?
> And in its place would be a display of a randomly picked stream bitrate ?
>
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> If you fake or manipulate statistics in a paper in physics you will never
> get a job again.
> If you fake or manipulate statistics in a paper in medicin you will get
> a job for life at the pharma industry.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


-- 
Wang Cao
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-06-28 Thread Wang Cao
Friendly ping. Thanks!
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] (no subject)

2018-06-28 Thread Wang Cao
I created a newer version to change "MPEG" to "LIMITED" and "JPEG" to
"FULL".


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


[FFmpeg-devel] [PATCH] libavformat/yuv4mpeg: Add color range support for Y4M Add color_range support in Y4M.

2018-06-28 Thread Wang Cao
Set pixel format and color_range for YUVJ pixel formats. Also set
color_range based on AVFormatContext.

Signed-off-by: Wang Cao 
---
 libavformat/yuv4mpegdec.c |  8 
 libavformat/yuv4mpegenc.c | 37 +++--
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c
index eff7fc518e..855fadbb31 100644
--- a/libavformat/yuv4mpegdec.c
+++ b/libavformat/yuv4mpegdec.c
@@ -41,6 +41,7 @@ static int yuv4_read_header(AVFormatContext *s)
 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE, alt_pix_fmt = 
AV_PIX_FMT_NONE;
 enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
 enum AVFieldOrder field_order = AV_FIELD_UNKNOWN;
+enum AVColorRange color_range = AVCOL_RANGE_UNSPECIFIED;
 AVStream *st;
 
 for (i = 0; i < MAX_YUV4_HEADER; i++) {
@@ -220,6 +221,12 @@ static int yuv4_read_header(AVFormatContext *s)
 alt_pix_fmt = AV_PIX_FMT_YUV422P;
 else if (strncmp("444", tokstart, 3) == 0)
 alt_pix_fmt = AV_PIX_FMT_YUV444P;
+} else if (strncmp("COLORRANGE=", tokstart, 11) == 0) {
+  tokstart += 11;
+  if (strncmp("FULL",tokstart, 4) == 0)
+  color_range = AVCOL_RANGE_JPEG;
+  else if (strncmp("LIMITED", tokstart, 7) == 0)
+  color_range = AVCOL_RANGE_MPEG;
 }
 while (tokstart < header_end && *tokstart != 0x20)
 tokstart++;
@@ -263,6 +270,7 @@ static int yuv4_read_header(AVFormatContext *s)
 st->codecpar->codec_id= AV_CODEC_ID_RAWVIDEO;
 st->sample_aspect_ratio   = (AVRational){ aspectn, aspectd };
 st->codecpar->chroma_location = chroma_sample_location;
+st->codecpar->color_range = color_range;
 st->codecpar->field_order = field_order;
 s->packet_size = av_image_get_buffer_size(st->codecpar->format, width, 
height, 1) + Y4M_FRAME_MAGIC_LEN;
 if ((int) s->packet_size < 0)
diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c
index 44f40bbad9..e84dbf9568 100644
--- a/libavformat/yuv4mpegenc.c
+++ b/libavformat/yuv4mpegenc.c
@@ -33,6 +33,7 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
 int raten, rated, aspectn, aspectd, n;
 char inter;
 const char *colorspace = "";
+const char *colorrange = "";
 int field_order;
 
 st = s->streams[0];
@@ -57,6 +58,17 @@ static int yuv4_generate_header(AVFormatContext *s, char* 
buf)
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
+switch(st->codecpar->color_range) {
+case AVCOL_RANGE_MPEG:
+colorrange = " XCOLORRANGE=LIMITED";
+break;
+case AVCOL_RANGE_JPEG:
+colorrange = " XCOLORRANGE=FULL";
+break;
+default:
+break;
+}
+
 switch (field_order) {
 case AV_FIELD_TB:
 case AV_FIELD_TT: inter = 't'; break;
@@ -84,6 +96,18 @@ static int yuv4_generate_header(AVFormatContext *s, char* 
buf)
 case AV_PIX_FMT_YUV411P:
 colorspace = " C411 XYSCSS=411";
 break;
+case AV_PIX_FMT_YUVJ420P:
+colorspace = " C420jpeg XYSCSS=420JPEG";
+colorrange = " XCOLORRANGE=FULL";
+break;
+case AV_PIX_FMT_YUVJ422P:
+colorspace = " C422 XYSCSS=422";
+colorrange = " XCOLORRANGE=FULL";
+break;
+case AV_PIX_FMT_YUVJ444P:
+colorspace = " C444 XYSCSS=444";
+colorrange = " XCOLORRANGE=FULL";
+break;
 case AV_PIX_FMT_YUV420P:
 switch (st->codecpar->chroma_location) {
 case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; 
break;
@@ -145,13 +169,14 @@ static int yuv4_generate_header(AVFormatContext *s, char* 
buf)
 }
 
 /* construct stream header, if this is the first frame */
-n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
+n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s%s\n",
  Y4M_MAGIC, width, height, raten, rated, inter,
- aspectn, aspectd, colorspace);
+ aspectn, aspectd, colorspace, colorrange);
 
 return n;
 }
 
+
 static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
 AVStream *st = s->streams[pkt->stream_index];
@@ -192,6 +217,10 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 case AV_PIX_FMT_YUV420P:
 case AV_PIX_FMT_YUV422P:
 case AV_PIX_FMT_YUV444P:
+// TODO: remove YUVJ pixel formats when they are completely removed from 
the codebase.
+case AV_PIX_FMT_YUVJ420P:
+case AV_PIX_FMT_YUVJ422P:
+case AV_PIX_FMT_YUVJ444P:
 break;
 case AV_PIX_FMT_GRA

Re: [FFmpeg-devel] [PATCH] libavformat/yuv4mpeg: Add color range support for Y4M Add color_range support in Y4M. Also set pixel format and color_range for YUVJ pixel formats.

2018-06-28 Thread Wang Cao
>
> If this is a type we are choosing then it would be probably better
> to use something else than mpeg/jpeg as names
> these are 2 standard comittees and their standards support more than
> one color range.
> maybe "full" and "limited" or some other terms may be better

Thanks for pointing out this. I feel "MPEG" and "JPEG" is more consistent
with the defined variable names (.e.g AVCOL_RANGE_MPEG and
AVCOL_RANGE_JPEG). If you think "FULL" and "LIMITED" look better to you, it
also looks good to me not to use "MPEG" and "JPEG" names.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-06-22 Thread Wang Cao
Make ffmpeg to output stats for each video/audio streams and each ouptut file 
ffmpeg output log in print_report. The report of video/audio sizes is clear now 
as previously all output video/audio sizes were combined to report and it is 
unclear such stats is for one output files or aggregates for all output files.

Signed-off-by: Wang Cao 
---
 fftools/ffmpeg.c | 52 +---
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d4ac6903cc..321f7a6017 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1530,17 +1530,27 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats(void)
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
+AVFormatContext *oc;
 
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1552,7 +1562,13 @@ static void print_final_stats(int64_t total_size)
 if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
-}
+
+// Print stats for each output file.
+if (i == nb_output_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx; 
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
 
 if (data_size && total_size>0 && total_size >= data_size)
 percent = 100.0 * (total_size - data_size) / data_size;
@@ -1568,6 +1584,8 @@ static void print_final_stats(int64_t total_size)
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+}
+}
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1651,7 +1669,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 {
 AVBPrint buf, buf_script;
 OutputStream *ost;
-AVFormatContext *oc;
 int64_t total_size;
 AVCodecContext *enc;
 int frame_number, vid, i;
@@ -1680,13 +1697,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, 1);
@@ -1697,12 +1707,13 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 av_bprintf(, "q=%2.1f ", q);
 av_bprintf(_script, "stream_%d_%d_q=%.1f\n",
ost->file_index, ost->index, q);
 }
-if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report || !is_last_report && !vid) {
+if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 float fps;
 
 frame_number = ost->frame_number;
@@ -1759,9 +1770,11 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE)
 pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st),
   ost->st->time_base, AV_TIME_BASE_Q));
-if (is_last_report)
+if (is_last_report) {
 nb_frames_drop += ost->last_dropped;
-}
+}
+
+total_size = ost->data_size;
 
 secs = FFABS(pts) / AV_TIME_BASE;
 us = FFABS(pts) % AV_TIME_BASE;
@@ -1815,8 +1828,15 @@ static void print_report(int is_last_report, int6

[FFmpeg-devel] (no subject)

2018-06-22 Thread Wang Cao
Thanks for pointing this out. I have modified the code according to your
comments.


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


Re: [FFmpeg-devel] [PATCH] libavformat/yuv4mpeg: Add color range support for Y4M Add color_range support in Y4M. Also set pixel format and color_range for YUVJ pixel formats.

2018-06-22 Thread Wang Cao
>
> My question was which authority defined this metadata for
> y4m? Or which (non-FFmpeg-based) other software
> understands the metadata your patch adds to the files.
>
AFAIK, no other software and authority has defined this metadata
for color range. According to https://linux.die.net/man/5/yuv4mpeg,
we should be able to use X tag to support color range.

Color range would be good to have to give Y4M more capability to
handle HDR(probably) and other pixel formats (.e.g. YUV420P with
full range).
-- 
Wang Cao
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream - Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_repor

2018-06-20 Thread Wang Cao
Thanks for letting me know about this. I actually submitted another patch
without long commit message. I will clean up according to your feedback
after getting feedbacks from other people.

On Sat, Jun 16, 2018 at 2:52 AM Michael Niedermayer 
wrote:

> On Thu, Jun 14, 2018 at 08:35:48PM +0800, Wang Cao wrote:
> > Signed-off-by: Wang Cao 
> > ---
> >  fftools/ffmpeg.c | 45 +++--
> >  1 file changed, 31 insertions(+), 14 deletions(-)
>
> this adds some warnings:
>
> CC  fftools/ffmpeg.o
> fftools/ffmpeg.c:1533:13: warning: function declaration isn’t a prototype
> [-Wstrict-prototypes]
>  static void print_final_stats()
>  ^
> fftools/ffmpeg.c: In function ‘print_report’:
> fftools/ffmpeg.c:1672:22: warning: unused variable ‘oc’ [-Wunused-variable]
>  AVFormatContext *oc;
>   ^
>
> also the commit message should not be one very long line
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> What does censorship reveal? It reveals fear. -- Julian Assange
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


-- 
Wang Cao
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavformat/yuv4mpeg: Add color range support for Y4M Add color_range support in Y4M. Also set pixel format and color_range for YUVJ pixel formats.

2018-06-20 Thread Wang Cao
It's in the yuv4mpegenc.c. I added a support for color range by specifying
metadata in the Y4M header.
On Thu, Jun 14, 2018 at 12:19 AM Carl Eugen Hoyos 
wrote:

> 2018-06-13 18:03 GMT+02:00, Wang Cao :
>
> > @@ -220,6 +221,12 @@ static int yuv4_read_header(AVFormatContext *s)
> >  alt_pix_fmt = AV_PIX_FMT_YUV422P;
> >  else if (strncmp("444", tokstart, 3) == 0)
> >  alt_pix_fmt = AV_PIX_FMT_YUV444P;
> > +} else if (strncmp("COLORRANGE=", tokstart, 11) == 0) {
>
> Where is this specified?

Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


-- 
Wang Cao
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-06-20 Thread Wang Cao
Make ffmpeg to output stats for each video/audio streams and each ouptut file 
ffmpeg output log in print_report. The report of video/audio sizes is clear now 
as previously all output video/audio sizes were combined to report and it is 
unclear such stats is for one output files or aggregates for all output files.

Signed-off-by: Wang Cao 
---
 fftools/ffmpeg.c | 47 +--
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d4ac6903cc..1842ccd543 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1530,17 +1530,27 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats()
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
+AVFormatContext *oc;
 
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1552,7 +1562,13 @@ static void print_final_stats(int64_t total_size)
 if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
-}
+
+// Print stats for each output file.
+if (i == nb_output_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx; 
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
 
 if (data_size && total_size>0 && total_size >= data_size)
 percent = 100.0 * (total_size - data_size) / data_size;
@@ -1568,6 +1584,8 @@ static void print_final_stats(int64_t total_size)
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+}
+}
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1680,13 +1698,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, 1);
@@ -1697,12 +1708,13 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 av_bprintf(, "q=%2.1f ", q);
 av_bprintf(_script, "stream_%d_%d_q=%.1f\n",
ost->file_index, ost->index, q);
 }
-if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report || !is_last_report && !vid) {
+if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 float fps;
 
 frame_number = ost->frame_number;
@@ -1761,7 +1773,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
   ost->st->time_base, AV_TIME_BASE_Q));
 if (is_last_report)
 nb_frames_drop += ost->last_dropped;
-}
+total_size = ost->data_size;
 
 secs = FFABS(pts) / AV_TIME_BASE;
 us = FFABS(pts) % AV_TIME_BASE;
@@ -1815,8 +1827,15 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 av_bprintf(_script, "speed=%4.3gx\n", speed);
 }
 
+if (is_last_report)
+av_bprintf(, "\n");
+   else if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
+av_bprintf(, "\r");
+   }
+}
+
 if (print_stats || is_last_report) {
-const char end = is_last_report ? '\n' : '\r';
+const char end = '\r';
 if (print_stat

[FFmpeg-devel] (no subject)

2018-06-20 Thread Wang Cao
For example: with (-psnr)
frame=  450 fps=315 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB 
time=00:00:15.01 bitrate= 210.0kbits/s speed=10.5x (video stats)
size= 107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=10.6x (audio stats)

frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB 
time=00:00:15.01 bitrate= 210.0kbits/s speed=3.74x
size= 107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
q=0.0 frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 
385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x
size= 107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
q=0.0 frame=  450 fps=112 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 
385kB time=00:00:15.13 bitrate= 208.4kbits/s speed=3.77x
size= 107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=3.77x
video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB 
muxing overhead: 1.880871%
video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB 
muxing overhead: 1.880871%
video:385kB audio:107kB subtitle:0kB other streams:0kB global headers:0kB 
muxing overhead: 1.880871%



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


[FFmpeg-devel] (no subject)

2018-06-20 Thread Wang Cao
For example: with (-psnr)
frame=  450 fps=315 q=0.0 LPSNR=Y:44.15 U:43.21 V:42.36 *:43.64 size= 385kB 
time=00:00:15.01 bitrate= 210.0kbits/s speed=10.5x (video stats)
size= 107kB time=00:00:15.13 bitrate=  58.0kbits/s speed=10.6x (audio stats)

If there are multiple files, stats of the second output would be concatenated
after the first one. Is this a acceptable behavior?

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


[FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-06-14 Thread Wang Cao
Make ffmpeg to output stats for each video/audio streams and each ouptut file 
ffmpeg output log in print_report. The report of video/audio sizes is clear now 
as previously all output video/audio sizes were combined to report and it is 
unclear such stats is for one output files or aggregates for all output files.

Signed-off-by: Wang Cao 
---
 fftools/ffmpeg.c | 45 +++--
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d4ac6903cc..1eaf344552 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1530,17 +1530,27 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats()
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
+AVFormatContext *oc;
 
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1552,7 +1562,13 @@ static void print_final_stats(int64_t total_size)
 if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
-}
+
+// Print stats for each output file.
+if (i == nb_output_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx; 
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
 
 if (data_size && total_size>0 && total_size >= data_size)
 percent = 100.0 * (total_size - data_size) / data_size;
@@ -1568,6 +1584,8 @@ static void print_final_stats(int64_t total_size)
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+}
+}
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1680,13 +1698,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, 1);
@@ -1697,12 +1708,13 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 av_bprintf(, "q=%2.1f ", q);
 av_bprintf(_script, "stream_%d_%d_q=%.1f\n",
ost->file_index, ost->index, q);
 }
-if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report || !is_last_report && !vid) {
+if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 float fps;
 
 frame_number = ost->frame_number;
@@ -1761,7 +1773,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
   ost->st->time_base, AV_TIME_BASE_Q));
 if (is_last_report)
 nb_frames_drop += ost->last_dropped;
-}
+total_size = ost->data_size;
 
 secs = FFABS(pts) / AV_TIME_BASE;
 us = FFABS(pts) % AV_TIME_BASE;
@@ -1815,8 +1827,13 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 av_bprintf(_script, "speed=%4.3gx\n", speed);
 }
 
+if (is_last_report)
+av_bprintf(, "\n");
+   }
+}
+
 if (print_stats || is_last_report) {
-const char end = is_last_report ? '\n' : '\r';
+const char end = '\r';
 if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
 fprintf(stderr, "%s%c&quo

[FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream - Make ffmpeg to output stats for each video/audio streams and each ouptut file ffmpeg output log in print_report. T

2018-06-14 Thread Wang Cao
Signed-off-by: Wang Cao 
---
 fftools/ffmpeg.c | 45 +++--
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d4ac6903cc..1eaf344552 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1530,17 +1530,27 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats()
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
+AVFormatContext *oc;
 
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1552,7 +1562,13 @@ static void print_final_stats(int64_t total_size)
 if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
-}
+
+// Print stats for each output file.
+if (i == nb_output_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx; 
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
 
 if (data_size && total_size>0 && total_size >= data_size)
 percent = 100.0 * (total_size - data_size) / data_size;
@@ -1568,6 +1584,8 @@ static void print_final_stats(int64_t total_size)
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+}
+}
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1680,13 +1698,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, 1);
@@ -1697,12 +1708,13 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 av_bprintf(, "q=%2.1f ", q);
 av_bprintf(_script, "stream_%d_%d_q=%.1f\n",
ost->file_index, ost->index, q);
 }
-if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report || !is_last_report && !vid) {
+if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 float fps;
 
 frame_number = ost->frame_number;
@@ -1761,7 +1773,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
   ost->st->time_base, AV_TIME_BASE_Q));
 if (is_last_report)
 nb_frames_drop += ost->last_dropped;
-}
+total_size = ost->data_size;
 
 secs = FFABS(pts) / AV_TIME_BASE;
 us = FFABS(pts) % AV_TIME_BASE;
@@ -1815,8 +1827,13 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 av_bprintf(_script, "speed=%4.3gx\n", speed);
 }
 
+if (is_last_report)
+av_bprintf(, "\n");
+   }
+}
+
 if (print_stats || is_last_report) {
-const char end = is_last_report ? '\n' : '\r';
+const char end = '\r';
 if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
 fprintf(stderr, "%s%c", buf.str, end);
 } else
@@ -1841,7 +1858,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 }
 
 if (is_last_report)
-print_final_stats(total_size);
+print_final_stats();
 }
 
 static void ifilter_parameters_from_codecpar(InputFilter *ifilter, 
AVCodecParameters *par)
-- 
2.18.0.rc1.242.g61856ae69a-goog

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


[FFmpeg-devel] [PATCH] libavformat/yuv4mpeg: Add color range support for Y4M Add color_range support in Y4M. Also set pixel format and color_range for YUVJ pixel formats.

2018-06-13 Thread Wang Cao
---
 libavformat/yuv4mpegdec.c |  8 
 libavformat/yuv4mpegenc.c | 37 +++--
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c
index eff7fc518e..86e8673b2f 100644
--- a/libavformat/yuv4mpegdec.c
+++ b/libavformat/yuv4mpegdec.c
@@ -41,6 +41,7 @@ static int yuv4_read_header(AVFormatContext *s)
 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE, alt_pix_fmt = 
AV_PIX_FMT_NONE;
 enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
 enum AVFieldOrder field_order = AV_FIELD_UNKNOWN;
+enum AVColorRange color_range = AVCOL_RANGE_UNSPECIFIED;
 AVStream *st;
 
 for (i = 0; i < MAX_YUV4_HEADER; i++) {
@@ -220,6 +221,12 @@ static int yuv4_read_header(AVFormatContext *s)
 alt_pix_fmt = AV_PIX_FMT_YUV422P;
 else if (strncmp("444", tokstart, 3) == 0)
 alt_pix_fmt = AV_PIX_FMT_YUV444P;
+} else if (strncmp("COLORRANGE=", tokstart, 11) == 0) {
+  tokstart += 11;
+  if (strncmp("JPEG",tokstart, 4) == 0)
+  color_range = AVCOL_RANGE_JPEG;
+  else if (strncmp("MPEG", tokstart, 4) == 0)
+  color_range = AVCOL_RANGE_MPEG;
 }
 while (tokstart < header_end && *tokstart != 0x20)
 tokstart++;
@@ -263,6 +270,7 @@ static int yuv4_read_header(AVFormatContext *s)
 st->codecpar->codec_id= AV_CODEC_ID_RAWVIDEO;
 st->sample_aspect_ratio   = (AVRational){ aspectn, aspectd };
 st->codecpar->chroma_location = chroma_sample_location;
+st->codecpar->color_range = color_range;
 st->codecpar->field_order = field_order;
 s->packet_size = av_image_get_buffer_size(st->codecpar->format, width, 
height, 1) + Y4M_FRAME_MAGIC_LEN;
 if ((int) s->packet_size < 0)
diff --git a/libavformat/yuv4mpegenc.c b/libavformat/yuv4mpegenc.c
index 44f40bbad9..555ef15105 100644
--- a/libavformat/yuv4mpegenc.c
+++ b/libavformat/yuv4mpegenc.c
@@ -33,6 +33,7 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf)
 int raten, rated, aspectn, aspectd, n;
 char inter;
 const char *colorspace = "";
+const char *colorrange = "";
 int field_order;
 
 st = s->streams[0];
@@ -57,6 +58,17 @@ static int yuv4_generate_header(AVFormatContext *s, char* 
buf)
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
+switch(st->codecpar->color_range) {
+case AVCOL_RANGE_MPEG:
+colorrange = " XCOLORRANGE=MPEG";
+break;
+case AVCOL_RANGE_JPEG:
+colorrange = " XCOLORRANGE=JPEG";
+break;
+default:
+break;
+}
+
 switch (field_order) {
 case AV_FIELD_TB:
 case AV_FIELD_TT: inter = 't'; break;
@@ -84,6 +96,18 @@ static int yuv4_generate_header(AVFormatContext *s, char* 
buf)
 case AV_PIX_FMT_YUV411P:
 colorspace = " C411 XYSCSS=411";
 break;
+case AV_PIX_FMT_YUVJ420P:
+colorspace = " C420jpeg XYSCSS=420JPEG";
+colorrange = " XCOLORRANGE=JPEG";
+break;
+case AV_PIX_FMT_YUVJ422P:
+colorspace = " C422 XYSCSS=422";
+colorrange = " XCOLORRANGE=JPEG";
+break;
+case AV_PIX_FMT_YUVJ444P:
+colorspace = " C444 XYSCSS=444";
+colorrange = " XCOLORRANGE=JPEG";
+break;
 case AV_PIX_FMT_YUV420P:
 switch (st->codecpar->chroma_location) {
 case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; 
break;
@@ -145,13 +169,14 @@ static int yuv4_generate_header(AVFormatContext *s, char* 
buf)
 }
 
 /* construct stream header, if this is the first frame */
-n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
+n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s%s\n",
  Y4M_MAGIC, width, height, raten, rated, inter,
- aspectn, aspectd, colorspace);
+ aspectn, aspectd, colorspace, colorrange);
 
 return n;
 }
 
+
 static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
 AVStream *st = s->streams[pkt->stream_index];
@@ -192,6 +217,10 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 case AV_PIX_FMT_YUV420P:
 case AV_PIX_FMT_YUV422P:
 case AV_PIX_FMT_YUV444P:
+// TODO: remove YUVJ pixel formats when they are completely removed from 
the codebase.
+case AV_PIX_FMT_YUVJ420P:
+case AV_PIX_FMT_YUVJ422P:
+case AV_PIX_FMT_YUVJ444P:
 break;
 case AV_PIX_FMT_GRAY9:
 case AV_PIX_FMT_GRAY10:
@@ -271,6 +300,10 @@ static int yuv4_write_header(AVFormatContext *s)
 case AV_PIX_FMT_YUV420P:
 case AV_PIX_FMT_YUV422P:
 case AV_PIX_FMT_YUV444P:
+// TODO: remove YUVJ pixel formats when they are completely removed from 
the codebase.
+case AV_PIX_FMT_YUVJ420P:
+case AV_PIX_FMT_YUVJ422P:
+case AV_PIX_FMT_YUVJ444P:
 

[FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-05-22 Thread Wang Cao
- Make ffmpeg to output stats for each video/audio streams and each ouptut file 
ffmpeg output log in print_report.
- The report of video/audio sizes is clear as previously all output
video/audio sizes were combined to report and it is unclear such stats
is for one output files or aggregates for all output files.

Signed-off-by: Wang Cao <wang...@google.com>
---
 fftools/ffmpeg.c | 65 
 1 file changed, 44 insertions(+), 21 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5a19a09d9a..0b98521852 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1526,17 +1526,28 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats()
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
+AVFormatContext *oc;
 
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
+
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1545,25 +1556,37 @@ static void print_final_stats(int64_t total_size)
 }
 extra_size += ost->enc_ctx->extradata_size;
 data_size  += ost->data_size;
+
 if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
-}
-
+
+// Print stats for each output file.
+if (i == nb_output_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx; 
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
+
 if (data_size && total_size>0 && total_size >= data_size)
 percent = 100.0 * (total_size - data_size) / data_size;
-
+
 av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB 
other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ",
video_size / 1024.0,
audio_size / 1024.0,
subtitle_size / 1024.0,
other_size / 1024.0,
extra_size / 1024.0);
+   
 if (percent >= 0.0)
 av_log(NULL, AV_LOG_INFO, "%f%%", percent);
 else
 av_log(NULL, AV_LOG_INFO, "unknown");
 av_log(NULL, AV_LOG_INFO, "\n");
+}
+}
+
+
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1676,13 +1699,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, 1);
@@ -1693,12 +1709,13 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 av_bprintf(, "q=%2.1f ", q);
 av_bprintf(_script, "stream_%d_%d_q=%.1f\n",
ost->file_index, ost->index, q);
 }
-if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report || !is_last_report && !vid) {
+if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 float fps;
 
 frame_number = ost->frame_number;
@@ -1750,14 +1767,16 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
ost->file_index, ost->index, p);
 }
 vid = 1;
-}
+}
+
 /* compute min output value */
 if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE)
 pts = FFMAX(pts, av_rescale_q(av_stream_get

Re: [FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-05-21 Thread Wang Cao
Sorry the ticket doesn't contain alaw_2.aif as in
https://trac.ffmpeg.org/ticket/1660

On Fri, May 18, 2018 at 8:13 PM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Fri, May 18, 2018 at 04:54:25PM -0700, Wang Cao wrote:
> > - Make ffmpeg to output stats for each video streams and each ouptut
> file ffmpeg output log in print_report.
> > - The report of video/audio sizes is clear as previously all output
> > video/audio sizes were combined to report and it is unclear such stats
> > is for one output files or aggregates for all output files.
> >
> > Signed-off-by: Wang Cao <wang...@google.com>
> > ---
> >  fftools/ffmpeg.c | 182 ++-
> >  1 file changed, 101 insertions(+), 81 deletions(-)
>
> This causes the report to disappear for
> ./ffmpeg -i ~/tickets/1660/alaw_2.aif -f null -
>
> file should be in the ticket on trac, if not, say so and ill figure out
> where
> the file is
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Those who are best at talking, realize last or never when they are wrong.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>


-- 
Wang Cao
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg.c: allow ffmpeg to output stats for each video stream

2018-05-18 Thread Wang Cao
- Make ffmpeg to output stats for each video streams and each ouptut file 
ffmpeg output log in print_report.
- The report of video/audio sizes is clear as previously all output
video/audio sizes were combined to report and it is unclear such stats
is for one output files or aggregates for all output files.

Signed-off-by: Wang Cao <wang...@google.com>
---
 fftools/ffmpeg.c | 182 ++-
 1 file changed, 101 insertions(+), 81 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5a19a09d9a..4aa6c1d3e4 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1526,17 +1526,28 @@ static int reap_filters(int flush)
 return 0;
 }
 
-static void print_final_stats(int64_t total_size)
+static void print_final_stats()
 {
 uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 uint64_t subtitle_size = 0;
 uint64_t data_size = 0;
+int64_t total_size;
 float percent = -1.0;
 int i, j;
 int pass1_used = 1;
+AVFormatContext *oc;
 
 for (i = 0; i < nb_output_streams; i++) {
 OutputStream *ost = output_streams[i];
+if (i > 0 && ost->file_index != output_streams[i-1]->file_index) {
+video_size = 0;
+audio_size = 0;
+extra_size = 0;
+other_size = 0;
+subtitle_size = 0;
+data_size = 0;
+}
+
 switch (ost->enc_ctx->codec_type) {
 case AVMEDIA_TYPE_VIDEO: video_size += ost->data_size; break;
 case AVMEDIA_TYPE_AUDIO: audio_size += ost->data_size; break;
@@ -1545,25 +1556,37 @@ static void print_final_stats(int64_t total_size)
 }
 extra_size += ost->enc_ctx->extradata_size;
 data_size  += ost->data_size;
-if (   (ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | 
AV_CODEC_FLAG_PASS2))
+
+if ((ost->enc_ctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2))
 != AV_CODEC_FLAG_PASS1)
 pass1_used = 0;
+
+// Print stats for each output file.
+if (i == nb_output_streams-1 || ost->file_index != 
output_streams[i+1]->file_index) {
+oc = output_files[ost->file_index]->ctx; 
+total_size =  avio_size(oc->pb);
+if (total_size <= 0) // FIXME improve avio_size() so it works with 
non seekable output too
+total_size = avio_tell(oc->pb);
+
+if (data_size && total_size>0 && total_size >= data_size)
+percent = 100.0 * (total_size - data_size) / data_size;
+
+av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB 
subtitle:%1.0fkB other streams:%1.0fkB global headers:%1.0fkB muxing overhead: 
",
+   video_size / 1024.0,
+   audio_size / 1024.0,
+   subtitle_size / 1024.0,
+   other_size / 1024.0,
+   extra_size / 1024.0);
+   
+if (percent >= 0.0)
+av_log(NULL, AV_LOG_INFO, "%f%%", percent);
+else
+av_log(NULL, AV_LOG_INFO, "unknown");
+av_log(NULL, AV_LOG_INFO, "\n");
+}
 }
 
-if (data_size && total_size>0 && total_size >= data_size)
-percent = 100.0 * (total_size - data_size) / data_size;
 
-av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB subtitle:%1.0fkB 
other streams:%1.0fkB global headers:%1.0fkB muxing overhead: ",
-   video_size / 1024.0,
-   audio_size / 1024.0,
-   subtitle_size / 1024.0,
-   other_size / 1024.0,
-   extra_size / 1024.0);
-if (percent >= 0.0)
-av_log(NULL, AV_LOG_INFO, "%f%%", percent);
-else
-av_log(NULL, AV_LOG_INFO, "unknown");
-av_log(NULL, AV_LOG_INFO, "\n");
 
 /* print verbose per-stream stats */
 for (i = 0; i < nb_input_files; i++) {
@@ -1676,13 +1699,6 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 t = (cur_time-timer_start) / 100.0;
 
-
-oc = output_files[0]->ctx;
-
-total_size = avio_size(oc->pb);
-if (total_size <= 0) // FIXME improve avio_size() so it works with non 
seekable output too
-total_size = avio_tell(oc->pb);
-
 vid = 0;
 av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
 av_bprint_init(_script, 0, 1);
@@ -1693,12 +1709,12 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!ost->stream_copy)
 q = ost->quality / (float) FF_QP2LAMBDA;
 
-if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (is_last_report && vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {