[FFmpeg-devel] [PATCH] avfilter/af_apad: do not add infinte silence for zero pad_dur or whole_dur

Marton Balint cus at passwd.hu
Sat Nov 13 15:17:58 EET 2021



On Sun, 7 Nov 2021, Marton Balint wrote:

>
>
> On Thu, 29 Jul 2021, Marton Balint wrote:
>
>>  Unfortunately pad_len and pad_dur behaviour was different if 0 was
>>  specified,
>>  pad_dur handled 0 duration as infinity, for pad_len, infinity was -1.
>>
>>  Let's make the behaviour consistent by handling 0 duration for pad_dur and
>>  whole_dur as indeed 0 duration. This somewhat changes the behaviour of the
>>  filter if 0 was explicitly specified, but deprecating the old option and
>>  adding
>>  a new for the corrected behaviour seemed a bit overkill. So let's document
>>  the
>>  change instead.
>
> Ping, anybody against this? Slightly breaks compatibility.

Will apply soon.

Regards,
Marton

>
>>
>>  Signed-off-by: Marton Balint <cus at passwd.hu>
>>  ---
>>  doc/filters.texi      | 7 +++++--
>>  libavfilter/af_apad.c | 8 ++++----
>>  libavfilter/version.h | 2 +-
>>  3 files changed, 10 insertions(+), 7 deletions(-)
>>
>>  diff --git a/doc/filters.texi b/doc/filters.texi
>>  index 66c0f87e47..f164f4d62d 100644
>>  --- a/doc/filters.texi
>>  +++ b/doc/filters.texi
>> @@  -2248,12 +2248,12 @@ with @option{pad_len}.
>> @ item pad_dur
>>  Specify the duration of samples of silence to add. See
>> @ ref{time duration syntax,,the Time duration section in the 
>> @ ffmpeg-utils(1) manual,ffmpeg-utils}
>>  -for the accepted syntax. Used only if set to non-zero value.
>>  +for the accepted syntax. Used only if set to non-negative value.
>> 
>> @ item whole_dur
>>  Specify the minimum total duration in the output audio stream. See
>> @ ref{time duration syntax,,the Time duration section in the 
>> @ ffmpeg-utils(1) manual,ffmpeg-utils}
>>  -for the accepted syntax. Used only if set to non-zero value. If the value
>>  is longer than
>>  +for the accepted syntax. Used only if set to non-negative value. If the
>>  value is longer than
>>  the input audio length, silence is added to the end, until the value is
>>  reached.
>>  This option is mutually exclusive with @option{pad_dur}
>> @ end table
>> @@  -2262,6 +2262,9 @@ If neither the @option{pad_len} nor the 
>> @@  @option{whole_len} nor @option{pad_dur}
>>  nor @option{whole_dur} option is set, the filter will add silence to the
>>  end of
>>  the input stream indefinitely.
>>
>>  +Note that for ffmpeg 4.4 and earlier a zero @option{pad_dur} or
>>  + at option{whole_dur} also caused the filter to add silence indefinitely.
>>  +
>> @ subsection Examples
>> 
>> @ itemize
>>  diff --git a/libavfilter/af_apad.c b/libavfilter/af_apad.c
>>  index 8628c0c2e2..ff60eaa397 100644
>>  --- a/libavfilter/af_apad.c
>>  +++ b/libavfilter/af_apad.c
>> @@  -52,8 +52,8 @@ static const AVOption apad_options[] = {
>>      { "packet_size", "set silence packet size",
>>      OFFSET(packet_size), AV_OPT_TYPE_INT,   { .i64 = 4096 }, 0, INT_MAX, A
>>      },
>>      { "pad_len",     "set number of samples of silence to add",
>>      OFFSET(pad_len),     AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX,
>>      A },
>>      { "whole_len",   "set minimum target number of samples in the audio
>>      stream", OFFSET(whole_len),   AV_OPT_TYPE_INT64, { .i64 = -1 }, -1,
>>      INT64_MAX, A },
>>  -    { "pad_dur",     "set duration of silence to add",
>>  OFFSET(pad_dur),     AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, A
>>  },
>>  -    { "whole_dur",   "set minimum target duration in the audio stream",
>>  OFFSET(whole_dur),   AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT64_MAX, A
>>  },
>>  +    { "pad_dur",     "set duration of silence to add",
>>  OFFSET(pad_dur),     AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT64_MAX, A
>>  },
>>  +    { "whole_dur",   "set minimum target duration in the audio stream",
>>  OFFSET(whole_dur),   AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT64_MAX, A
>>  },
>>      { NULL }
>>  };
>> 
>> @@  -138,9 +138,9 @@ static int config_output(AVFilterLink *outlink)
>>      AVFilterContext *ctx = outlink->src;
>>      APadContext *s  = ctx->priv;
>>
>>  -    if (s->pad_dur)
>>  +    if (s->pad_dur >= 0)
>>          s->pad_len = av_rescale(s->pad_dur, outlink->sample_rate,
>>  AV_TIME_BASE);
>>  -    if (s->whole_dur)
>>  +    if (s->whole_dur >= 0)
>>          s->whole_len = av_rescale(s->whole_dur, outlink->sample_rate,
>>          AV_TIME_BASE);
>>
>>      s->pad_len_left   = s->pad_len;
>>  diff --git a/libavfilter/version.h b/libavfilter/version.h
>>  index 75cd10dccd..85acd613a0 100644
>>  --- a/libavfilter/version.h
>>  +++ b/libavfilter/version.h
>> @@  -31,7 +31,7 @@
>>
>>  #define LIBAVFILTER_VERSION_MAJOR   8
>>  #define LIBAVFILTER_VERSION_MINOR   1
>>  -#define LIBAVFILTER_VERSION_MICRO 103
>>  +#define LIBAVFILTER_VERSION_MICRO 104
>> 
>>
>>  #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR,
>>  \
>>  --
>>  2.26.2
>>
>>  _______________________________________________
>>  ffmpeg-devel mailing list
>>  ffmpeg-devel at ffmpeg.org
>>  https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>>  To unsubscribe, visit link above, or email
>>  ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-devel mailing list