51 #define OFFSET(x) offsetof(SignalstatsContext, x)
52 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
81 s->
yuv_color[0] = (( 66*r + 129*g + 25*b + (1<<7)) >> 8) + 16;
82 s->
yuv_color[1] = ((-38*r + -74*g + 112*b + (1<<7)) >> 8) + 128;
83 s->
yuv_color[2] = ((112*r + -94*g + -18*b + (1<<7)) >> 8) + 128;
115 outlink->
w = inlink->
w;
116 outlink->
h = inlink->
h;
121 s->
fs = inlink->
w * inlink->
h;
135 const int chromax = x >> s->
hsub;
136 const int chromay = y >> s->
vsub;
145 const int yc = y >> s->
vsub;
150 for (x = 0; x < w; x++) {
151 const int xc = x >> s->
hsub;
152 const int luma = pluma[x];
153 const int chromau = pchromau[xc];
154 const int chromav = pchromav[xc];
155 const int filt = luma < 16 || luma > 235 ||
156 chromau < 16 || chromau > 240 ||
157 chromav < 16 || chromav > 240;
167 return ((abs(x - y) + abs (z - y)) / 2) - abs(z - x) > 4;
174 int x, score = 0,
filt;
176 if (y - 1 < 0 || y + 1 >= h)
182 #define FILTER(i, j) \
183 filter_tout_outlier(p[(y-j) * lw + x + i], \
184 p[ y * lw + x + i], \
185 p[(y+j) * lw + x + i])
187 #define FILTER3(j) (FILTER(-1, j) && FILTER(0, j) && FILTER(1, j))
189 if (y - 2 >= 0 && y + 2 < h) {
190 for (x = 1; x < w - 1; x++) {
197 for (x = 1; x < w - 1; x++) {
219 for (i = 0; i < w; i++)
220 totdiff += abs(p->
data[0][y2lw + i] - p->
data[0][ylw + i]);
234 for (x = 0; x < w; x++) {
244 static const struct {
268 unsigned int histy[
DEPTH] = {0},
272 histsat[
DEPTH] = {0};
273 int miny = -1, minu = -1, minv = -1;
274 int maxy = -1, maxu = -1, maxv = -1;
275 int lowy = -1, lowu = -1, lowv = -1;
276 int highy = -1, highu = -1, highv = -1;
277 int minsat = -1, maxsat = -1, lowsat = -1, highsat = -1;
278 int lowp, highp, clowp, chighp;
279 int accy, accu, accv;
280 int accsat, acchue = 0;
282 int toty = 0, totu = 0, totv = 0, totsat=0;
284 int dify = 0, difu = 0, difv = 0;
302 for (j = 0; j < link->
h; j++) {
303 for (i = 0; i < link->
w; i++) {
304 yuv = in->
data[0][w + i];
306 dify += abs(in->
data[0][w + i] - prev->
data[0][pw + i]);
313 for (j = 0; j < s->
chromah; j++) {
314 for (i = 0; i < s->
chromaw; i++) {
317 yuvu = in->
data[1][cw+i];
318 yuvv = in->
data[2][cw+i];
320 difu += abs(in->
data[1][cw+i] - prev->
data[1][cpw+i]);
322 difv += abs(in->
data[2][cw+i] - prev->
data[2][cpw+i]);
325 sat = hypot(yuvu - 128, yuvv - 128);
327 hue = floor((180 /
M_PI) *
atan2f(yuvu-128, yuvv-128) + 180);
334 for (j = 0; j < link->
h; j++) {
338 filtot[fil] +=
filters_def[fil].process(s, in, dbg, j, link->
w, link->
h);
346 lowp =
lrint(s->
fs * 10 / 100.);
347 highp =
lrint(s->
fs * 90 / 100.);
351 accy = accu = accv = accsat = 0;
352 for (fil = 0; fil <
DEPTH; fil++) {
353 if (miny < 0 && histy[fil]) miny = fil;
354 if (minu < 0 && histu[fil]) minu = fil;
355 if (minv < 0 && histv[fil]) minv = fil;
356 if (minsat < 0 && histsat[fil]) minsat = fil;
358 if (histy[fil]) maxy = fil;
359 if (histu[fil]) maxu = fil;
360 if (histv[fil]) maxv = fil;
361 if (histsat[fil]) maxsat = fil;
363 toty += histy[fil] * fil;
364 totu += histu[fil] * fil;
365 totv += histv[fil] * fil;
366 totsat += histsat[fil] * fil;
371 accsat += histsat[fil];
373 if (lowy == -1 && accy >= lowp) lowy = fil;
374 if (lowu == -1 && accu >= clowp) lowu = fil;
375 if (lowv == -1 && accv >= clowp) lowv = fil;
376 if (lowsat == -1 && accsat >= clowp) lowsat = fil;
378 if (highy == -1 && accy >= highp) highy = fil;
379 if (highu == -1 && accu >= chighp) highu = fil;
380 if (highv == -1 && accv >= chighp) highv = fil;
381 if (highsat == -1 && accsat >= chighp) highsat = fil;
386 for (fil = 0; fil < 360; fil++) {
387 tothue += histhue[fil] * fil;
388 acchue += histhue[fil];
390 if (medhue == -1 && acchue > s->
cfs / 2)
392 if (histhue[fil] > maxhue) {
393 maxhue = histhue[fil];
400 #define SET_META(key, fmt, val) do { \
401 snprintf(metabuf, sizeof(metabuf), fmt, val); \
402 av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0); \
439 snprintf(metabuf,
sizeof(metabuf),
"%g", 1.0 * filtot[fil] / s->
fs);
469 .
name =
"signalstats",
470 .description =
"Generate statistics from video analysis.",
475 .
inputs = signalstats_inputs,
476 .
outputs = signalstats_outputs,
477 .priv_class = &signalstats_class,