Blackframe video filter now sets metadata accordingly.

the libavfilter/vf_blackframe.c filter now not only logs detected
values, but also sets frame metadata. Currently, only `pblack` value is set
but `SET_META` macro has been introduced to ease development in the future.

Signed-off-by: Stepan Bujnak <stepan.bujnak@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Stepan Bujnak 2014-07-11 23:40:07 +02:00 committed by Michael Niedermayer
parent 880dbe43ca
commit 895e92eca0
1 changed files with 12 additions and 1 deletions

View File

@ -58,6 +58,10 @@ static int query_formats(AVFilterContext *ctx)
return 0; return 0;
} }
#define SET_META(key, format, value) \
snprintf(buf, sizeof(buf), format, value); \
av_dict_set(metadata, key, buf, 0)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame) static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
@ -65,6 +69,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
int x, i; int x, i;
int pblack = 0; int pblack = 0;
uint8_t *p = frame->data[0]; uint8_t *p = frame->data[0];
AVDictionary **metadata;
char buf[32];
for (i = 0; i < frame->height; i++) { for (i = 0; i < frame->height; i++) {
for (x = 0; x < inlink->w; x++) for (x = 0; x < inlink->w; x++)
@ -76,13 +82,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
s->last_keyframe = s->frame; s->last_keyframe = s->frame;
pblack = s->nblack * 100 / (inlink->w * inlink->h); pblack = s->nblack * 100 / (inlink->w * inlink->h);
if (pblack >= s->bamount) if (pblack >= s->bamount) {
metadata = avpriv_frame_get_metadatap(frame);
av_log(ctx, AV_LOG_INFO, "frame:%u pblack:%u pts:%"PRId64" t:%f " av_log(ctx, AV_LOG_INFO, "frame:%u pblack:%u pts:%"PRId64" t:%f "
"type:%c last_keyframe:%d\n", "type:%c last_keyframe:%d\n",
s->frame, pblack, frame->pts, s->frame, pblack, frame->pts,
frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base), frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base),
av_get_picture_type_char(frame->pict_type), s->last_keyframe); av_get_picture_type_char(frame->pict_type), s->last_keyframe);
SET_META("lavfi.blackframe.pblack", "%u", pblack);
}
s->frame++; s->frame++;
s->nblack = 0; s->nblack = 0;
return ff_filter_frame(inlink->dst->outputs[0], frame); return ff_filter_frame(inlink->dst->outputs[0], frame);