Go to the documentation of this file.
56 #define OFFSET(x) offsetof(BlackDetectContext, x)
57 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
61 {
"black_min_duration",
"set minimum detected black duration in seconds",
OFFSET(black_min_duration_time),
AV_OPT_TYPE_DOUBLE, {.dbl=2}, 0, DBL_MAX,
FLAGS },
62 {
"picture_black_ratio_th",
"set the picture black ratio threshold",
OFFSET(picture_black_ratio_th),
AV_OPT_TYPE_DOUBLE, {.dbl=.98}, 0, 1,
FLAGS },
71 #define YUVJ_FORMATS \
72 AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P
106 const int depth =
desc->comp[0].depth;
110 s->time_base =
inlink->time_base;
111 s->black_min_duration =
s->black_min_duration_time /
av_q2d(
s->time_base);
112 s->counter =
av_calloc(
s->nb_threads,
sizeof(*
s->counter));
117 "black_min_duration:%s pixel_black_th:%f picture_black_ratio_th:%f\n",
119 s->pixel_black_th,
s->picture_black_ratio_th);
127 if ((
s->black_end -
s->black_start) >=
s->black_min_duration) {
129 "black_start:%s black_end:%s black_duration:%s\n",
137 int jobnr,
int nb_jobs)
140 const unsigned int threshold =
s->pixel_black_th_i;
141 unsigned int *counterp = &
s->counter[jobnr];
143 const int linesize = in->
linesize[0];
146 const int start = (
h * jobnr) / nb_jobs;
147 const int end = (
h * (jobnr+1)) / nb_jobs;
148 const int size = end - start;
149 unsigned int counter = 0;
152 const uint8_t *p = in->
data[0] + start * linesize;
154 for (
int i = 0;
i <
size;
i++) {
155 for (
int x = 0; x <
w; x++)
156 counter += p[x] <= threshold;
160 const uint16_t *p = (
const uint16_t *)(in->
data[0] + start * linesize);
162 for (
int i = 0;
i <
size;
i++) {
163 for (
int x = 0; x <
w; x++)
164 counter += p[x] <= threshold;
179 double picture_black_ratio = 0;
180 const int max = (1 <<
s->depth) - 1;
181 const int factor = (1 << (
s->depth - 8));
185 s->pixel_black_th_i = full ?
s->pixel_black_th *
max :
192 for (
int i = 0;
i <
s->nb_threads;
i++)
193 s->nb_black_pixels +=
s->counter[
i];
195 picture_black_ratio = (
double)
s->nb_black_pixels / (
inlink->w *
inlink->h);
198 "frame:%"PRId64
" picture_black_ratio:%f pts:%s t:%s type:%c\n",
203 if (picture_black_ratio >=
s->picture_black_ratio_th) {
204 if (!
s->black_started) {
206 s->black_started = 1;
207 s->black_start = picref->
pts;
211 }
else if (
s->black_started) {
213 s->black_started = 0;
214 s->black_end = picref->
pts;
220 s->last_picref_pts = picref->
pts;
221 s->nb_black_pixels = 0;
231 if (
s->black_started) {
233 s->black_end =
s->last_picref_pts;
248 .
name =
"blackdetect",
255 .priv_class = &blackdetect_class,
#define AV_PIX_FMT_YUVA422P16
enum AVColorRange color_range
MPEG vs JPEG YUV range.
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static const AVOption blackdetect_options[]
#define FILTER_PIXFMTS_ARRAY(array)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
int64_t black_end
pts end time of the last black picture
double black_min_duration_time
minimum duration of detected black, in seconds
#define AV_PIX_FMT_YUVA422P9
#define FILTER_INPUTS(array)
int64_t last_picref_pts
pts of the last input picture
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define AV_PIX_FMT_YUVA420P16
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV420P10
static int black_counter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Link properties exposed to filter code, but not external callers.
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_GRAY16
A filter pad used for either input or output.
#define AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV422P16
const AVFilter ff_vf_blackdetect
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
static const AVFilterPad blackdetect_inputs[]
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
static av_cold void uninit(AVFilterContext *ctx)
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int config_input(AVFilterLink *inlink)
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GRAY14
int ff_fmt_is_in(int fmt, const int *fmts)
Tell if an integer is contained in the provided -1-terminated list of integers.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_OUTPUTS(array)
#define AV_PIX_FMT_GRAY10
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV422P10
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static enum AVPixelFormat yuvj_formats[]
static FilterLink * ff_filter_link(AVFilterLink *link)
enum AVPictureType pict_type
Picture type of the frame.
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV444P12
int64_t black_start
pts start time of the first black picture
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
#define AV_LOG_INFO
Standard information.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
#define i(width, name, range_min, range_max)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
static void check_black_end(AVFilterContext *ctx)
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
#define AV_PIX_FMT_YUV444P9
double picture_black_ratio_th
int64_t black_min_duration
minimum duration of detected black, expressed in timebase units
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
#define AV_PIX_FMT_YUVA444P9
unsigned int pixel_black_th_i
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
unsigned int nb_black_pixels
number of black pixels counted so far
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
#define AV_PIX_FMT_YUVA422P12
AVDictionary * metadata
metadata.
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
static enum AVPixelFormat pix_fmts[]
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static const int factor[16]
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVFILTER_DEFINE_CLASS(blackdetect)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_GRAY12
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14