65 #define OFFSET(x) offsetof(SignalstatsContext, x)
66 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
95 s->
yuv_color[0] = (( 66*r + 129*g + 25*b + (1<<7)) >> 8) + 16;
96 s->
yuv_color[1] = ((-38*r + -74*g + 112*b + (1<<7)) >> 8) + 128;
97 s->
yuv_color[2] = ((112*r + -94*g + -18*b + (1<<7)) >> 8) + 128;
152 outlink->
w = inlink->
w;
153 outlink->
h = inlink->
h;
158 s->
fs = inlink->
w * inlink->
h;
176 const int chromax = x >> s->
hsub;
177 const int chromay = y >> s->
vsub;
189 const int w = in->
width;
191 const int slice_start = (h * jobnr ) / nb_jobs;
192 const int slice_end = (h * (jobnr+1)) / nb_jobs;
195 for (y = slice_start; y <
slice_end; y++) {
196 const int yc = y >> s->
vsub;
201 for (x = 0; x < w; x++) {
202 const int xc = x >> s->
hsub;
203 const int luma = pluma[x];
204 const int chromau = pchromau[xc];
205 const int chromav = pchromav[xc];
206 const int filt = luma < 16 || luma > 235 ||
207 chromau < 16 || chromau > 240 ||
208 chromav < 16 || chromav > 240;
219 return ((abs(x - y) + abs (z - y)) / 2) - abs(z - x) > 4;
228 const int w = in->
width;
230 const int slice_start = (h * jobnr ) / nb_jobs;
231 const int slice_end = (h * (jobnr+1)) / nb_jobs;
234 int x,
y, score = 0,
filt;
236 for (y = slice_start; y <
slice_end; y++) {
238 if (y - 1 < 0 || y + 1 >= h)
244 #define FILTER(i, j) \
245 filter_tout_outlier(p[(y-j) * lw + x + i], \
246 p[ y * lw + x + i], \
247 p[(y+j) * lw + x + i])
249 #define FILTER3(j) (FILTER(-1, j) && FILTER(0, j) && FILTER(1, j))
251 if (y - 2 >= 0 && y + 2 < h) {
252 for (x = 1; x < w - 1; x++) {
259 for (x = 1; x < w - 1; x++) {
278 const int w = in->
width;
280 const int slice_start = (h * jobnr ) / nb_jobs;
281 const int slice_end = (h * (jobnr+1)) / nb_jobs;
286 for (y = slice_start; y <
slice_end; y++) {
288 const int ylw = y * lw;
289 int filt, totdiff = 0;
294 for (x = 0; x < w; x++)
295 totdiff += abs(p[y2lw + x] - p[ylw + x]);
300 for (x = 0; x < w; x++)
306 static const struct {
327 const int slice_start = (s->
chromah * jobnr ) / nb_jobs;
332 const uint8_t *p_u = src->
data[1] + slice_start * lsz_u;
333 const uint8_t *p_v = src->
data[2] + slice_start * lsz_v;
335 const int lsz_sat = dst_sat->
linesize[0];
336 const int lsz_hue = dst_hue->
linesize[0];
337 uint8_t *p_sat = dst_sat->
data[0] + slice_start * lsz_sat;
338 uint8_t *p_hue = dst_hue->
data[0] + slice_start * lsz_hue;
340 for (j = slice_start; j <
slice_end; j++) {
341 for (i = 0; i < s->
chromaw; i++) {
342 const int yuvu = p_u[i];
343 const int yuvv = p_v[i];
344 p_sat[i] = hypot(yuvu - 128, yuvv - 128);
345 ((int16_t*)p_hue)[i] = floor((180 /
M_PI) *
atan2f(yuvu-128, yuvv-128) + 180);
367 unsigned int histy[
DEPTH] = {0},
371 histsat[
DEPTH] = {0};
372 int miny = -1, minu = -1, minv = -1;
373 int maxy = -1, maxu = -1, maxv = -1;
374 int lowy = -1, lowu = -1, lowv = -1;
375 int highy = -1, highu = -1, highv = -1;
376 int minsat = -1, maxsat = -1, lowsat = -1, highsat = -1;
377 int lowp, highp, clowp, chighp;
378 int accy, accu, accv;
379 int accsat, acchue = 0;
381 int toty = 0, totu = 0, totv = 0, totsat=0;
383 int dify = 0, difu = 0, difv = 0;
392 const int lsz_sat = sat->
linesize[0];
393 const int lsz_hue = hue->
linesize[0];
414 for (j = 0; j < link->
h; j++) {
415 for (i = 0; i < link->
w; i++) {
416 const int yuv = in->
data[0][w + i];
418 dify += abs(yuv - prev->
data[0][pw + i]);
425 for (j = 0; j < s->
chromah; j++) {
426 for (i = 0; i < s->
chromaw; i++) {
427 const int yuvu = in->
data[1][cw+i];
428 const int yuvv = in->
data[2][cw+i];
430 difu += abs(yuvu - prev->
data[1][cpw+i]);
432 difv += abs(yuvv - prev->
data[2][cpw+i]);
435 histhue[((int16_t*)p_hue)[i]]++;
452 for (i = 0; i < s->
nb_jobs; i++)
460 lowp =
lrint(s->
fs * 10 / 100.);
461 highp =
lrint(s->
fs * 90 / 100.);
465 accy = accu = accv = accsat = 0;
466 for (fil = 0; fil <
DEPTH; fil++) {
467 if (miny < 0 && histy[fil]) miny = fil;
468 if (minu < 0 && histu[fil]) minu = fil;
469 if (minv < 0 && histv[fil]) minv = fil;
470 if (minsat < 0 && histsat[fil]) minsat = fil;
472 if (histy[fil]) maxy = fil;
473 if (histu[fil]) maxu = fil;
474 if (histv[fil]) maxv = fil;
475 if (histsat[fil]) maxsat = fil;
477 toty += histy[fil] * fil;
478 totu += histu[fil] * fil;
479 totv += histv[fil] * fil;
480 totsat += histsat[fil] * fil;
485 accsat += histsat[fil];
487 if (lowy == -1 && accy >= lowp) lowy = fil;
488 if (lowu == -1 && accu >= clowp) lowu = fil;
489 if (lowv == -1 && accv >= clowp) lowv = fil;
490 if (lowsat == -1 && accsat >= clowp) lowsat = fil;
492 if (highy == -1 && accy >= highp) highy = fil;
493 if (highu == -1 && accu >= chighp) highu = fil;
494 if (highv == -1 && accv >= chighp) highv = fil;
495 if (highsat == -1 && accsat >= chighp) highsat = fil;
500 for (fil = 0; fil < 360; fil++) {
501 tothue += histhue[fil] * fil;
502 acchue += histhue[fil];
504 if (medhue == -1 && acchue > s->
cfs / 2)
506 if (histhue[fil] > maxhue) {
507 maxhue = histhue[fil];
514 #define SET_META(key, fmt, val) do { \
515 snprintf(metabuf, sizeof(metabuf), fmt, val); \
516 av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0); \
553 snprintf(metabuf,
sizeof(metabuf),
"%g", 1.0 * filtot[fil] / s->
fs);
583 .
name =
"signalstats",
584 .description =
"Generate statistics from video analysis.",
589 .
inputs = signalstats_inputs,
590 .
outputs = signalstats_outputs,
591 .priv_class = &signalstats_class,