58 int jobnr,
int nb_jobs);
60 int jobnr,
int nb_jobs);
67#define OFFSET(x) offsetof(CorrContext, x)
68#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
77 snprintf(key2,
sizeof(key2),
"lavfi.%s.%s%s%c",
82 snprintf(key2,
sizeof(key2),
"lavfi.%s.%s%s",
83 ctx->filter->name,
ctx->filter->name,
key);
88#define SUM(type, name) \
89static int sum_##name(AVFilterContext *ctx, void *arg, \
90 int jobnr, int nb_jobs) \
92 CorrContext *s = ctx->priv; \
93 ThreadData *td = arg; \
94 AVFrame *master = td->master; \
95 AVFrame *ref = td->ref; \
97 for (int c = 0; c < s->nb_components; c++) { \
98 const ptrdiff_t linesize1 = master->linesize[c] / \
100 const ptrdiff_t linesize2 = ref->linesize[c] / \
102 const int h = s->planeheight[c]; \
103 const int w = s->planewidth[c]; \
104 const int slice_start = ff_slice_pos(h, jobnr, nb_jobs); \
105 const int slice_end = ff_slice_pos(h, jobnr + 1, nb_jobs); \
106 const type *src1 = (const type *)master->data[c] + \
107 linesize1 * slice_start; \
108 const type *src2 = (const type *)ref->data[c] + \
109 linesize2 * slice_start; \
110 uint64_t sum1 = 0, sum2 = 0; \
112 for (int y = slice_start; y < slice_end; y++) { \
113 for (int x = 0; x < w; x++) { \
122 s->sums[jobnr * s->nb_components + c].s[0] = sum1; \
123 s->sums[jobnr * s->nb_components + c].s[1] = sum2; \
130SUM(uint16_t, slice16)
132#define CORR(type, name) \
133static int corr_##name(AVFilterContext *ctx, void *arg, \
134 int jobnr, int nb_jobs) \
136 CorrContext *s = ctx->priv; \
137 ThreadData *td = arg; \
138 AVFrame *master = td->master; \
139 AVFrame *ref = td->ref; \
141 for (int c = 0; c < s->nb_components; c++) { \
142 const ptrdiff_t linesize1 = master->linesize[c] / \
144 const ptrdiff_t linesize2 = ref->linesize[c] / \
146 const type *src1 = (const type *)master->data[c]; \
147 const type *src2 = (const type *)ref->data[c]; \
148 const int h = s->planeheight[c]; \
149 const int w = s->planewidth[c]; \
150 const int slice_start = ff_slice_pos(h, jobnr, nb_jobs); \
151 const int slice_end = ff_slice_pos(h, jobnr + 1, nb_jobs); \
152 const float scale = 1.f / s->max[c]; \
153 const float mean1 = s->mean[c][0]; \
154 const float mean2 = s->mean[c][1]; \
155 float sum12 = 0.f, sum1q = 0.f, sum2q = 0.f; \
157 src1 = (const type *)master->data[c] + \
158 slice_start * linesize1; \
159 src2 = (const type *)ref->data[c] + \
160 slice_start * linesize2; \
162 for (int y = slice_start; y < slice_end; y++) { \
163 for (int x = 0; x < w; x++) { \
164 const float f1 = scale * src1[x] - mean1; \
165 const float f2 = scale * src2[x] - mean2; \
176 s->qsums[jobnr * s->nb_components + c].s[0] = sum12; \
177 s->qsums[jobnr * s->nb_components + c].s[1] = sum1q; \
178 s->qsums[jobnr * s->nb_components + c].s[2] = sum2q; \
185CORR(uint16_t, slice16)
192 double comp_score[4], score = 0.;
200 if (
ctx->is_disabled || !
ref)
207 FFMIN(
s->planeheight[1],
s->nb_threads));
209 for (
int c = 0;
c <
s->nb_components;
c++) {
210 const double scale = 1.f /
s->max[
c];
211 uint64_t sum1 = 0, sum2 = 0;
213 for (
int n = 0; n <
s->nb_threads; n++) {
214 sum1 +=
s->sums[n *
s->nb_components +
c].s[0];
215 sum2 +=
s->sums[n *
s->nb_components +
c].s[1];
223 FFMIN(
s->planeheight[1],
s->nb_threads));
225 for (
int c = 0;
c <
s->nb_components;
c++) {
226 double sumq, sum12 = 0.0, sum1q = 0.0, sum2q = 0.0;
228 for (
int n = 0; n <
s->nb_threads; n++) {
229 sum12 +=
s->qsums[n *
s->nb_components +
c].s[0];
230 sum1q +=
s->qsums[n *
s->nb_components +
c].s[1];
231 sum2q +=
s->qsums[n *
s->nb_components +
c].s[2];
234 sumq = sqrt(sum1q * sum2q);
236 comp_score[
c] =
av_clipd(sum12 / sumq,-1.0,1.0);
242 for (
int c = 0;
c <
s->nb_components;
c++)
243 score += comp_score[
c];
244 score /=
s->nb_components;
247 s->min_score =
fmin(
s->min_score, score);
248 s->max_score =
fmax(
s->max_score, score);
250 for (
int c = 0;
c <
s->nb_components;
c++)
251 s->score_comp[
c] += comp_score[
c];
254 for (
int j = 0; j <
s->nb_components; j++) {
255 int c =
s->is_rgb ?
s->rgba_map[j] : j;
274#define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
275#define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
276#define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
294 s->nb_components =
desc->nb_components;
295 if (
ctx->inputs[0]->w !=
ctx->inputs[1]->w ||
296 ctx->inputs[0]->h !=
ctx->inputs[1]->h) {
302 s->comps[0] =
s->is_rgb ?
'R' :
'Y' ;
303 s->comps[1] =
s->is_rgb ?
'G' :
'U' ;
304 s->comps[2] =
s->is_rgb ?
'B' :
'V' ;
308 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
310 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
312 s->sums =
av_calloc(
s->nb_threads *
s->nb_components,
sizeof(*
s->sums));
313 s->qsums =
av_calloc(
s->nb_threads *
s->nb_components,
sizeof(*
s->qsums));
314 if (!
s->qsums || !
s->sums)
320 s->max[0] = (1 <<
desc->comp[0].depth) - 1;
321 s->max[1] = (1 <<
desc->comp[1].depth) - 1;
322 s->max[2] = (1 <<
desc->comp[2].depth) - 1;
323 s->max[3] = (1 <<
desc->comp[3].depth) - 1;
325 s->sum_slice =
desc->comp[0].depth > 8 ? sum_slice16 : sum_slice8;
326 s->corr_slice =
desc->comp[0].depth > 8 ? corr_slice16 : corr_slice8;
343 outlink->
w = mainlink->
w;
344 outlink->
h = mainlink->
h;
355 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",
357 ctx->inputs[1]->time_base.num,
ctx->inputs[1]->time_base.den);
372 if (
s->nb_frames > 0) {
376 for (
int j = 0; j <
s->nb_components; j++) {
377 int c =
s->is_rgb ?
s->rgba_map[j] : j;
378 av_strlcatf(buf,
sizeof(buf),
" %c:%f",
s->comps[j],
s->score_comp[
c] /
s->nb_frames);
384 s->score /
s->nb_frames,
417#define corr_options options
423 .p.priv_class = &corr_class,
427 .preinit = corr_framesync_preinit,
const FFFilter ff_vf_corr
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Main libavfilter public API header.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define fs(width, name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
double fmin(double, double)
double fmax(double, double)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
int(* init)(AVBSFContext *ctx)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
#define FRAMESYNC_DEFINE_CLASS(name, context, field)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS_ARRAY(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP14
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int(* corr_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int(* sum_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
Used for passing data between threads.
static int ref[MAX_W *MAX_W]
static AVFormatContext * ctx
static int do_corr(FFFrameSync *fs)
static const AVFilterPad corr_inputs[]
static void set_meta(AVFilterContext *ctx, AVDictionary **metadata, const char *key, char comp, float d)
static const AVFilterPad corr_outputs[]
static int config_input_ref(AVFilterLink *inlink)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)