diff mbox series

[FFmpeg-devel] fftools/ffmpeg_filter: add -autoscale to disable/enable the default scale

Message ID 1581734613-15466-1-git-send-email-linjie.fu@intel.com
State Superseded
Headers show
Series [FFmpeg-devel] fftools/ffmpeg_filter: add -autoscale to disable/enable the default scale
Related show

Checks

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

Commit Message

Fu, Linjie Feb. 15, 2020, 2:43 a.m. UTC
Currently, ffmpeg inserts scale filter by default in the filter graph
to force the whole decoded stream to scale into the same size with the
first frame. It's not quite make sense in resolution changing cases if
user wants the rawvideo without any scale.

Using autoscale/noautoscale as an output option to indicate whether auto
inserting the scale filter in the filter graph:
    -noautoscale or -autoscale 0:
    disable the default auto scale filter inserting.

ffmpeg -y input.mp4 out1.yuv -noautoscale out2.yuv -autoscale 0 out3.yuv

Update docs.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---

Using autoscale as an output option and fix the missing spaces.

 doc/ffmpeg.texi         | 16 ++++++++++++----
 fftools/ffmpeg.h        |  3 +++
 fftools/ffmpeg_filter.c |  2 +-
 fftools/ffmpeg_opt.c    |  8 ++++++++
 4 files changed, 24 insertions(+), 5 deletions(-)

Comments

Nicolas George Feb. 15, 2020, 11:01 a.m. UTC | #1
Linjie Fu (12020-02-15):
> Currently, ffmpeg inserts scale filter by default in the filter graph
> to force the whole decoded stream to scale into the same size with the
> first frame. It's not quite make sense in resolution changing cases if
> user wants the rawvideo without any scale.
> 
> Using autoscale/noautoscale as an output option to indicate whether auto
> inserting the scale filter in the filter graph:
>     -noautoscale or -autoscale 0:
>     disable the default auto scale filter inserting.
> 
> ffmpeg -y input.mp4 out1.yuv -noautoscale out2.yuv -autoscale 0 out3.yuv
> 
> Update docs.
> 
> Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
> 
> Using autoscale as an output option and fix the missing spaces.
> 
>  doc/ffmpeg.texi         | 16 ++++++++++++----
>  fftools/ffmpeg.h        |  3 +++
>  fftools/ffmpeg_filter.c |  2 +-
>  fftools/ffmpeg_opt.c    |  8 ++++++++
>  4 files changed, 24 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> index 29753f0..aebafb3 100644
> --- a/doc/ffmpeg.texi
> +++ b/doc/ffmpeg.texi
> @@ -734,10 +734,6 @@ 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 -noautorotate
> -Disable automatically rotating video based on file metadata.
> -
>  @end table
>  
>  @section Video Options
> @@ -819,6 +815,18 @@ Create the filtergraph specified by @var{filtergraph} and use it to
>  filter the stream.
>  
>  This is an alias for @code{-filter:v}, see the @ref{filter_option,,-filter option}.
> +
> +@item -autorotate
> +Automatically rotate the video according to file metadata. Enabled by
> +default, use @option{-noautorotate} to disable it.
> +
> +@item -autoscale
> +Automatically scale the video according to the resolution of first frame.
> +Enabled by default, use @option{-noautoscale} to disable it. When autoscale is
> +disabled, all output frames of filter graph might not be in the same resolution
> +and may be inadequate for some encoder/muxer. Therefore, it is not recommended
> +to disable it unless you really know what you are doing.
> +Disable autoscale at your own risk.
>  @end table
>  
>  @section Advanced Video options
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index 7b6f802..8beba6c 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -230,6 +230,8 @@ typedef struct OptionsContext {
>      int        nb_time_bases;
>      SpecifierOpt *enc_time_bases;
>      int        nb_enc_time_bases;
> +    SpecifierOpt *autoscale;
> +    int        nb_autoscale;
>  } OptionsContext;
>  
>  typedef struct InputFilter {
> @@ -479,6 +481,7 @@ typedef struct OutputStream {
>      int force_fps;
>      int top_field_first;
>      int rotate_overridden;
> +    int autoscale;
>      double rotate_override_value;
>  
>      AVRational frame_aspect_ratio;
> diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
> index 40cc4c1..46c8ea8 100644
> --- a/fftools/ffmpeg_filter.c
> +++ b/fftools/ffmpeg_filter.c
> @@ -469,7 +469,7 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
>      if (ret < 0)
>          return ret;
>  
> -    if (ofilter->width || ofilter->height) {
> +    if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) {
>          char args[255];
>          AVFilterContext *filter;
>          AVDictionaryEntry *e = NULL;
> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 12d4488..62bcfc1 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -1405,6 +1405,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
>          ost->encoder_opts  = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
>  
>          MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
> +        ost->autoscale = 1;
> +        MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
>          if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
>              do  {
>                  buf = get_line(s);
> @@ -3650,6 +3652,12 @@ const OptionDef options[] = {
>      { "autorotate",       HAS_ARG | OPT_BOOL | OPT_SPEC |
>                            OPT_EXPERT | OPT_INPUT,                                { .off = OFFSET(autorotate) },
>          "automatically insert correct rotate filters" },

> +    { "autoscale",        HAS_ARG | OPT_BOOL | OPT_SPEC |
> +                          OPT_EXPERT | OPT_OUTPUT,                               { .off = OFFSET(autoscale) },
> +        "automatically insert a scale filter at the end of the filter graph if a resolution "
> +        "change is detected. This ensures all frames are the same resolution as the first frame "
> +        "when they leave the filter chain (this option is enabled by default). "
> +        "If disabled, some encoders/muxers may not support this mode."},

The help text for most options is half a line. This one is four long
lines. Maybe this is misusing the field: a short summary here, the full
explanation in the doc.

>  
>      /* audio options */
>      { "aframes",        OPT_AUDIO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT,           { .func_arg = opt_audio_frames },

Regards,
Fu, Linjie Feb. 15, 2020, 11:46 a.m. UTC | #2
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Nicolas George
> Sent: Saturday, February 15, 2020 19:01
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Cc: Fu, Linjie <linjie.fu@intel.com>; Eoff, Ullysses A
> <ullysses.a.eoff@intel.com>
> Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_filter: add -autoscale
> to disable/enable the default scale
> 
> Linjie Fu (12020-02-15):
> > Currently, ffmpeg inserts scale filter by default in the filter graph
> > to force the whole decoded stream to scale into the same size with the
> > first frame. It's not quite make sense in resolution changing cases if
> > user wants the rawvideo without any scale.
> >
> > Using autoscale/noautoscale as an output option to indicate whether auto
> > inserting the scale filter in the filter graph:
> >     -noautoscale or -autoscale 0:
> >     disable the default auto scale filter inserting.
> >
> > ffmpeg -y input.mp4 out1.yuv -noautoscale out2.yuv -autoscale 0 out3.yuv
> >
> > Update docs.
> >
> > Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > ---
> >
> > Using autoscale as an output option and fix the missing spaces.
> >
> >  doc/ffmpeg.texi         | 16 ++++++++++++----
> >  fftools/ffmpeg.h        |  3 +++
> >  fftools/ffmpeg_filter.c |  2 +-
> >  fftools/ffmpeg_opt.c    |  8 ++++++++
> >  4 files changed, 24 insertions(+), 5 deletions(-)
> >
> > diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> > index 29753f0..aebafb3 100644
> > --- a/doc/ffmpeg.texi
> > +++ b/doc/ffmpeg.texi
> > @@ -734,10 +734,6 @@ 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 -noautorotate
> > -Disable automatically rotating video based on file metadata.
> > -
> >  @end table
> >
> >  @section Video Options
> > @@ -819,6 +815,18 @@ Create the filtergraph specified by
> @var{filtergraph} and use it to
> >  filter the stream.
> >
> >  This is an alias for @code{-filter:v}, see the @ref{filter_option,,-filter
> option}.
> > +
> > +@item -autorotate
> > +Automatically rotate the video according to file metadata. Enabled by
> > +default, use @option{-noautorotate} to disable it.
> > +
> > +@item -autoscale
> > +Automatically scale the video according to the resolution of first frame.
> > +Enabled by default, use @option{-noautoscale} to disable it. When
> autoscale is
> > +disabled, all output frames of filter graph might not be in the same
> resolution
> > +and may be inadequate for some encoder/muxer. Therefore, it is not
> recommended
> > +to disable it unless you really know what you are doing.
> > +Disable autoscale at your own risk.
> >  @end table
> >
> >  @section Advanced Video options
> > diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> > index 7b6f802..8beba6c 100644
> > --- a/fftools/ffmpeg.h
> > +++ b/fftools/ffmpeg.h
> > @@ -230,6 +230,8 @@ typedef struct OptionsContext {
> >      int        nb_time_bases;
> >      SpecifierOpt *enc_time_bases;
> >      int        nb_enc_time_bases;
> > +    SpecifierOpt *autoscale;
> > +    int        nb_autoscale;
> >  } OptionsContext;
> >
> >  typedef struct InputFilter {
> > @@ -479,6 +481,7 @@ typedef struct OutputStream {
> >      int force_fps;
> >      int top_field_first;
> >      int rotate_overridden;
> > +    int autoscale;
> >      double rotate_override_value;
> >
> >      AVRational frame_aspect_ratio;
> > diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
> > index 40cc4c1..46c8ea8 100644
> > --- a/fftools/ffmpeg_filter.c
> > +++ b/fftools/ffmpeg_filter.c
> > @@ -469,7 +469,7 @@ static int configure_output_video_filter(FilterGraph
> *fg, OutputFilter *ofilter,
> >      if (ret < 0)
> >          return ret;
> >
> > -    if (ofilter->width || ofilter->height) {
> > +    if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) {
> >          char args[255];
> >          AVFilterContext *filter;
> >          AVDictionaryEntry *e = NULL;
> > diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> > index 12d4488..62bcfc1 100644
> > --- a/fftools/ffmpeg_opt.c
> > +++ b/fftools/ffmpeg_opt.c
> > @@ -1405,6 +1405,8 @@ static OutputStream
> *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
> >          ost->encoder_opts  = filter_codec_opts(o->g->codec_opts, ost->enc-
> >id, oc, st, ost->enc);
> >
> >          MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
> > +        ost->autoscale = 1;
> > +        MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
> >          if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s))))
> {
> >              do  {
> >                  buf = get_line(s);
> > @@ -3650,6 +3652,12 @@ const OptionDef options[] = {
> >      { "autorotate",       HAS_ARG | OPT_BOOL | OPT_SPEC |
> >                            OPT_EXPERT | OPT_INPUT,                                { .off =
> OFFSET(autorotate) },
> >          "automatically insert correct rotate filters" },
> 
> > +    { "autoscale",        HAS_ARG | OPT_BOOL | OPT_SPEC |
> > +                          OPT_EXPERT | OPT_OUTPUT,                               { .off =
> OFFSET(autoscale) },
> > +        "automatically insert a scale filter at the end of the filter graph if a
> resolution "
> > +        "change is detected. This ensures all frames are the same resolution
> as the first frame "
> > +        "when they leave the filter chain (this option is enabled by default). "
> > +        "If disabled, some encoders/muxers may not support this mode."},
> 
> The help text for most options is half a line. This one is four long
> lines. Maybe this is misusing the field: a short summary here, the full
> explanation in the doc.

How about shortening into
"automatically insert a scale filter at the end of the filter graph if a resolution change is detected (enabled by default)."
in the help message and keep the current explanation unchanged in doc?

> Regards,
> 
> --
>   Nicolas George

Thanks for pointing this out.
Paul B Mahol Feb. 15, 2020, 11:49 a.m. UTC | #3
On 2/15/20, Fu, Linjie <linjie.fu@intel.com> wrote:
>> -----Original Message-----
>> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
>> Nicolas George
>> Sent: Saturday, February 15, 2020 19:01
>> To: FFmpeg development discussions and patches <ffmpeg-
>> devel@ffmpeg.org>
>> Cc: Fu, Linjie <linjie.fu@intel.com>; Eoff, Ullysses A
>> <ullysses.a.eoff@intel.com>
>> Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_filter: add -autoscale
>> to disable/enable the default scale
>>
>> Linjie Fu (12020-02-15):
>> > Currently, ffmpeg inserts scale filter by default in the filter graph
>> > to force the whole decoded stream to scale into the same size with the
>> > first frame. It's not quite make sense in resolution changing cases if
>> > user wants the rawvideo without any scale.
>> >
>> > Using autoscale/noautoscale as an output option to indicate whether auto
>> > inserting the scale filter in the filter graph:
>> >     -noautoscale or -autoscale 0:
>> >     disable the default auto scale filter inserting.
>> >
>> > ffmpeg -y input.mp4 out1.yuv -noautoscale out2.yuv -autoscale 0 out3.yuv
>> >
>> > Update docs.
>> >
>> > Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
>> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
>> > ---
>> >
>> > Using autoscale as an output option and fix the missing spaces.
>> >
>> >  doc/ffmpeg.texi         | 16 ++++++++++++----
>> >  fftools/ffmpeg.h        |  3 +++
>> >  fftools/ffmpeg_filter.c |  2 +-
>> >  fftools/ffmpeg_opt.c    |  8 ++++++++
>> >  4 files changed, 24 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
>> > index 29753f0..aebafb3 100644
>> > --- a/doc/ffmpeg.texi
>> > +++ b/doc/ffmpeg.texi
>> > @@ -734,10 +734,6 @@ 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 -noautorotate
>> > -Disable automatically rotating video based on file metadata.
>> > -
>> >  @end table
>> >
>> >  @section Video Options
>> > @@ -819,6 +815,18 @@ Create the filtergraph specified by
>> @var{filtergraph} and use it to
>> >  filter the stream.
>> >
>> >  This is an alias for @code{-filter:v}, see the
>> > @ref{filter_option,,-filter
>> option}.
>> > +
>> > +@item -autorotate
>> > +Automatically rotate the video according to file metadata. Enabled by
>> > +default, use @option{-noautorotate} to disable it.
>> > +
>> > +@item -autoscale
>> > +Automatically scale the video according to the resolution of first
>> > frame.
>> > +Enabled by default, use @option{-noautoscale} to disable it. When
>> autoscale is
>> > +disabled, all output frames of filter graph might not be in the same
>> resolution
>> > +and may be inadequate for some encoder/muxer. Therefore, it is not
>> recommended
>> > +to disable it unless you really know what you are doing.
>> > +Disable autoscale at your own risk.
>> >  @end table
>> >
>> >  @section Advanced Video options
>> > diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
>> > index 7b6f802..8beba6c 100644
>> > --- a/fftools/ffmpeg.h
>> > +++ b/fftools/ffmpeg.h
>> > @@ -230,6 +230,8 @@ typedef struct OptionsContext {
>> >      int        nb_time_bases;
>> >      SpecifierOpt *enc_time_bases;
>> >      int        nb_enc_time_bases;
>> > +    SpecifierOpt *autoscale;
>> > +    int        nb_autoscale;
>> >  } OptionsContext;
>> >
>> >  typedef struct InputFilter {
>> > @@ -479,6 +481,7 @@ typedef struct OutputStream {
>> >      int force_fps;
>> >      int top_field_first;
>> >      int rotate_overridden;
>> > +    int autoscale;
>> >      double rotate_override_value;
>> >
>> >      AVRational frame_aspect_ratio;
>> > diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
>> > index 40cc4c1..46c8ea8 100644
>> > --- a/fftools/ffmpeg_filter.c
>> > +++ b/fftools/ffmpeg_filter.c
>> > @@ -469,7 +469,7 @@ static int configure_output_video_filter(FilterGraph
>> *fg, OutputFilter *ofilter,
>> >      if (ret < 0)
>> >          return ret;
>> >
>> > -    if (ofilter->width || ofilter->height) {
>> > +    if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale)
>> > {
>> >          char args[255];
>> >          AVFilterContext *filter;
>> >          AVDictionaryEntry *e = NULL;
>> > diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
>> > index 12d4488..62bcfc1 100644
>> > --- a/fftools/ffmpeg_opt.c
>> > +++ b/fftools/ffmpeg_opt.c
>> > @@ -1405,6 +1405,8 @@ static OutputStream
>> *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
>> >          ost->encoder_opts  = filter_codec_opts(o->g->codec_opts,
>> > ost->enc-
>> >id, oc, st, ost->enc);
>> >
>> >          MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
>> > +        ost->autoscale = 1;
>> > +        MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
>> >          if (preset && (!(ret = get_preset_file_2(preset,
>> > ost->enc->name, &s))))
>> {
>> >              do  {
>> >                  buf = get_line(s);
>> > @@ -3650,6 +3652,12 @@ const OptionDef options[] = {
>> >      { "autorotate",       HAS_ARG | OPT_BOOL | OPT_SPEC |
>> >                            OPT_EXPERT | OPT_INPUT,
>> >          { .off =
>> OFFSET(autorotate) },
>> >          "automatically insert correct rotate filters" },
>>
>> > +    { "autoscale",        HAS_ARG | OPT_BOOL | OPT_SPEC |
>> > +                          OPT_EXPERT | OPT_OUTPUT,
>> >          { .off =
>> OFFSET(autoscale) },
>> > +        "automatically insert a scale filter at the end of the filter
>> > graph if a
>> resolution "
>> > +        "change is detected. This ensures all frames are the same
>> > resolution
>> as the first frame "
>> > +        "when they leave the filter chain (this option is enabled by
>> > default). "
>> > +        "If disabled, some encoders/muxers may not support this
>> > mode."},
>>
>> The help text for most options is half a line. This one is four long
>> lines. Maybe this is misusing the field: a short summary here, the full
>> explanation in the doc.
>
> How about shortening into
> "automatically insert a scale filter at the end of the filter graph if a
> resolution change is detected (enabled by default)."
> in the help message and keep the current explanation unchanged in doc?

last part in () is redundant.

>
>> Regards,
>>
>> --
>>   Nicolas George
>
> Thanks for pointing this out.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Nicolas George Feb. 15, 2020, 11:51 a.m. UTC | #4
Fu, Linjie (12020-02-15):
> "automatically insert a scale filter at the end of the filter graph if a resolution change is detected (enabled by default)."
> in the help message and keep the current explanation unchanged in doc?

It's still twice as long as most help text. Take example on the other
help texts. Take example on the help text for autorotate!

Regards,
Fu, Linjie Feb. 15, 2020, 12:14 p.m. UTC | #5
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Nicolas George
> Sent: Saturday, February 15, 2020 19:52
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Cc: Eoff, Ullysses A <ullysses.a.eoff@intel.com>
> Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_filter: add -autoscale
> to disable/enable the default scale
> 
> Fu, Linjie (12020-02-15):
> > "automatically insert a scale filter at the end of the filter graph if a
> resolution change is detected (enabled by default)."
> > in the help message and keep the current explanation unchanged in doc?
> 
> It's still twice as long as most help text. Take example on the other
> help texts. Take example on the help text for autorotate!

It's based on some discussions previously talked in [1] to keep it sufficient and not confusing.

To keep it more precise, how about "automatically insert a scale filter at the end of the filter graph." ?

[1] https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190715103835.26634-1-linjie.fu@intel.com/


> Regards,
> 
> --
>   Nicolas George
Gyan Doshi Feb. 15, 2020, 12:36 p.m. UTC | #6
On 15-02-2020 05:44 pm, Fu, Linjie wrote:
>> -----Original Message-----
>> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
>> Nicolas George
>> Sent: Saturday, February 15, 2020 19:52
>> To: FFmpeg development discussions and patches <ffmpeg-
>> devel@ffmpeg.org>
>> Cc: Eoff, Ullysses A <ullysses.a.eoff@intel.com>
>> Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_filter: add -autoscale
>> to disable/enable the default scale
>>
>> Fu, Linjie (12020-02-15):
>>> "automatically insert a scale filter at the end of the filter graph if a
>> resolution change is detected (enabled by default)."
>>> in the help message and keep the current explanation unchanged in doc?
>> It's still twice as long as most help text. Take example on the other
>> help texts. Take example on the help text for autorotate!
> It's based on some discussions previously talked in [1] to keep it sufficient and not confusing.
>
> To keep it more precise, how about "automatically insert a scale filter at the end of the filter graph." ?

This is better. "if a resolution change is detected" isn't accurate 
anyway since filter *insertion* isn't conditional on frame change 
detection, which may happen 1000 frames into the stream.

Also, based on a glance at the patch, this doesn't apply to output 
streams exiting a complex filtergraph, right? Make a note of that.

Thanks,
Gyan
Gyan Doshi Feb. 15, 2020, 12:41 p.m. UTC | #7
On 15-02-2020 06:06 pm, Gyan Doshi wrote:
>
>
> Also, based on a glance at the patch, this doesn't apply to output 
> streams exiting a complex filtergraph, right? Make a note of that.

Scratch that, it does.

Gyan
Fu, Linjie Feb. 15, 2020, 1:01 p.m. UTC | #8
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Gyan Doshi
> Sent: Saturday, February 15, 2020 20:37
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_filter: add -autoscale
> to disable/enable the default scale
> 
> 
> 
> On 15-02-2020 05:44 pm, Fu, Linjie wrote:
> >> -----Original Message-----
> >> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> >> Nicolas George
> >> Sent: Saturday, February 15, 2020 19:52
> >> To: FFmpeg development discussions and patches <ffmpeg-
> >> devel@ffmpeg.org>
> >> Cc: Eoff, Ullysses A <ullysses.a.eoff@intel.com>
> >> Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_filter: add -
> autoscale
> >> to disable/enable the default scale
> >>
> >> Fu, Linjie (12020-02-15):
> >>> "automatically insert a scale filter at the end of the filter graph if a
> >> resolution change is detected (enabled by default)."
> >>> in the help message and keep the current explanation unchanged in doc?
> >> It's still twice as long as most help text. Take example on the other
> >> help texts. Take example on the help text for autorotate!
> > It's based on some discussions previously talked in [1] to keep it sufficient
> and not confusing.
> >
> > To keep it more precise, how about "automatically insert a scale filter at the
> end of the filter graph." ?
> 
> This is better. "if a resolution change is detected" isn't accurate
> anyway since filter *insertion* isn't conditional on frame change
> detection, which may happen 1000 frames into the stream.

Will update like this unless there are better suggestions.
Thanks.
diff mbox series

Patch

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 29753f0..aebafb3 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -734,10 +734,6 @@  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 -noautorotate
-Disable automatically rotating video based on file metadata.
-
 @end table
 
 @section Video Options
@@ -819,6 +815,18 @@  Create the filtergraph specified by @var{filtergraph} and use it to
 filter the stream.
 
 This is an alias for @code{-filter:v}, see the @ref{filter_option,,-filter option}.
+
+@item -autorotate
+Automatically rotate the video according to file metadata. Enabled by
+default, use @option{-noautorotate} to disable it.
+
+@item -autoscale
+Automatically scale the video according to the resolution of first frame.
+Enabled by default, use @option{-noautoscale} to disable it. When autoscale is
+disabled, all output frames of filter graph might not be in the same resolution
+and may be inadequate for some encoder/muxer. Therefore, it is not recommended
+to disable it unless you really know what you are doing.
+Disable autoscale at your own risk.
 @end table
 
 @section Advanced Video options
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7b6f802..8beba6c 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -230,6 +230,8 @@  typedef struct OptionsContext {
     int        nb_time_bases;
     SpecifierOpt *enc_time_bases;
     int        nb_enc_time_bases;
+    SpecifierOpt *autoscale;
+    int        nb_autoscale;
 } OptionsContext;
 
 typedef struct InputFilter {
@@ -479,6 +481,7 @@  typedef struct OutputStream {
     int force_fps;
     int top_field_first;
     int rotate_overridden;
+    int autoscale;
     double rotate_override_value;
 
     AVRational frame_aspect_ratio;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 40cc4c1..46c8ea8 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -469,7 +469,7 @@  static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter,
     if (ret < 0)
         return ret;
 
-    if (ofilter->width || ofilter->height) {
+    if ((ofilter->width || ofilter->height) && ofilter->ost->autoscale) {
         char args[255];
         AVFilterContext *filter;
         AVDictionaryEntry *e = NULL;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 12d4488..62bcfc1 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1405,6 +1405,8 @@  static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
         ost->encoder_opts  = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
 
         MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
+        ost->autoscale = 1;
+        MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
         if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
             do  {
                 buf = get_line(s);
@@ -3650,6 +3652,12 @@  const OptionDef options[] = {
     { "autorotate",       HAS_ARG | OPT_BOOL | OPT_SPEC |
                           OPT_EXPERT | OPT_INPUT,                                { .off = OFFSET(autorotate) },
         "automatically insert correct rotate filters" },
+    { "autoscale",        HAS_ARG | OPT_BOOL | OPT_SPEC |
+                          OPT_EXPERT | OPT_OUTPUT,                               { .off = OFFSET(autoscale) },
+        "automatically insert a scale filter at the end of the filter graph if a resolution "
+        "change is detected. This ensures all frames are the same resolution as the first frame "
+        "when they leave the filter chain (this option is enabled by default). "
+        "If disabled, some encoders/muxers may not support this mode."},
 
     /* audio options */
     { "aframes",        OPT_AUDIO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT,           { .func_arg = opt_audio_frames },