Go to the documentation of this file.
45 int jobnr,
int nb_jobs);
48 #define OFFSET(x) offsetof(CorrContext, x)
49 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
58 snprintf(key2,
sizeof(key2),
"lavfi.%s.%s%s%c",
63 snprintf(key2,
sizeof(key2),
"lavfi.%s.%s%s",
64 ctx->filter->name,
ctx->filter->name,
key);
69 #define CORR(type, name) \
70 static void f##name(AVFilterContext *ctx, AVFrame *master, \
71 AVFrame *ref, double *comp_score) \
73 CorrContext *s = ctx->priv; \
75 for (int c = 0; c < s->nb_components; c++) { \
76 const ptrdiff_t linesize1 = master->linesize[c] / \
78 const ptrdiff_t linesize2 = ref->linesize[c] / \
80 const type *src1 = (const type *)master->data[c]; \
81 const type *src2 = (const type *)ref->data[c]; \
82 const int h = s->planeheight[c]; \
83 const int w = s->planewidth[c]; \
84 const float scale = 1.f / s->max[c]; \
85 uint64_t sum1 = 0, sum2 = 0; \
86 float sum12, sum1q, sum2q; \
87 float sumq, mean1, mean2; \
89 for (int y = 0; y < h; y++) { \
90 for (int x = 0; x < w; x++) { \
99 mean1 = scale * (sum1 /(double)(w * h)); \
100 mean2 = scale * (sum2 /(double)(w * h)); \
102 src1 = (const type *)master->data[c]; \
103 src2 = (const type *)ref->data[c]; \
109 for (int y = 0; y < h; y++) { \
110 for (int x = 0; x < w; x++) { \
111 const float f1 = scale * src1[x] - mean1; \
112 const float f2 = scale * src2[x] - mean2; \
123 sumq = sqrtf(sum1q * sum2q); \
125 comp_score[c] = av_clipf(sum12 / sumq,-1.f,1.f); \
127 comp_score[c] = sum1q == sum2q ? 1.f : 0.f; \
133 CORR(uint16_t, corr16)
140 double comp_score[4], score = 0.;
147 if (
ctx->is_disabled || !
ref)
149 metadata = &
master->metadata;
151 if (
s->max[0] > 255) {
157 for (
int c = 0;
c <
s->nb_components;
c++)
158 score += comp_score[
c];
159 score /=
s->nb_components;
162 s->min_score =
fmin(
s->min_score, score);
163 s->max_score =
fmax(
s->max_score, score);
165 for (
int c = 0;
c <
s->nb_components;
c++)
166 s->score_comp[
c] += comp_score[
c];
169 for (
int j = 0; j <
s->nb_components; j++) {
170 int c =
s->is_rgb ?
s->rgba_map[j] : j;
189 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
190 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
191 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
208 s->nb_components =
desc->nb_components;
209 if (
ctx->inputs[0]->w !=
ctx->inputs[1]->w ||
210 ctx->inputs[0]->h !=
ctx->inputs[1]->h) {
216 s->comps[0] =
s->is_rgb ?
'R' :
'Y' ;
217 s->comps[1] =
s->is_rgb ?
'G' :
'U' ;
218 s->comps[2] =
s->is_rgb ?
'B' :
'V' ;
222 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
224 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
229 s->max[0] = (1 <<
desc->comp[0].depth) - 1;
230 s->max[1] = (1 <<
desc->comp[1].depth) - 1;
231 s->max[2] = (1 <<
desc->comp[2].depth) - 1;
232 s->max[3] = (1 <<
desc->comp[3].depth) - 1;
247 outlink->
w = mainlink->
w;
248 outlink->
h = mainlink->
h;
259 av_log(
ctx,
AV_LOG_WARNING,
"not matching timebases found between first input: %d/%d and second input %d/%d, results may be incorrect!\n",
261 ctx->inputs[1]->time_base.num,
ctx->inputs[1]->time_base.den);
276 if (
s->nb_frames > 0) {
280 for (
int j = 0; j <
s->nb_components; j++) {
281 int c =
s->is_rgb ?
s->rgba_map[j] : j;
282 av_strlcatf(buf,
sizeof(buf),
" %c:%f",
s->comps[j],
s->score_comp[
c] /
s->nb_frames);
288 s->score /
s->nb_frames,
319 #define corr_options options
325 .preinit = corr_framesync_preinit,
330 .priv_class = &corr_class,
#define AV_PIX_FMT_GBRAP16
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
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
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
int(* filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define FILTER_PIXFMTS_ARRAY(array)
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
This structure describes decoded (raw) audio or video data.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
static int config_output(AVFilterLink *outlink)
FRAMESYNC_DEFINE_CLASS(corr, CorrContext, fs)
static const AVFilterPad corr_inputs[]
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
static const AVFilterPad corr_outputs[]
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GRAY16
const AVFilter ff_vf_corr
A filter pad used for either input or output.
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int init(AVFilterContext *ctx)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP12
#define AV_CEIL_RSHIFT(a, b)
static int activate(AVFilterContext *ctx)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
#define AV_PIX_FMT_GRAY14
static const AVOption options[]
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GBRP16
Describe the class of an AVClass context structure.
#define fs(width, name, subs,...)
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
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
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
double fmin(double, double)
AVFilterContext * src
source filter
#define AV_LOG_INFO
Standard information.
int w
agreed upon image width
static int config_input_ref(AVFilterLink *inlink)
#define AV_PIX_FMT_GBRP12
static enum AVPixelFormat pix_fmts[]
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
static av_cold void uninit(AVFilterContext *ctx)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static void set_meta(AVFilterContext *ctx, AVDictionary **metadata, const char *key, char comp, float d)
double fmax(double, double)
int h
agreed upon image height
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
static int ref[MAX_W *MAX_W]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#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.
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
#define AV_PIX_FMT_GRAY12
static int do_corr(FFFrameSync *fs)