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;
154 outlink->
w = inlink->
w;
155 outlink->
h = inlink->
h;
160 s->
fs = inlink->
w * inlink->
h;
178 const int chromax = x >> s->
hsub;
179 const int chromay = y >> s->
vsub;
191 const int w = in->
width;
193 const int slice_start = (h * jobnr ) / nb_jobs;
194 const int slice_end = (h * (jobnr+1)) / nb_jobs;
197 for (y = slice_start; y <
slice_end; y++) {
198 const int yc = y >> s->
vsub;
203 for (x = 0; x < w; x++) {
204 const int xc = x >> s->
hsub;
205 const int luma = pluma[x];
206 const int chromau = pchromau[xc];
207 const int chromav = pchromav[xc];
208 const int filt = luma < 16 || luma > 235 ||
209 chromau < 16 || chromau > 240 ||
210 chromav < 16 || chromav > 240;
221 return ((abs(x - y) + abs (z - y)) / 2) - abs(z - x) > 4;
230 const int w = in->
width;
232 const int slice_start = (h * jobnr ) / nb_jobs;
233 const int slice_end = (h * (jobnr+1)) / nb_jobs;
236 int x,
y, score = 0,
filt;
238 for (y = slice_start; y <
slice_end; y++) {
240 if (y - 1 < 0 || y + 1 >= h)
246 #define FILTER(i, j) \
247 filter_tout_outlier(p[(y-j) * lw + x + i], \
248 p[ y * lw + x + i], \
249 p[(y+j) * lw + x + i])
251 #define FILTER3(j) (FILTER(-1, j) && FILTER(0, j) && FILTER(1, j))
253 if (y - 2 >= 0 && y + 2 < h) {
254 for (x = 1; x < w - 1; x++) {
261 for (x = 1; x < w - 1; x++) {
280 const int w = in->
width;
282 const int slice_start = (h * jobnr ) / nb_jobs;
283 const int slice_end = (h * (jobnr+1)) / nb_jobs;
288 for (y = slice_start; y <
slice_end; y++) {
290 const int ylw = y * lw;
291 int filt, totdiff = 0;
296 for (x = 0; x < w; x++)
297 totdiff += abs(p[y2lw + x] - p[ylw + x]);
302 for (x = 0; x < w; x++)
308 static const struct {
329 const int slice_start = (s->
chromah * jobnr ) / nb_jobs;
334 const uint8_t *p_u = src->
data[1] + slice_start * lsz_u;
335 const uint8_t *p_v = src->
data[2] + slice_start * lsz_v;
337 const int lsz_sat = dst_sat->
linesize[0];
338 const int lsz_hue = dst_hue->
linesize[0];
339 uint8_t *p_sat = dst_sat->
data[0] + slice_start * lsz_sat;
340 uint8_t *p_hue = dst_hue->
data[0] + slice_start * lsz_hue;
342 for (j = slice_start; j <
slice_end; j++) {
343 for (i = 0; i < s->
chromaw; i++) {
344 const int yuvu = p_u[i];
345 const int yuvv = p_v[i];
346 p_sat[i] = hypot(yuvu - 128, yuvv - 128);
347 ((int16_t*)p_hue)[i] = floor((180 /
M_PI) *
atan2f(yuvu-128, yuvv-128) + 180);
369 unsigned int histy[
DEPTH] = {0},
373 histsat[
DEPTH] = {0};
374 int miny = -1, minu = -1, minv = -1;
375 int maxy = -1, maxu = -1, maxv = -1;
376 int lowy = -1, lowu = -1, lowv = -1;
377 int highy = -1, highu = -1, highv = -1;
378 int minsat = -1, maxsat = -1, lowsat = -1, highsat = -1;
379 int lowp, highp, clowp, chighp;
380 int accy, accu, accv;
381 int accsat, acchue = 0;
383 int toty = 0, totu = 0, totv = 0, totsat=0;
385 int dify = 0, difu = 0, difv = 0;
394 const int lsz_sat = sat->
linesize[0];
395 const int lsz_hue = hue->
linesize[0];
416 for (j = 0; j < link->
h; j++) {
417 for (i = 0; i < link->
w; i++) {
418 const int yuv = in->
data[0][w + i];
420 dify += abs(yuv - prev->
data[0][pw + i]);
427 for (j = 0; j < s->
chromah; j++) {
428 for (i = 0; i < s->
chromaw; i++) {
429 const int yuvu = in->
data[1][cw+i];
430 const int yuvv = in->
data[2][cw+i];
432 difu += abs(yuvu - prev->
data[1][cpw+i]);
434 difv += abs(yuvv - prev->
data[2][cpw+i]);
437 histhue[((int16_t*)p_hue)[i]]++;
454 for (i = 0; i < s->
nb_jobs; i++)
462 lowp =
lrint(s->
fs * 10 / 100.);
463 highp =
lrint(s->
fs * 90 / 100.);
467 accy = accu = accv = accsat = 0;
468 for (fil = 0; fil <
DEPTH; fil++) {
469 if (miny < 0 && histy[fil]) miny = fil;
470 if (minu < 0 && histu[fil]) minu = fil;
471 if (minv < 0 && histv[fil]) minv = fil;
472 if (minsat < 0 && histsat[fil]) minsat = fil;
474 if (histy[fil]) maxy = fil;
475 if (histu[fil]) maxu = fil;
476 if (histv[fil]) maxv = fil;
477 if (histsat[fil]) maxsat = fil;
479 toty += histy[fil] * fil;
480 totu += histu[fil] * fil;
481 totv += histv[fil] * fil;
482 totsat += histsat[fil] * fil;
487 accsat += histsat[fil];
489 if (lowy == -1 && accy >= lowp) lowy = fil;
490 if (lowu == -1 && accu >= clowp) lowu = fil;
491 if (lowv == -1 && accv >= clowp) lowv = fil;
492 if (lowsat == -1 && accsat >= clowp) lowsat = fil;
494 if (highy == -1 && accy >= highp) highy = fil;
495 if (highu == -1 && accu >= chighp) highu = fil;
496 if (highv == -1 && accv >= chighp) highv = fil;
497 if (highsat == -1 && accsat >= chighp) highsat = fil;
502 for (fil = 0; fil < 360; fil++) {
503 tothue += histhue[fil] * fil;
504 acchue += histhue[fil];
506 if (medhue == -1 && acchue > s->
cfs / 2)
508 if (histhue[fil] > maxhue) {
509 maxhue = histhue[fil];
516 #define SET_META(key, fmt, val) do { \
517 snprintf(metabuf, sizeof(metabuf), fmt, val); \
518 av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0); \
555 snprintf(metabuf,
sizeof(metabuf),
"%g", 1.0 * filtot[fil] / s->
fs);
585 .
name =
"signalstats",
586 .description =
"Generate statistics from video analysis.",
591 .
inputs = signalstats_inputs,
592 .
outputs = signalstats_outputs,
593 .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 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 AV_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 AV_PIX_FMT_YUV422P and setting col...
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.
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 AV_PIX_FMT_YUV420P and setting col...
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...
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_log(ac->avr, AV_LOG_TRACE,"%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
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.
static const struct @140 filters_def[]
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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 AV_PIX_FMT_YUV444P and setting col...
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 ...
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_log(ac->avr, AV_LOG_TRACE,"%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 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[]
AVPixelFormat
Pixel format.