[FFmpeg-devel] [PATCH v2] avfilter/vf_freezedetect: add discard option to force drop freezen frame

Gyan ffmpeg at gyani.pro
Tue Oct 8 07:32:25 EEST 2019



On 08-10-2019 09:24 AM, lance.lmwang at gmail.com wrote:
> From: Limin Wang <lance.lmwang at gmail.com>
>
> How to tested it, please try with the following command:
> ./ffmpeg  -f lavfi -i "smptebars=duration=5:size=1280x720:rate=30,freezedetect=d=1:discard=0"  -f null -
> frame=  150 fps=0.0 q=-0.0 Lsize=N/A time=00:00:05.00 bitrate=N/A speed= 234x
>
> ./ffmpeg  -f lavfi -i "smptebars=duration=5:size=1280x720:rate=30,freezedetect=d=1:discard=1"  -f null -
> frame=   30 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.00 bitrate=N/A speed=59.7x
>
> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
> ---
>   doc/filters.texi              | 10 ++++++++++
>   libavfilter/vf_freezedetect.c |  8 +++++++-
>   2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 333f502083..8aa7471f7e 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -10678,6 +10678,9 @@ timestamp of the first frame of the freeze. The
>   @code{lavfi.freezedetect.freeze_duration} and
>   @code{lavfi.freezedetect.freeze_end} metadata keys are set on the first frame
>   after the freeze.
> +In addition, you can choose to discard the freezen frames instead of report
> +by metadata. Please note the first few freezen frames (the detection interval)
> +won't be dropped for the filter doesn't buffer any frames.
>   
freezen --> frozen
You could suggest that users apply tpad at start of stream so that all 
frozen frames can be removed. Afterwards, users can trim out those added 
frames.
Test this if you add it.

>   The filter accepts the following options:
>   
> @@ -10689,6 +10692,13 @@ specified value) or as a difference ratio between 0 and 1. Default is -60dB, or
>   
>   @item duration, d
>   Set freeze duration until notification (default is 2 seconds).
> +
> + at item discard
> +Set force to discard freezen frame.
> + 0:  do nothing
> + 1:  discard freezen frame
> +
> +Default is 0
>   @end table
>   
>   @anchor{frei0r}
> diff --git a/libavfilter/vf_freezedetect.c b/libavfilter/vf_freezedetect.c
> index cc086afee6..cc115eb521 100644
> --- a/libavfilter/vf_freezedetect.c
> +++ b/libavfilter/vf_freezedetect.c
> @@ -45,6 +45,8 @@ typedef struct FreezeDetectContext {
>   
>       double noise;
>       int64_t duration;            ///< minimum duration of frozen frame until notification
> +
> +    int discard;                 ///< 0: no discard, 1: discard freezen frame
>   } FreezeDetectContext;
>   
>   #define OFFSET(x) offsetof(FreezeDetectContext, x)
> @@ -56,6 +58,7 @@ static const AVOption freezedetect_options[] = {
>       { "noise",               "set noise tolerance",                       OFFSET(noise),  AV_OPT_TYPE_DOUBLE,   {.dbl=0.001},     0,       1.0, V|F },
>       { "d",                   "set minimum duration in seconds",        OFFSET(duration),  AV_OPT_TYPE_DURATION, {.i64=2000000},   0, INT64_MAX, V|F },
>       { "duration",            "set minimum duration in seconds",        OFFSET(duration),  AV_OPT_TYPE_DURATION, {.i64=2000000},   0, INT64_MAX, V|F },
> +    { "discard",             "set frame discard flag",                 OFFSET(discard),   AV_OPT_TYPE_BOOL,     {.i64=0},         0,         1, V|F },
>   
>       {NULL}
>   };
> @@ -196,7 +199,10 @@ static int activate(AVFilterContext *ctx)
>                   return AVERROR(ENOMEM);
>               }
>           }
> -        return ff_filter_frame(outlink, frame);
> +        if (s->discard && s->frozen) {
> +            av_frame_free(&frame);
> +        } else
> +            return ff_filter_frame(outlink, frame);
>       }
>   
>       FF_FILTER_FORWARD_STATUS(inlink, outlink);

Gyan


More information about the ffmpeg-devel mailing list