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 return 0;
85 }
86
88 {
91
94
96 // luminance_minimum_value + pixel_black_th * luminance_range_size
99
101 "black_min_duration:%s pixel_black_th:%f pixel_black_th_i:%d picture_black_ratio_th:%f\n",
105 return 0;
106 }
107
109 {
112
115 "black_start:%s black_end:%s black_duration:%s\n",
119 }
120 }
121
123 {
128
130 // FIXME: black_end should be set to last_picref_pts + last_picref_duration
133 }
135 }
136
137 // TODO: document metadata
139 {
142 double picture_black_ratio = 0;
144 int x, i;
145
146 for (i = 0; i < inlink->
h; i++) {
147 for (x = 0; x < inlink->
w; x++)
150 }
151
152 picture_black_ratio = (double)blackdetect->
nb_black_pixels / (inlink->
w * inlink->
h);
153
155 "frame:%"PRId64" picture_black_ratio:%f pts:%s t:%s type:%c\n",
159
162 /* black starts here */
167 }
169 /* black ends here */
175 }
176
180 }
181
183 {
188 },
190 };
191
193 {
197 },
199 };
200
202 .
name =
"blackdetect",
206 .
inputs = blackdetect_inputs,
207 .
outputs = blackdetect_outputs,
208 .priv_class = &blackdetect_class,
209 };