Browse code

lavfi/bbox: export bbox info to frame metadata

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2013/05/26 18:53:03
Showing 1 changed files
... ...
@@ -60,12 +60,17 @@ static int query_formats(AVFilterContext *ctx)
60 60
     return 0;
61 61
 }
62 62
 
63
+#define SET_META(key, value) \
64
+    snprintf(buf, sizeof(buf), "%d", value);  \
65
+    av_dict_set(metadata, #key, buf, 0); \
66
+
63 67
 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
64 68
 {
65 69
     AVFilterContext *ctx = inlink->dst;
66 70
     BBoxContext *bbox = ctx->priv;
67 71
     FFBoundingBox box;
68 72
     int has_bbox, w, h;
73
+    char buf[32];
69 74
 
70 75
     has_bbox =
71 76
         ff_calculate_bounding_box(&box,
... ...
@@ -79,6 +84,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
79 79
            av_ts2str(frame->pts), av_ts2timestr(frame->pts, &inlink->time_base));
80 80
 
81 81
     if (has_bbox) {
82
+        AVDictionary **metadata = avpriv_frame_get_metadatap(frame);
83
+
84
+        SET_META("lavfi.bbox.x1", box.x1)
85
+        SET_META("lavfi.bbox.x2", box.x2)
86
+        SET_META("lavfi.bbox.y1", box.y1)
87
+        SET_META("lavfi.bbox.y2", box.y2)
88
+        SET_META("lavfi.bbox.w",  w)
89
+        SET_META("lavfi.bbox.h",  h)
90
+
82 91
         av_log(ctx, AV_LOG_INFO,
83 92
                " x1:%d x2:%d y1:%d y2:%d w:%d h:%d"
84 93
                " crop=%d:%d:%d:%d drawbox=%d:%d:%d:%d",