[FFmpeg-devel] [PATCH 4/4] lavfi/bbox: export drawbox, crop & bbox info to metadata

Paul B Mahol onemda at gmail.com
Sun May 26 16:08:34 CEST 2013


On 5/26/13, Stefano Sabatini <stefasab at gmail.com> wrote:
> On date Sunday 2013-05-26 10:00:58 +0000, Paul B Mahol encoded:
>> Signed-off-by: Paul B Mahol <onemda at gmail.com>
>> ---
>>  libavfilter/vf_bbox.c | 24 ++++++++++++++++++++++++
>>  1 file changed, 24 insertions(+)
>>
>> diff --git a/libavfilter/vf_bbox.c b/libavfilter/vf_bbox.c
>> index 2081e68..11ed395 100644
>> --- a/libavfilter/vf_bbox.c
>> +++ b/libavfilter/vf_bbox.c
>> @@ -60,12 +60,17 @@ static int query_formats(AVFilterContext *ctx)
>>      return 0;
>>  }
>>
>> +#define SET_META(key, value) \
>> +    snprintf(buf, sizeof(buf), "%d", value);  \
>> +    av_dict_set(metadata, #key, buf, 0); \
>> +
>>  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
>>  {
>>      AVFilterContext *ctx = inlink->dst;
>>      BBoxContext *bbox = ctx->priv;
>>      FFBoundingBox box;
>>      int has_bbox, w, h;
>> +    char buf[32];
>>
>>      has_bbox =
>>          ff_calculate_bounding_box(&box,
>> @@ -79,6 +84,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
>> *frame)
>>             av_ts2str(frame->pts), av_ts2timestr(frame->pts,
>> &inlink->time_base));
>>
>>      if (has_bbox) {
>> +        AVDictionary **metadata = avpriv_frame_get_metadatap(frame);
>> +
>
>> +        SET_META("lavfi.drawbox.x", box.x1)
>> +        SET_META("lavfi.drawbox.y", box.y1)
>> +        SET_META("lavfi.drawbox.w", w)
>> +        SET_META("lavfi.drawbox.h", h)
>> +
>> +        SET_META("lavfi.crop.w", w)
>> +        SET_META("lavfi.crop.h", h)
>> +        SET_META("lavfi.crop.x", box.x1)
>> +        SET_META("lavfi.crop.y", box.y1)
>
> I don't like this one. Indeed I don't think that a filter should set
> metadata for other filters, or we end up messing around with metadata
> all over the place.
>
> Also crop.w/h data might change at each frame, while it can't be
> changed on the fly by the crop filter (with no reconfiguration).
>
> A more generic way to deal with this would involve (again)
> scripting. In this specific case, you could create a custom filter
> which reads bbox data, and convert it to different metadata meant to
> be processed by another filter.

Removed.

>
>> +
>> +        SET_META("lavfi.bbox.x1", box.x1)
>> +        SET_META("lavfi.bbox.x2", box.x2)
>> +        SET_META("lavfi.bbox.y1", box.y1)
>> +        SET_META("lavfi.bbox.y2", box.y2)
>> +        SET_META("lavfi.bbox.w",  w)
>> +        SET_META("lavfi.bbox.h",  h)
>
> So I'd rather keep only this one for the moment, and avoid the user to
> rely on something which could/should be removed later when we have a
> more flexible mechanism. In the meanwhile it is still possible to
> write a custom C filter.

Applied with others.

> --
> FFmpeg = Fascinating and Fancy Majestic Purposeless Egregious Gadget
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list