54 int jobnr,
int nb_jobs);
58 #define OFFSET(x) offsetof(IdentityContext, x)
59 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
65 for (
int j = 0; j < outw; j++)
66 score += main_line[j] == ref_line[j];
73 const uint16_t *main_line = (
const uint16_t *)mmain_line;
74 const uint16_t *ref_line = (
const uint16_t *)rref_line;
77 for (
int j = 0; j < outw; j++)
78 score += main_line[j] == ref_line[j];
96 int jobnr,
int nb_jobs)
100 uint64_t *score =
td->score[jobnr];
102 for (
int c = 0;
c <
td->nb_components;
c++) {
103 const int outw =
td->planewidth[
c];
104 const int outh =
td->planeheight[
c];
105 const int slice_start = (outh * jobnr) / nb_jobs;
106 const int slice_end = (outh * (jobnr+1)) / nb_jobs;
107 const int ref_linesize =
td->ref_linesize[
c];
108 const int main_linesize =
td->main_linesize[
c];
109 const uint8_t *main_line =
td->main_data[
c] + main_linesize * slice_start;
110 const uint8_t *ref_line =
td->ref_data[
c] + ref_linesize * slice_start;
113 s->sad(main_line, main_linesize, ref_line, ref_linesize,
124 int jobnr,
int nb_jobs)
128 uint64_t *score =
td->score[jobnr];
130 for (
int c = 0;
c <
td->nb_components;
c++) {
131 const int outw =
td->planewidth[
c];
132 const int outh =
td->planeheight[
c];
133 const int slice_start = (outh * jobnr) / nb_jobs;
134 const int slice_end = (outh * (jobnr+1)) / nb_jobs;
135 const int ref_linesize =
td->ref_linesize[
c];
136 const int main_linesize =
td->main_linesize[
c];
137 const uint8_t *main_line =
td->main_data[
c] + main_linesize * slice_start;
138 const uint8_t *ref_line =
td->ref_data[
c] + ref_linesize * slice_start;
142 m +=
s->filter_line(main_line, ref_line, outw);
143 ref_line += ref_linesize;
144 main_line += main_linesize;
159 snprintf(key2,
sizeof(key2),
"lavfi.%s.%s%s%c",
164 snprintf(key2,
sizeof(key2),
"lavfi.%s.%s%s",
165 ctx->filter->name,
ctx->filter->name,
key);
175 double comp_score[4], score = 0.;
176 uint64_t comp_sum[4] = { 0 };
184 if (
ctx->is_disabled || !
ref)
186 metadata = &
master->metadata;
188 td.nb_components =
s->nb_components;
189 td.score =
s->scores;
190 for (
int c = 0;
c <
s->nb_components;
c++) {
194 td.ref_linesize[
c] =
ref->linesize[
c];
195 td.planewidth[
c] =
s->planewidth[
c];
196 td.planeheight[
c] =
s->planeheight[
c];
201 for (
int j = 0; j <
s->nb_threads; j++) {
202 for (
int c = 0;
c <
s->nb_components;
c++)
203 comp_sum[
c] +=
s->scores[j][
c];
206 for (
int c = 0;
c <
s->nb_components;
c++)
207 comp_score[
c] = comp_sum[
c] / ((
double)
s->planewidth[
c] *
s->planeheight[
c]);
209 for (
int c = 0;
c <
s->nb_components &&
s->is_msad;
c++)
210 comp_score[
c] /= (
double)
s->max[
c];
212 for (
int c = 0;
c <
s->nb_components;
c++)
213 score += comp_score[
c];
214 score /=
s->nb_components;
216 s->min_score =
FFMIN(
s->min_score, score);
217 s->max_score =
FFMAX(
s->max_score, score);
221 for (
int j = 0; j <
s->nb_components; j++)
222 s->score_comp[j] += comp_score[j];
225 for (
int j = 0; j <
s->nb_components; j++) {
226 int c =
s->is_rgb ?
s->rgba_map[j] : j;
247 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
248 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
249 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
273 s->nb_components =
desc->nb_components;
274 if (
ctx->inputs[0]->w !=
ctx->inputs[1]->w ||
275 ctx->inputs[0]->h !=
ctx->inputs[1]->h) {
279 if (
ctx->inputs[0]->format !=
ctx->inputs[1]->format) {
285 s->comps[0] =
s->is_rgb ?
'R' :
'Y' ;
286 s->comps[1] =
s->is_rgb ?
'G' :
'U' ;
287 s->comps[2] =
s->is_rgb ?
'B' :
'V' ;
291 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
293 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
295 s->scores =
av_calloc(
s->nb_threads,
sizeof(*
s->scores));
299 for (
int t = 0; t <
s->nb_threads &&
s->scores; t++) {
300 s->scores[t] =
av_calloc(
s->nb_components,
sizeof(*
s->scores[0]));
308 s->max[0] = (1 <<
desc->comp[0].depth) - 1;
309 s->max[1] = (1 <<
desc->comp[1].depth) - 1;
310 s->max[2] = (1 <<
desc->comp[2].depth) - 1;
311 s->max[3] = (1 <<
desc->comp[3].depth) - 1;
313 s->is_msad = !strcmp(
ctx->filter->name,
"msad");
334 outlink->
w = mainlink->
w;
335 outlink->
h = mainlink->
h;
346 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",
348 ctx->inputs[1]->time_base.num,
ctx->inputs[1]->time_base.den);
363 if (
s->nb_frames > 0) {
367 for (
int j = 0; j <
s->nb_components; j++) {
368 int c =
s->is_rgb ?
s->rgba_map[j] : j;
369 av_strlcatf(buf,
sizeof(buf),
" %c:%f",
s->comps[j],
s->score_comp[
c] /
s->nb_frames);
375 s->score /
s->nb_frames,
381 for (
int t = 0; t <
s->nb_threads &&
s->scores; t++)
411 #if CONFIG_IDENTITY_FILTER
413 #define identity_options options
419 .preinit = identity_framesync_preinit,
425 .priv_class = &identity_class,
433 #if CONFIG_MSAD_FILTER
435 #define msad_options options
441 .preinit = msad_framesync_preinit,
447 .priv_class = &msad_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
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,...)
#define flags(name, subs,...)
#define fs(width, name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
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...
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.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
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
ff_scene_sad_fn ff_scene_sad_get_fn(int depth)
void(* ff_scene_sad_fn)(SCENE_SAD_PARAMS)
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
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
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...
unsigned(* filter_line)(const uint8_t *buf, const uint8_t *ref, int w)
int(* filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Used for passing data between threads.
const uint8_t * ref_data[4]
const uint8_t * main_data[4]
static int ref[MAX_W *MAX_W]
static int do_identity(FFFrameSync *fs)
static const AVOption options[]
static int compute_images_identity(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int query_formats(AVFilterContext *ctx)
static const AVFilterPad identity_inputs[]
static unsigned identity_line_16bit(const uint8_t *mmain_line, const uint8_t *rref_line, int outw)
static int compute_images_msad(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void set_meta(AVFilterContext *ctx, AVDictionary **metadata, const char *key, char comp, float d)
static int config_input_ref(AVFilterLink *inlink)
static const AVFilterPad identity_outputs[]
static int activate(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
static unsigned identity_line_8bit(const uint8_t *main_line, const uint8_t *ref_line, int outw)