[FFmpeg-devel] [PATCH V6 5/6] lavfi: show side data of bounding box

Guo, Yejun yejun.guo at intel.com
Fri Mar 26 10:09:30 EET 2021


Signed-off-by: Guo, Yejun <yejun.guo at intel.com>
---
 libavfilter/f_sidedata.c  |  2 ++
 libavfilter/vf_showinfo.c | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/libavfilter/f_sidedata.c b/libavfilter/f_sidedata.c
index 3757723375..912fb0d881 100644
--- a/libavfilter/f_sidedata.c
+++ b/libavfilter/f_sidedata.c
@@ -71,6 +71,7 @@ static const AVOption filt_name##_options[] = { \
     {   "S12M_TIMECOD",               "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_S12M_TIMECODE              }, 0, 0, FLAGS, "type" }, \
     {   "DYNAMIC_HDR_PLUS",           "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_DYNAMIC_HDR_PLUS           }, 0, 0, FLAGS, "type" }, \
     {   "REGIONS_OF_INTEREST",        "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_REGIONS_OF_INTEREST        }, 0, 0, FLAGS, "type" }, \
+    {   "BOUNDING_BOXES",             "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_BOUNDING_BOXES             }, 0, 0, FLAGS, "type" }, \
     {   "SEI_UNREGISTERED",           "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_SEI_UNREGISTERED           }, 0, 0, FLAGS, "type" }, \
     { NULL } \
 }
@@ -100,6 +101,7 @@ static const AVOption filt_name##_options[] = { \
     {   "S12M_TIMECOD",               "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_S12M_TIMECODE              }, 0, 0, FLAGS, "type" }, \
     {   "DYNAMIC_HDR_PLUS",           "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_DYNAMIC_HDR_PLUS           }, 0, 0, FLAGS, "type" }, \
     {   "REGIONS_OF_INTEREST",        "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_REGIONS_OF_INTEREST        }, 0, 0, FLAGS, "type" }, \
+    {   "BOUNDING_BOXES",             "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_BOUNDING_BOXES             }, 0, 0, FLAGS, "type" }, \
     {   "SEI_UNREGISTERED",           "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_SEI_UNREGISTERED           }, 0, 0, FLAGS, "type" }, \
     { NULL } \
 }
diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 6208892005..3d8bc2634e 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -38,6 +38,7 @@
 #include "libavutil/timecode.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/video_enc_params.h"
+#include "libavutil/boundingbox.h"
 
 #include "avfilter.h"
 #include "internal.h"
@@ -153,6 +154,39 @@ static void dump_roi(AVFilterContext *ctx, const AVFrameSideData *sd)
     }
 }
 
+static void dump_boundingbox(AVFilterContext *ctx, const AVFrameSideData *sd)
+{
+    int nb_bbox;
+    const AVBoundingBoxHeader *header;
+    const AVBoundingBox *bbox;
+    uint32_t array_size;
+
+    header = (const AVBoundingBoxHeader *)sd->data;
+    nb_bbox = header->nb_bbox;
+    array_size = sd->size - sizeof(*header);
+    if (!nb_bbox || array_size % nb_bbox != 0 || array_size / nb_bbox != sizeof(*bbox)) {
+        av_log(ctx, AV_LOG_ERROR, "Invalid AVBoundingBoxHeader.nb_bbox.\n");
+        return;
+    }
+
+    bbox = header->bboxes;
+
+    av_log(ctx, AV_LOG_INFO, "bounding boxes:\n");
+    av_log(ctx, AV_LOG_INFO, "source: %s\n", header->source);
+    for (int i = 0; i < nb_bbox; i++) {
+        av_log(ctx, AV_LOG_INFO, "index: %d,\tregion: (%d, %d) -> (%d, %d), label: %s, confidence: %d/%d.\n",
+                                 i, bbox->left, bbox->top, bbox->right, bbox->bottom,
+                                 bbox->detect_label, bbox->detect_confidence.num, bbox->detect_confidence.den);
+        if (bbox->classify_count > 0) {
+            for (int j = 0; j < bbox->classify_count; j++) {
+                av_log(ctx, AV_LOG_INFO, "\t\tclassify:  label: %s, confidence: %d/%d.\n",
+                       bbox->classify_labels[j], bbox->classify_confidences[j].num, bbox->classify_confidences[j].den);
+            }
+        }
+        bbox++;
+    }
+}
+
 static void dump_mastering_display(AVFilterContext *ctx, const AVFrameSideData *sd)
 {
     const AVMasteringDisplayMetadata *mastering_display;
@@ -494,6 +528,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         case AV_FRAME_DATA_REGIONS_OF_INTEREST:
             dump_roi(ctx, sd);
             break;
+        case AV_FRAME_DATA_BOUNDING_BOXES:
+            dump_boundingbox(ctx, sd);
+            break;
         case AV_FRAME_DATA_MASTERING_DISPLAY_METADATA:
             dump_mastering_display(ctx, sd);
             break;
-- 
2.17.1



More information about the ffmpeg-devel mailing list