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;
150 outlink->
w = inlink->
w;
151 outlink->
h = inlink->
h;
156 s->
fs = inlink->
w * inlink->
h;
174 const int chromax = x >> s->
hsub;
175 const int chromay = y >> s->
vsub;
187 const int w = in->
width;
189 const int slice_start = (h * jobnr ) / nb_jobs;
190 const int slice_end = (h * (jobnr+1)) / nb_jobs;
193 for (y = slice_start; y <
slice_end; y++) {
194 const int yc = y >> s->
vsub;
199 for (x = 0; x < w; x++) {
200 const int xc = x >> s->
hsub;
201 const int luma = pluma[x];
202 const int chromau = pchromau[xc];
203 const int chromav = pchromav[xc];
204 const int filt = luma < 16 || luma > 235 ||
205 chromau < 16 || chromau > 240 ||
206 chromav < 16 || chromav > 240;
217 return ((abs(x - y) + abs (z - y)) / 2) - abs(z - x) > 4;
226 const int w = in->
width;
228 const int slice_start = (h * jobnr ) / nb_jobs;
229 const int slice_end = (h * (jobnr+1)) / nb_jobs;
232 int x,
y, score = 0,
filt;
234 for (y = slice_start; y <
slice_end; y++) {
236 if (y - 1 < 0 || y + 1 >= h)
242 #define FILTER(i, j) \
243 filter_tout_outlier(p[(y-j) * lw + x + i], \
244 p[ y * lw + x + i], \
245 p[(y+j) * lw + x + i])
247 #define FILTER3(j) (FILTER(-1, j) && FILTER(0, j) && FILTER(1, j))
249 if (y - 2 >= 0 && y + 2 < h) {
250 for (x = 1; x < w - 1; x++) {
257 for (x = 1; x < w - 1; x++) {
276 const int w = in->
width;
278 const int slice_start = (h * jobnr ) / nb_jobs;
279 const int slice_end = (h * (jobnr+1)) / nb_jobs;
284 for (y = slice_start; y <
slice_end; y++) {
286 const int ylw = y * lw;
287 int filt, totdiff = 0;
292 for (x = 0; x < w; x++)
293 totdiff += abs(p[y2lw + x] - p[ylw + x]);
298 for (x = 0; x < w; x++)
304 static const struct {
325 const int slice_start = (s->
chromah * jobnr ) / nb_jobs;
330 const uint8_t *p_u = src->
data[1] + slice_start * lsz_u;
331 const uint8_t *p_v = src->
data[2] + slice_start * lsz_v;
333 const int lsz_sat = dst_sat->
linesize[0];
334 const int lsz_hue = dst_hue->
linesize[0];
335 uint8_t *p_sat = dst_sat->
data[0] + slice_start * lsz_sat;
336 uint8_t *p_hue = dst_hue->
data[0] + slice_start * lsz_hue;
338 for (j = slice_start; j <
slice_end; j++) {
339 for (i = 0; i < s->
chromaw; i++) {
340 const int yuvu = p_u[i];
341 const int yuvv = p_v[i];
342 p_sat[i] = hypot(yuvu - 128, yuvv - 128);
343 ((int16_t*)p_hue)[i] = floor((180 /
M_PI) *
atan2f(yuvu-128, yuvv-128) + 180);
365 unsigned int histy[
DEPTH] = {0},
369 histsat[
DEPTH] = {0};
370 int miny = -1, minu = -1, minv = -1;
371 int maxy = -1, maxu = -1, maxv = -1;
372 int lowy = -1, lowu = -1, lowv = -1;
373 int highy = -1, highu = -1, highv = -1;
374 int minsat = -1, maxsat = -1, lowsat = -1, highsat = -1;
375 int lowp, highp, clowp, chighp;
376 int accy, accu, accv;
377 int accsat, acchue = 0;
379 int toty = 0, totu = 0, totv = 0, totsat=0;
381 int dify = 0, difu = 0, difv = 0;
390 const int lsz_sat = sat->
linesize[0];
391 const int lsz_hue = hue->
linesize[0];
412 for (j = 0; j < link->
h; j++) {
413 for (i = 0; i < link->
w; i++) {
414 const int yuv = in->
data[0][w + i];
416 dify += abs(yuv - prev->
data[0][pw + i]);
423 for (j = 0; j < s->
chromah; j++) {
424 for (i = 0; i < s->
chromaw; i++) {
425 const int yuvu = in->
data[1][cw+i];
426 const int yuvv = in->
data[2][cw+i];
428 difu += abs(yuvu - prev->
data[1][cpw+i]);
430 difv += abs(yuvv - prev->
data[2][cpw+i]);
433 histhue[((int16_t*)p_hue)[i]]++;
445 .out = out != in && s->
outfilter == fil ? out : NULL,
450 for (i = 0; i < s->
nb_jobs; i++)
458 lowp =
lrint(s->
fs * 10 / 100.);
459 highp =
lrint(s->
fs * 90 / 100.);
463 accy = accu = accv = accsat = 0;
464 for (fil = 0; fil <
DEPTH; fil++) {
465 if (miny < 0 && histy[fil]) miny = fil;
466 if (minu < 0 && histu[fil]) minu = fil;
467 if (minv < 0 && histv[fil]) minv = fil;
468 if (minsat < 0 && histsat[fil]) minsat = fil;
470 if (histy[fil]) maxy = fil;
471 if (histu[fil]) maxu = fil;
472 if (histv[fil]) maxv = fil;
473 if (histsat[fil]) maxsat = fil;
475 toty += histy[fil] * fil;
476 totu += histu[fil] * fil;
477 totv += histv[fil] * fil;
478 totsat += histsat[fil] * fil;
483 accsat += histsat[fil];
485 if (lowy == -1 && accy >= lowp) lowy = fil;
486 if (lowu == -1 && accu >= clowp) lowu = fil;
487 if (lowv == -1 && accv >= clowp) lowv = fil;
488 if (lowsat == -1 && accsat >= clowp) lowsat = fil;
490 if (highy == -1 && accy >= highp) highy = fil;
491 if (highu == -1 && accu >= chighp) highu = fil;
492 if (highv == -1 && accv >= chighp) highv = fil;
493 if (highsat == -1 && accsat >= chighp) highsat = fil;
498 for (fil = 0; fil < 360; fil++) {
499 tothue += histhue[fil] * fil;
500 acchue += histhue[fil];
502 if (medhue == -1 && acchue > s->
cfs / 2)
504 if (histhue[fil] > maxhue) {
505 maxhue = histhue[fil];
512 #define SET_META(key, fmt, val) do { \
513 snprintf(metabuf, sizeof(metabuf), fmt, val); \
514 av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0); \
551 snprintf(metabuf,
sizeof(metabuf),
"%g", 1.0 * filtot[fil] / s->
fs);
581 .
name =
"signalstats",
582 .description =
"Generate statistics from video analysis.",
587 .
inputs = signalstats_inputs,
588 .
outputs = signalstats_outputs,
589 .priv_class = &signalstats_class,