Go to the documentation of this file.
32 #define MAX_FRAMES 240
34 #define NUM_CHANNELS 3
58 #define OFFSET(x) offsetof(PhotosensitivityContext, x)
59 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
64 {
"threshold",
"set detection threshold factor (lower is stricter)",
OFFSET(threshold_multiplier),
AV_OPT_TYPE_FLOAT, {.dbl=1}, 0.1, FLT_MAX,
FLAGS },
65 {
"t",
"set detection threshold factor (lower is stricter)",
OFFSET(threshold_multiplier),
AV_OPT_TYPE_FLOAT, {.dbl=1}, 0.1, FLT_MAX,
FLAGS },
80 #define NUM_CELLS (GRID_SIZE * GRID_SIZE)
84 int cell, gx, gy, x0, x1, y0, y1, x, y,
c, area;
90 const int slice_start = (
NUM_CELLS * jobnr) / nb_jobs;
93 int width =
td->in->width,
height =
td->in->height, linesize =
td->in->linesize[0], skip =
td->skip;
94 const uint8_t *
data =
td->in->data[0];
96 for (cell = slice_start; cell <
slice_end; cell++) {
108 for (y = y0; y < y1; y += skip) {
110 for (x = x0; x < x1; x += skip) {
120 area = ((x1 - x0 + skip - 1) / skip) * ((y1 - y0 + skip - 1) / skip);
124 td->out->grid[gy][gx][
c] = sum[
c];
153 const uint16_t s_mul =
td->s_mul;
154 const uint16_t t_mul = 0x100 - s_mul;
155 const int slice_start = (
td->target->height * jobnr) / nb_jobs;
156 const int slice_end = (
td->target->height * (jobnr+1)) / nb_jobs;
157 const int linesize =
td->target->linesize[0];
159 for (y = slice_start; y <
slice_end; y++) {
160 t =
td->target->data[0] + y *
td->target->linesize[0];
161 s =
td->source->data[0] + y *
td->source->linesize[0];
162 for (x = 0; x < linesize; x++) {
163 *t = (*t * t_mul + *
s * s_mul) >> 8;
175 td.s_mul = (uint16_t)(
factor * 0x100);
182 int badness, x, y,
c;
187 badness +=
abs((
int)
a->grid[y][x][
c] - (
int)
b->grid[y][x][
c]);
209 int this_badness, current_badness, fixed_badness, new_badness,
i, res;
222 for (
i = 1;
i <
s->nb_frames;
i++)
223 current_badness +=
i *
s->history[(
s->history_pos +
i) %
s->nb_frames];
224 current_badness /=
s->nb_frames;
228 new_badness = current_badness + this_badness;
230 current_badness, new_badness,
s->badness_threshold,
231 100 * new_badness /
s->badness_threshold, new_badness < s->badness_threshold ?
"OK" :
"EXCEEDED");
233 fixed_badness = new_badness;
234 if (new_badness < s->badness_threshold || !
s->last_frame_av ||
s->bypass) {
237 s->last_frame_av =
src = in;
238 s->last_frame_e = ef;
239 s->history[
s->history_pos] = this_badness;
241 factor = (float)(
s->badness_threshold - current_badness) / (new_badness - current_badness);
244 s->history[
s->history_pos] = 0;
255 fixed_badness = current_badness + this_badness;
257 current_badness, fixed_badness,
s->badness_threshold,
258 100 * new_badness /
s->badness_threshold,
factor);
259 s->last_frame_e = ef;
260 s->history[
s->history_pos] = this_badness;
262 src =
s->last_frame_av;
265 s->history_pos = (
s->history_pos + 1) %
s->nb_frames;
274 metadata = &
out->metadata;
320 .
name =
"photosensitivity",
321 .description =
NULL_IF_CONFIG_SMALL(
"Filter out photosensitive epilepsy seizure-inducing flashes."),
323 .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.
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
#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_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
uint8_t grid[GRID_SIZE][GRID_SIZE][4]
static const AVFilterPad outputs[]
#define FILTER_INPUTS(array)
static void convert_frame(AVFilterContext *ctx, AVFrame *in, PhotosensitivityFrame *out, int skip)
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