summaryrefslogtreecommitdiff
path: root/libavfilter/vf_blackframe.c
diff options
context:
space:
mode:
authorStepan Bujnak <stepan.bujnak@gmail.com>2014-07-11 23:40:07 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-07-15 23:37:27 +0200
commit895e92eca0509e540e98913436533ae032552655 (patch)
treef17c53964ecc6f8cb6487ef79130e88a5a0d70fd /libavfilter/vf_blackframe.c
parent880dbe43ca71982ecdfe1c73446137d6b2fd24d5 (diff)
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>
Diffstat (limited to 'libavfilter/vf_blackframe.c')
-rw-r--r--libavfilter/vf_blackframe.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c
index 0eeda618f9..1be9fcca9d 100644
--- a/libavfilter/vf_blackframe.c
+++ b/libavfilter/vf_blackframe.c
@@ -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);