[FFmpeg-devel] [PATCH] libavfilter: add photosensitivity filter

Michael Niedermayer michael at niedermayer.cc
Sat Jul 13 00:07:51 EEST 2019


On Fri, Jul 12, 2019 at 11:26:34AM +0200, Paul B Mahol wrote:
> From: Vladimir Panteleev <git at thecybershadow.net>
> 
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  doc/filters.texi                  |  20 ++
>  libavfilter/Makefile              |   1 +
>  libavfilter/allfilters.c          |   1 +
>  libavfilter/vf_photosensitivity.c | 336 ++++++++++++++++++++++++++++++
>  4 files changed, 358 insertions(+)
>  create mode 100644 libavfilter/vf_photosensitivity.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index c92ed8de07..39ee2cb001 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -13938,6 +13938,26 @@ Filter selects among @samp{t}, @samp{b} and @samp{p} using image analysis only.
>  @end table
>  @end table
>  
> + at section photosensitivity
> +Reduce various flashes in video, so to help users with epilepsy.

This should clearly specify if this filter is known to work reliably,
untested, experimental or what exactly.
Consider someone might end up injuring themselfs if this doesnt
work for them.



> +
> +It accepts the following options:
> + at table @option
> + at item frames, f
> +Set how many frames to use when filtering. Default is 30.
> +
> + at item threshold, t
> +Set detection threshold factor. Default is 1.
> +Lower is stricter.
> +
> + at item skip
> +Set how many pixels to skip when sampling frames. Defalt is 1.
> +Allowed range is from 1 to 1024.
> +
> + at item bypass
> +Leave frames unchanged. Default is disabled.
> + at end table
> +
>  @section pixdesctest
>  
>  Pixel format descriptor test filter, mainly useful for internal
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 455c809b15..6a3521e813 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -319,6 +319,7 @@ OBJS-$(CONFIG_PALETTEUSE_FILTER)             += vf_paletteuse.o framesync.o
>  OBJS-$(CONFIG_PERMS_FILTER)                  += f_perms.o
>  OBJS-$(CONFIG_PERSPECTIVE_FILTER)            += vf_perspective.o
>  OBJS-$(CONFIG_PHASE_FILTER)                  += vf_phase.o
> +OBJS-$(CONFIG_PHOTOSENSITIVITY_FILTER)       += vf_photosensitivity.o
>  OBJS-$(CONFIG_PIXDESCTEST_FILTER)            += vf_pixdesctest.o
>  OBJS-$(CONFIG_PIXSCOPE_FILTER)               += vf_datascope.o
>  OBJS-$(CONFIG_PP_FILTER)                     += vf_pp.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 04a3df7d56..0a05030a01 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -303,6 +303,7 @@ extern AVFilter ff_vf_paletteuse;
>  extern AVFilter ff_vf_perms;
>  extern AVFilter ff_vf_perspective;
>  extern AVFilter ff_vf_phase;
> +extern AVFilter ff_vf_photosensitivity;
>  extern AVFilter ff_vf_pixdesctest;
>  extern AVFilter ff_vf_pixscope;
>  extern AVFilter ff_vf_pp;
> diff --git a/libavfilter/vf_photosensitivity.c b/libavfilter/vf_photosensitivity.c
> new file mode 100644
> index 0000000000..6805e92712
> --- /dev/null
> +++ b/libavfilter/vf_photosensitivity.c
> @@ -0,0 +1,336 @@
> +/*
> + * Copyright (c) 2019 Vladimir Panteleev
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include <float.h>
> +
> +#include "libavutil/imgutils.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "avfilter.h"
> +
> +#include "formats.h"
> +#include "internal.h"
> +#include "video.h"
> +
> +#define MAX_FRAMES 240
> +#define GRID_SIZE 8
> +#define NUM_CHANNELS 3
> +
> +typedef struct PhotosensitivityFrame {
> +    uint8_t grid[GRID_SIZE][GRID_SIZE][4];
> +} PhotosensitivityFrame;
> +
> +typedef struct PhotosensitivityContext {
> +    const AVClass *class;
> +
> +    int nb_frames;
> +    int skip;
> +    float threshold_multiplier;
> +    int bypass;
> +
> +    int badness_threshold;
> +
> +    /* Circular buffer */
> +    int history[MAX_FRAMES];
> +    int history_pos;
> +
> +    PhotosensitivityFrame last_frame_e;
> +    AVFrame *last_frame_av;
> +} PhotosensitivityContext;
> +
> +#define OFFSET(x) offsetof(PhotosensitivityContext, x)
> +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
> +
> +static const AVOption photosensitivity_options[] = {
> +    { "frames",    "set how many frames to use"                        ,  OFFSET(nb_frames           ), AV_OPT_TYPE_INT  , {.i64=30}, 2, MAX_FRAMES, FLAGS },
> +    { "f",         "set how many frames to use"                        ,  OFFSET(nb_frames           ), AV_OPT_TYPE_INT  , {.i64=30}, 2, MAX_FRAMES, FLAGS },
> +    { "threshold", "set detection threshold factor (lower is stricter)",  OFFSET(threshold_multiplier), AV_OPT_TYPE_FLOAT, {.dbl= 1}, 0.1, FLT_MAX,  FLAGS },
> +    { "t"        , "set detection threshold factor (lower is stricter)",  OFFSET(threshold_multiplier), AV_OPT_TYPE_FLOAT, {.dbl= 1}, 0.1, FLT_MAX,  FLAGS },
> +    { "skip"     , "set pixels to skip when sampling frames"           ,  OFFSET(skip                ), AV_OPT_TYPE_INT  , {.i64= 1}, 1, 1024      , FLAGS },
> +    { "bypass"   , "leave frames unchanged"                            ,  OFFSET(bypass              ), AV_OPT_TYPE_BOOL , {.i64= 0}, 0, 1         , FLAGS },
> +    { NULL }
> +};
> +
> +AVFILTER_DEFINE_CLASS(photosensitivity);
> +

> +static int query_formats(AVFilterContext *ctx)
> +{
> +    static const enum AVPixelFormat pixel_fmts[] = {
> +        AV_PIX_FMT_RGB24,
> +        AV_PIX_FMT_BGR24,
> +        AV_PIX_FMT_NONE
> +    };

as most videos are in YUV formats and as this filter only analyses a
subset of pixels it would be good not to have to convert all to RGB but
only the pixels needed.

Ill refrain from suggesting changes to what this filter does exactly as i 
do not know enough about the subject and have no reasonable way to test this.

Thanks

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190712/5c040d4c/attachment.sig>


More information about the ffmpeg-devel mailing list