Commit 895e92ec authored by Stepan Bujnak's avatar Stepan Bujnak Committed by Michael Niedermayer

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: 's avatarStepan Bujnak <stepan.bujnak@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 880dbe43
......@@ -58,6 +58,10 @@ static int query_formats(AVFilterContext *ctx)
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)
{
AVFilterContext *ctx = inlink->dst;
......@@ -65,6 +69,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
int x, i;
int pblack = 0;
uint8_t *p = frame->data[0];
AVDictionary **metadata;
char buf[32];
for (i = 0; i < frame->height; i++) {
for (x = 0; x < inlink->w; x++)
......@@ -76,13 +82,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
s->last_keyframe = s->frame;
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 "
"type:%c last_keyframe:%d\n",
s->frame, pblack, frame->pts,
frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base),
av_get_picture_type_char(frame->pict_type), s->last_keyframe);
SET_META("lavfi.blackframe.pblack", "%u", pblack);
}
s->frame++;
s->nblack = 0;
return ff_filter_frame(inlink->dst->outputs[0], frame);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment