1 /*
2 * Copyright (c) 2012 Stefano Sabatini
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * Video black detector, loosely based on blackframe with extended
24 * syntax and features
25 */
26
32
37 int64_t
black_start;
///< pts start time of the first black picture
38 int64_t
black_end;
///< pts end time of the last black picture
41
45
48
49 #define OFFSET(x) offsetof(BlackDetectContext, x)
50 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
51
54 {
"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 },
55 {
"picture_black_ratio_th",
"set the picture black ratio threshold",
OFFSET(picture_black_ratio_th),
AV_OPT_TYPE_DOUBLE, {.dbl=.98}, 0, 1,
FLAGS },
60 };
61
63
64 #define YUVJ_FORMATS \
65 AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P
66
69 };
70
72 {
81 };
82
84 if (!fmts_list)
87 }
88
90 {
93
96
98 // luminance_minimum_value + pixel_black_th * luminance_range_size
101
103 "black_min_duration:%s pixel_black_th:%f pixel_black_th_i:%d picture_black_ratio_th:%f\n",
107 return 0;
108 }
109
111 {
114
117 "black_start:%s black_end:%s black_duration:%s\n",
121 }
122 }
123
125 {
130
132 // FIXME: black_end should be set to last_picref_pts + last_picref_duration
135 }
136 return ret;
137 }
138
139 // TODO: document metadata
141 {
144 double picture_black_ratio = 0;
146 int x, i;
147
148 for (i = 0; i < inlink->
h; i++) {
149 for (x = 0; x < inlink->
w; x++)
152 }
153
154 picture_black_ratio = (double)blackdetect->
nb_black_pixels / (inlink->
w * inlink->
h);
155
157 "frame:%"PRId64" picture_black_ratio:%f pts:%s t:%s type:%c\n",
161
164 /* black starts here */
169 }
171 /* black ends here */
177 }
178
182 }
183
185 {
190 },
192 };
193
195 {
199 },
201 };
202
204 .
name =
"blackdetect",
208 .
inputs = blackdetect_inputs,
209 .
outputs = blackdetect_outputs,
210 .priv_class = &blackdetect_class,
211 };
This structure describes decoded (raw) audio or video data.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
int h
agreed upon image height
AVFilter ff_vf_blackdetect
unsigned int nb_black_pixels
number of black pixels counted so far
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
static const AVFilterPad blackdetect_inputs[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int config_input(AVFilterLink *inlink)
timestamp utils, mostly useful for debugging/logging purposes
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static int query_formats(AVFilterContext *ctx)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
AVDictionary * metadata
metadata.
int64_t black_min_duration
minimum duration of detected black, expressed in timebase units
double picture_black_ratio_th
A filter pad used for either input or output.
A link between two filters.
#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. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
static const AVFilterPad blackdetect_outputs[]
as above, but U and V bytes are swapped
enum AVPictureType pict_type
Picture type of the frame.
double black_min_duration_time
minimum duration of detected black, in seconds
int64_t last_picref_pts
pts of the last input picture
unsigned int pixel_black_th_i
AVFilterContext * src
source filter
AVFILTER_DEFINE_CLASS(blackdetect)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
int format
agreed upon media format
static void check_black_end(AVFilterContext *ctx)
#define AV_LOG_INFO
Standard information.
static enum AVPixelFormat yuvj_formats[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
int64_t black_end
pts end time of the last black picture
Describe the class of an AVClass context structure.
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int64_t black_start
pts start time of the first black picture
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
AVFilterContext * dst
dest filter
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static int request_frame(AVFilterLink *outlink)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static const AVOption blackdetect_options[]
AVPixelFormat
Pixel format.
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)