[FFmpeg-devel] [PATCH] lavfi/blackdetect: switch to new shiny ff_filter_frame() API
Stefano Sabatini
stefasab at gmail.com
Sun Dec 2 01:53:35 CET 2012
---
libavfilter/vf_blackdetect.c | 40 ++++++++++++++--------------------------
1 file changed, 14 insertions(+), 26 deletions(-)
diff --git a/libavfilter/vf_blackdetect.c b/libavfilter/vf_blackdetect.c
index a981212..4ebfb36 100644
--- a/libavfilter/vf_blackdetect.c
+++ b/libavfilter/vf_blackdetect.c
@@ -36,7 +36,7 @@ typedef struct {
int64_t black_min_duration; ///< minimum duration of detected black, expressed in timebase units
int64_t black_start; ///< pts start time of the first black picture
int64_t black_end; ///< pts end time of the last black picture
- int64_t last_picref_pts; ///< pts of the last input picture
+ int64_t last_frame_pts; ///< pts of the last input picture
int black_started;
double picture_black_ratio_th;
@@ -140,61 +140,51 @@ static int request_frame(AVFilterLink *outlink)
if (ret == AVERROR_EOF && blackdetect->black_started) {
// FIXME: black_end should be set to last_picref_pts + last_picref_duration
- blackdetect->black_end = blackdetect->last_picref_pts;
+ blackdetect->black_end = blackdetect->last_frame_pts;
check_black_end(ctx);
}
return ret;
}
-static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
{
AVFilterContext *ctx = inlink->dst;
BlackDetectContext *blackdetect = ctx->priv;
- AVFilterBufferRef *picref = inlink->cur_buf;
+ double picture_black_ratio = 0;
+ const uint8_t *p = frame->data[0];
int x, i;
- const uint8_t *p = picref->data[0] + y * picref->linesize[0];
- for (i = 0; i < h; i++) {
+ for (i = 0; i < inlink->h; i++) {
for (x = 0; x < inlink->w; x++)
blackdetect->nb_black_pixels += p[x] <= blackdetect->pixel_black_th_i;
- p += picref->linesize[0];
+ p += frame->linesize[0];
}
- return ff_draw_slice(ctx->outputs[0], y, h, slice_dir);
-}
-
-static int end_frame(AVFilterLink *inlink)
-{
- AVFilterContext *ctx = inlink->dst;
- BlackDetectContext *blackdetect = ctx->priv;
- AVFilterBufferRef *picref = inlink->cur_buf;
- double picture_black_ratio = 0;
-
picture_black_ratio = (double)blackdetect->nb_black_pixels / (inlink->w * inlink->h);
av_log(ctx, AV_LOG_DEBUG,
"frame:%u picture_black_ratio:%f pos:%"PRId64" pts:%s t:%s type:%c\n",
blackdetect->frame_count, picture_black_ratio,
- picref->pos, av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base),
- av_get_picture_type_char(picref->video->pict_type));
+ frame->pos, av_ts2str(frame->pts), av_ts2timestr(frame->pts, &inlink->time_base),
+ av_get_picture_type_char(frame->video->pict_type));
if (picture_black_ratio >= blackdetect->picture_black_ratio_th) {
if (!blackdetect->black_started) {
/* black starts here */
blackdetect->black_started = 1;
- blackdetect->black_start = picref->pts;
+ blackdetect->black_start = frame->pts;
}
} else if (blackdetect->black_started) {
/* black ends here */
blackdetect->black_started = 0;
- blackdetect->black_end = picref->pts;
+ blackdetect->black_end = frame->pts;
check_black_end(ctx);
}
- blackdetect->last_picref_pts = picref->pts;
+ blackdetect->last_frame_pts = frame->pts;
blackdetect->frame_count++;
blackdetect->nb_black_pixels = 0;
- return ff_end_frame(inlink->dst->outputs[0]);
+ return ff_filter_frame(inlink->dst->outputs[0], frame);
}
static const AVFilterPad blackdetect_inputs[] = {
@@ -202,10 +192,8 @@ static const AVFilterPad blackdetect_inputs[] = {
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.config_props = config_input,
- .draw_slice = draw_slice,
.get_video_buffer = ff_null_get_video_buffer,
- .start_frame = ff_null_start_frame,
- .end_frame = end_frame,
+ .filter_frame = filter_frame,
},
{ NULL }
};
--
1.7.9.5
More information about the ffmpeg-devel
mailing list