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,
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static av_cold void uninit(AVFilterContext *ctx)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static const AVFilterPad outputs[]
static int filter_brng(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int h
agreed upon image height
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static const AVFilterPad signalstats_outputs[]
struct AVFilterGraph * graph
filtergraph this filter belongs to
const char * name
Pad name.
static int filter_frame(AVFilterLink *link, AVFrame *in)
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
int nb_threads
Maximum number of threads used by filters in this graph.
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
AVDictionary * metadata
metadata.
static int compute_sat_hue_metrics(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A filter pad used for either input or output.
A link between two filters.
int width
width and height of the video frame
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
enum FilterMode outfilter
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static void burn_frame(const SignalstatsContext *s, AVFrame *f, int x, int y)
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
AVFilter ff_vf_signalstats
static int filter_vrep(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
#define AV_PIX_FMT_GRAY16
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
int(* process)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define FF_CEIL_RSHIFT(a, b)
#define SET_META(key, fmt, val)
AVFilterContext * src
source filter
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int format
agreed upon media format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const AVFilterPad signalstats_inputs[]
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
static av_always_inline av_const long int lrint(double x)
const char * name
Filter name.
static AVFrame * alloc_frame(enum AVPixelFormat pixfmt, int w, int h)
AVFilterLink ** outputs
array of pointers to output links
static int filter_tout(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
static int filter_tout_outlier(uint8_t x, uint8_t y, uint8_t z)
static const int8_t filt[NUMTAPS]
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static int config_props(AVFilterLink *outlink)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
avfilter_execute_func * execute
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
AVFilterContext * dst
dest filter
static const struct PPFilter filters[]
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
static int query_formats(AVFilterContext *ctx)
AVFILTER_DEFINE_CLASS(signalstats)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
#define av_malloc_array(a, b)
static av_cold int init(AVFilterContext *ctx)
static const AVOption signalstats_options[]
static const struct @135 filters_def[]
AVPixelFormat
Pixel format.