Go to the documentation of this file.
30 #define MAX_FRAMES 240
32 #define NUM_CHANNELS 3
56 #define OFFSET(x) offsetof(PhotosensitivityContext, x)
57 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
62 {
"threshold",
"set detection threshold factor (lower is stricter)",
OFFSET(threshold_multiplier),
AV_OPT_TYPE_FLOAT, {.dbl=1}, 0.1, FLT_MAX,
FLAGS },
63 {
"t",
"set detection threshold factor (lower is stricter)",
OFFSET(threshold_multiplier),
AV_OPT_TYPE_FLOAT, {.dbl=1}, 0.1, FLT_MAX,
FLAGS },
78 #define NUM_CELLS (GRID_SIZE * GRID_SIZE)
82 int cell, gx, gy, x0, x1, y0, y1, x, y,
c, area;
92 const uint8_t *
data =
td->in->data[0];
106 for (y = y0; y < y1; y +=
skip) {
108 for (x = x0; x < x1; x +=
skip) {
122 td->out->grid[gy][gx][
c] = sum[
c];
151 const uint16_t s_mul =
td->s_mul;
152 const uint16_t t_mul = 0x100 - s_mul;
153 const int slice_start = (
td->target->height * jobnr) / nb_jobs;
154 const int slice_end = (
td->target->height * (jobnr+1)) / nb_jobs;
155 const int linesize =
td->target->linesize[0];
158 t =
td->target->data[0] + y *
td->target->linesize[0];
159 s =
td->source->data[0] + y *
td->source->linesize[0];
160 for (x = 0; x < linesize; x++) {
161 *t = (*t * t_mul + *
s * s_mul) >> 8;
173 td.s_mul = (uint16_t)(
factor * 0x100);
180 int badness, x, y,
c;
185 badness +=
abs((
int)
a->grid[y][x][
c] - (
int)
b->grid[y][x][
c]);
207 int this_badness, current_badness, fixed_badness, new_badness,
i, res;
220 for (
i = 1;
i <
s->nb_frames;
i++)
221 current_badness +=
i *
s->history[(
s->history_pos +
i) %
s->nb_frames];
222 current_badness /=
s->nb_frames;
226 new_badness = current_badness + this_badness;
228 current_badness, new_badness,
s->badness_threshold,
229 100 * new_badness /
s->badness_threshold, new_badness < s->badness_threshold ?
"OK" :
"EXCEEDED");
231 fixed_badness = new_badness;
232 if (new_badness < s->badness_threshold || !
s->last_frame_av ||
s->bypass) {
235 s->last_frame_av =
src = in;
236 s->last_frame_e = ef;
237 s->history[
s->history_pos] = this_badness;
239 factor = (
float)(
s->badness_threshold - current_badness) / (new_badness - current_badness);
242 s->history[
s->history_pos] = 0;
253 fixed_badness = current_badness + this_badness;
255 current_badness, fixed_badness,
s->badness_threshold,
256 100 * new_badness /
s->badness_threshold,
factor);
257 s->last_frame_e = ef;
258 s->history[
s->history_pos] = this_badness;
260 src =
s->last_frame_av;
263 s->history_pos = (
s->history_pos + 1) %
s->nb_frames;
272 metadata = &
out->metadata;
311 .
name =
"photosensitivity",
312 .description =
NULL_IF_CONFIG_SMALL(
"Filter out photosensitive epilepsy seizure-inducing flashes."),
314 .priv_class = &photosensitivity_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVFILTER_DEFINE_CLASS(photosensitivity)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int config_input(AVFilterLink *inlink)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
const char * name
Filter name.
A link between two filters.
static int convert_frame_partial(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption photosensitivity_options[]
PhotosensitivityFrame last_frame_e
const AVFilter ff_vf_photosensitivity
A filter pad used for either input or output.
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
uint8_t grid[GRID_SIZE][GRID_SIZE][4]
#define FILTER_INPUTS(array)
static void convert_frame(AVFilterContext *ctx, AVFrame *in, PhotosensitivityFrame *out, int skip)
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
PhotosensitivityFrame * out
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a source
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FILTER_PIXFMTS(...)
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void blend_frame(AVFilterContext *ctx, AVFrame *target, AVFrame *source, float factor)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define i(width, name, range_min, range_max)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
const char * name
Pad name.
static int blend_frame_partial(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const int factor[16]
static const AVFilterPad inputs[]
#define FILTER_OUTPUTS(array)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static int get_badness(PhotosensitivityFrame *a, PhotosensitivityFrame *b)
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
float threshold_multiplier
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.