FFmpeg
vf_dnn_detect.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * implementing an object detecting filter using deep learning networks.
22  */
23 
24 #include "libavutil/file_open.h"
25 #include "libavutil/opt.h"
26 #include "filters.h"
27 #include "dnn_filter_common.h"
28 #include "internal.h"
29 #include "libavutil/time.h"
30 #include "libavutil/avstring.h"
32 
33 typedef struct DnnDetectContext {
34  const AVClass *class;
36  float confidence;
38  char **labels;
41 
42 #define OFFSET(x) offsetof(DnnDetectContext, dnnctx.x)
43 #define OFFSET2(x) offsetof(DnnDetectContext, x)
44 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
45 static const AVOption dnn_detect_options[] = {
46  { "dnn_backend", "DNN backend", OFFSET(backend_type), AV_OPT_TYPE_INT, { .i64 = 2 }, INT_MIN, INT_MAX, FLAGS, "backend" },
47 #if (CONFIG_LIBTENSORFLOW == 1)
48  { "tensorflow", "tensorflow backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "backend" },
49 #endif
50 #if (CONFIG_LIBOPENVINO == 1)
51  { "openvino", "openvino backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, "backend" },
52 #endif
54  { "confidence", "threshold of confidence", OFFSET2(confidence), AV_OPT_TYPE_FLOAT, { .dbl = 0.5 }, 0, 1, FLAGS},
55  { "labels", "path to labels file", OFFSET2(labels_filename), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
56  { NULL }
57 };
58 
59 AVFILTER_DEFINE_CLASS(dnn_detect);
60 
62 {
64  float conf_threshold = ctx->confidence;
65  int proposal_count = output->height;
66  int detect_size = output->width;
67  float *detections = output->data;
68  int nb_bboxes = 0;
69  AVFrameSideData *sd;
70  AVDetectionBBox *bbox;
72 
74  if (sd) {
75  av_log(filter_ctx, AV_LOG_ERROR, "already have bounding boxes in side data.\n");
76  return -1;
77  }
78 
79  for (int i = 0; i < proposal_count; ++i) {
80  float conf = detections[i * detect_size + 2];
81  if (conf < conf_threshold) {
82  continue;
83  }
84  nb_bboxes++;
85  }
86 
87  if (nb_bboxes == 0) {
88  av_log(filter_ctx, AV_LOG_VERBOSE, "nothing detected in this frame.\n");
89  return 0;
90  }
91 
93  if (!header) {
94  av_log(filter_ctx, AV_LOG_ERROR, "failed to create side data with %d bounding boxes\n", nb_bboxes);
95  return -1;
96  }
97 
98  av_strlcpy(header->source, ctx->dnnctx.model_filename, sizeof(header->source));
99 
100  for (int i = 0; i < proposal_count; ++i) {
101  int av_unused image_id = (int)detections[i * detect_size + 0];
102  int label_id = (int)detections[i * detect_size + 1];
103  float conf = detections[i * detect_size + 2];
104  float x0 = detections[i * detect_size + 3];
105  float y0 = detections[i * detect_size + 4];
106  float x1 = detections[i * detect_size + 5];
107  float y1 = detections[i * detect_size + 6];
108 
109  bbox = av_get_detection_bbox(header, i);
110 
111  if (conf < conf_threshold) {
112  continue;
113  }
114 
115  bbox->x = (int)(x0 * frame->width);
116  bbox->w = (int)(x1 * frame->width) - bbox->x;
117  bbox->y = (int)(y0 * frame->height);
118  bbox->h = (int)(y1 * frame->height) - bbox->y;
119 
120  bbox->detect_confidence = av_make_q((int)(conf * 10000), 10000);
121  bbox->classify_count = 0;
122 
123  if (ctx->labels && label_id < ctx->label_count) {
124  av_strlcpy(bbox->detect_label, ctx->labels[label_id], sizeof(bbox->detect_label));
125  } else {
126  snprintf(bbox->detect_label, sizeof(bbox->detect_label), "%d", label_id);
127  }
128 
129  nb_bboxes--;
130  if (nb_bboxes == 0) {
131  break;
132  }
133  }
134 
135  return 0;
136 }
137 
139 {
141  int proposal_count;
142  float conf_threshold = ctx->confidence;
143  float *conf, *position, *label_id, x0, y0, x1, y1;
144  int nb_bboxes = 0;
145  AVFrameSideData *sd;
146  AVDetectionBBox *bbox;
148 
149  proposal_count = *(float *)(output[0].data);
150  conf = output[1].data;
151  position = output[3].data;
152  label_id = output[2].data;
153 
155  if (sd) {
156  av_log(filter_ctx, AV_LOG_ERROR, "already have dnn bounding boxes in side data.\n");
157  return -1;
158  }
159 
160  for (int i = 0; i < proposal_count; ++i) {
161  if (conf[i] < conf_threshold)
162  continue;
163  nb_bboxes++;
164  }
165 
166  if (nb_bboxes == 0) {
167  av_log(filter_ctx, AV_LOG_VERBOSE, "nothing detected in this frame.\n");
168  return 0;
169  }
170 
172  if (!header) {
173  av_log(filter_ctx, AV_LOG_ERROR, "failed to create side data with %d bounding boxes\n", nb_bboxes);
174  return -1;
175  }
176 
177  av_strlcpy(header->source, ctx->dnnctx.model_filename, sizeof(header->source));
178 
179  for (int i = 0; i < proposal_count; ++i) {
180  y0 = position[i * 4];
181  x0 = position[i * 4 + 1];
182  y1 = position[i * 4 + 2];
183  x1 = position[i * 4 + 3];
184 
185  bbox = av_get_detection_bbox(header, i);
186 
187  if (conf[i] < conf_threshold) {
188  continue;
189  }
190 
191  bbox->x = (int)(x0 * frame->width);
192  bbox->w = (int)(x1 * frame->width) - bbox->x;
193  bbox->y = (int)(y0 * frame->height);
194  bbox->h = (int)(y1 * frame->height) - bbox->y;
195 
196  bbox->detect_confidence = av_make_q((int)(conf[i] * 10000), 10000);
197  bbox->classify_count = 0;
198 
199  if (ctx->labels && label_id[i] < ctx->label_count) {
200  av_strlcpy(bbox->detect_label, ctx->labels[(int)label_id[i]], sizeof(bbox->detect_label));
201  } else {
202  snprintf(bbox->detect_label, sizeof(bbox->detect_label), "%d", (int)label_id[i]);
203  }
204 
205  nb_bboxes--;
206  if (nb_bboxes == 0) {
207  break;
208  }
209  }
210  return 0;
211 }
212 
214 {
216  DnnContext *dnn_ctx = &ctx->dnnctx;
217  switch (dnn_ctx->backend_type) {
218  case DNN_OV:
220  case DNN_TF:
222  default:
223  avpriv_report_missing_feature(filter_ctx, "Current dnn backend does not support detect filter\n");
224  return AVERROR(EINVAL);
225  }
226 }
227 
229 {
230  for (int i = 0; i < ctx->label_count; i++) {
231  av_freep(&ctx->labels[i]);
232  }
233  ctx->label_count = 0;
234  av_freep(&ctx->labels);
235 }
236 
238 {
239  int line_len;
240  FILE *file;
241  DnnDetectContext *ctx = context->priv;
242 
243  file = avpriv_fopen_utf8(ctx->labels_filename, "r");
244  if (!file){
245  av_log(context, AV_LOG_ERROR, "failed to open file %s\n", ctx->labels_filename);
246  return AVERROR(EINVAL);
247  }
248 
249  while (!feof(file)) {
250  char *label;
251  char buf[256];
252  if (!fgets(buf, 256, file)) {
253  break;
254  }
255 
256  line_len = strlen(buf);
257  while (line_len) {
258  int i = line_len - 1;
259  if (buf[i] == '\n' || buf[i] == '\r' || buf[i] == ' ') {
260  buf[i] = '\0';
261  line_len--;
262  } else {
263  break;
264  }
265  }
266 
267  if (line_len == 0) // empty line
268  continue;
269 
270  if (line_len >= AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE) {
271  av_log(context, AV_LOG_ERROR, "label %s too long\n", buf);
272  fclose(file);
273  return AVERROR(EINVAL);
274  }
275 
276  label = av_strdup(buf);
277  if (!label) {
278  av_log(context, AV_LOG_ERROR, "failed to allocate memory for label %s\n", buf);
279  fclose(file);
280  return AVERROR(ENOMEM);
281  }
282 
283  if (av_dynarray_add_nofree(&ctx->labels, &ctx->label_count, label) < 0) {
284  av_log(context, AV_LOG_ERROR, "failed to do av_dynarray_add\n");
285  fclose(file);
286  av_freep(&label);
287  return AVERROR(ENOMEM);
288  }
289  }
290 
291  fclose(file);
292  return 0;
293 }
294 
295 static int check_output_nb(DnnDetectContext *ctx, DNNBackendType backend_type, int output_nb)
296 {
297  switch(backend_type) {
298  case DNN_TF:
299  if (output_nb != 4) {
300  av_log(ctx, AV_LOG_ERROR, "Only support tensorflow detect model with 4 outputs, \
301  but get %d instead\n", output_nb);
302  return AVERROR(EINVAL);
303  }
304  return 0;
305  case DNN_OV:
306  if (output_nb != 1) {
307  av_log(ctx, AV_LOG_ERROR, "Dnn detect filter with openvino backend needs 1 output only, \
308  but get %d instead\n", output_nb);
309  return AVERROR(EINVAL);
310  }
311  return 0;
312  default:
313  avpriv_report_missing_feature(ctx, "Dnn detect filter does not support current backend\n");
314  return AVERROR(EINVAL);
315  }
316  return 0;
317 }
318 
320 {
321  DnnDetectContext *ctx = context->priv;
322  DnnContext *dnn_ctx = &ctx->dnnctx;
323  int ret;
324 
326  if (ret < 0)
327  return ret;
328  ret = check_output_nb(ctx, dnn_ctx->backend_type, dnn_ctx->nb_outputs);
329  if (ret < 0)
330  return ret;
332 
333  if (ctx->labels_filename) {
335  }
336  return 0;
337 }
338 
339 static const enum AVPixelFormat pix_fmts[] = {
346 };
347 
348 static int dnn_detect_flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
349 {
350  DnnDetectContext *ctx = outlink->src->priv;
351  int ret;
352  DNNAsyncStatusType async_state;
353 
354  ret = ff_dnn_flush(&ctx->dnnctx);
355  if (ret != 0) {
356  return -1;
357  }
358 
359  do {
360  AVFrame *in_frame = NULL;
361  AVFrame *out_frame = NULL;
362  async_state = ff_dnn_get_result(&ctx->dnnctx, &in_frame, &out_frame);
363  if (async_state == DAST_SUCCESS) {
364  ret = ff_filter_frame(outlink, in_frame);
365  if (ret < 0)
366  return ret;
367  if (out_pts)
368  *out_pts = in_frame->pts + pts;
369  }
370  av_usleep(5000);
371  } while (async_state >= DAST_NOT_READY);
372 
373  return 0;
374 }
375 
377 {
378  AVFilterLink *inlink = filter_ctx->inputs[0];
379  AVFilterLink *outlink = filter_ctx->outputs[0];
381  AVFrame *in = NULL;
382  int64_t pts;
383  int ret, status;
384  int got_frame = 0;
385  int async_state;
386 
388 
389  do {
390  // drain all input frames
392  if (ret < 0)
393  return ret;
394  if (ret > 0) {
395  if (ff_dnn_execute_model(&ctx->dnnctx, in, NULL) != 0) {
396  return AVERROR(EIO);
397  }
398  }
399  } while (ret > 0);
400 
401  // drain all processed frames
402  do {
403  AVFrame *in_frame = NULL;
404  AVFrame *out_frame = NULL;
405  async_state = ff_dnn_get_result(&ctx->dnnctx, &in_frame, &out_frame);
406  if (async_state == DAST_SUCCESS) {
407  ret = ff_filter_frame(outlink, in_frame);
408  if (ret < 0)
409  return ret;
410  got_frame = 1;
411  }
412  } while (async_state == DAST_SUCCESS);
413 
414  // if frame got, schedule to next filter
415  if (got_frame)
416  return 0;
417 
419  if (status == AVERROR_EOF) {
420  int64_t out_pts = pts;
421  ret = dnn_detect_flush_frame(outlink, pts, &out_pts);
422  ff_outlink_set_status(outlink, status, out_pts);
423  return ret;
424  }
425  }
426 
428 
429  return 0;
430 }
431 
433 {
434  DnnDetectContext *ctx = context->priv;
435  ff_dnn_uninit(&ctx->dnnctx);
437 }
438 
439 static const AVFilterPad dnn_detect_inputs[] = {
440  {
441  .name = "default",
442  .type = AVMEDIA_TYPE_VIDEO,
443  },
444 };
445 
446 static const AVFilterPad dnn_detect_outputs[] = {
447  {
448  .name = "default",
449  .type = AVMEDIA_TYPE_VIDEO,
450  },
451 };
452 
454  .name = "dnn_detect",
455  .description = NULL_IF_CONFIG_SMALL("Apply DNN detect filter to the input."),
456  .priv_size = sizeof(DnnDetectContext),
462  .priv_class = &dnn_detect_class,
463  .activate = dnn_detect_activate,
464 };
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_dnn_detect.c:339
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
filter_ctx
static FilteringContext * filter_ctx
Definition: transcoding.c:49
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:691
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1009
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:170
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_unused
#define av_unused
Definition: attributes.h:131
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:432
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(dnn_detect)
read_detect_label_file
static int read_detect_label_file(AVFilterContext *context)
Definition: vf_dnn_detect.c:237
AVOption
AVOption.
Definition: opt.h:251
data
const char data[16]
Definition: mxf.c:146
dnn_detect_init
static av_cold int dnn_detect_init(AVFilterContext *context)
Definition: vf_dnn_detect.c:319
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
dnn_detect_inputs
static const AVFilterPad dnn_detect_inputs[]
Definition: vf_dnn_detect.c:439
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
dnn_filter_common.h
AVDetectionBBox::y
int y
Definition: detection_bbox.h:32
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
dnn_detect_post_proc_ov
static int dnn_detect_post_proc_ov(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx)
Definition: vf_dnn_detect.c:61
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1404
AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE
#define AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE
Definition: detection_bbox.h:36
AVDetectionBBox::detect_label
char detect_label[AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE]
Detect result with confidence.
Definition: detection_bbox.h:41
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:430
DnnContext
Definition: dnn_filter_common.h:29
dnn_detect_uninit
static av_cold void dnn_detect_uninit(AVFilterContext *context)
Definition: vf_dnn_detect.c:432
DnnDetectContext
Definition: vf_dnn_detect.c:33
pts
static int64_t pts
Definition: transcode_aac.c:654
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
av_get_detection_bbox
static av_always_inline AVDetectionBBox * av_get_detection_bbox(const AVDetectionBBoxHeader *header, unsigned int idx)
Definition: detection_bbox.h:84
DNN_TF
@ DNN_TF
Definition: dnn_interface.h:35
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
ff_dnn_set_detect_post_proc
int ff_dnn_set_detect_post_proc(DnnContext *ctx, DetectPostProc post_proc)
Definition: dnn_filter_common.c:97
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:363
free_detect_labels
static void free_detect_labels(DnnDetectContext *ctx)
Definition: vf_dnn_detect.c:228
DNNData
Definition: dnn_interface.h:59
filters.h
ff_dnn_get_result
DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame)
Definition: dnn_filter_common.c:147
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ff_vf_dnn_detect
const AVFilter ff_vf_dnn_detect
Definition: vf_dnn_detect.c:453
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:491
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
file_open.h
DNN_OV
@ DNN_OV
Definition: dnn_interface.h:35
context
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Definition: writing_filters.txt:91
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
AVDetectionBBoxHeader
Definition: detection_bbox.h:56
DnnDetectContext::dnnctx
DnnContext dnnctx
Definition: vf_dnn_detect.c:35
dnn_detect_activate
static int dnn_detect_activate(AVFilterContext *filter_ctx)
Definition: vf_dnn_detect.c:376
DnnDetectContext::labels_filename
char * labels_filename
Definition: vf_dnn_detect.c:37
DnnDetectContext::labels
char ** labels
Definition: vf_dnn_detect.c:38
time.h
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
ff_dnn_flush
int ff_dnn_flush(DnnContext *ctx)
Definition: dnn_filter_common.c:152
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1358
FLAGS
#define FLAGS
Definition: vf_dnn_detect.c:44
av_detection_bbox_create_side_data
AVDetectionBBoxHeader * av_detection_bbox_create_side_data(AVFrame *frame, uint32_t nb_bboxes)
Allocates memory for AVDetectionBBoxHeader, plus an array of.
Definition: detection_bbox.c:51
DNN_COMMON_OPTIONS
#define DNN_COMMON_OPTIONS
Definition: dnn_filter_common.h:43
DnnContext::backend_type
DNNBackendType backend_type
Definition: dnn_filter_common.h:31
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:115
DnnDetectContext::label_count
int label_count
Definition: vf_dnn_detect.c:39
DAST_SUCCESS
@ DAST_SUCCESS
Definition: dnn_interface.h:49
AVDetectionBBox::w
int w
Definition: detection_bbox.h:33
DNNBackendType
DNNBackendType
Definition: dnn_interface.h:35
DnnContext::nb_outputs
uint32_t nb_outputs
Definition: dnn_filter_common.h:38
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
header
static const uint8_t header[24]
Definition: sdr2.c:67
AVDetectionBBox::classify_count
uint32_t classify_count
Definition: detection_bbox.h:51
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
dnn_detect_options
static const AVOption dnn_detect_options[]
Definition: vf_dnn_detect.c:45
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
dnn_detect_flush_frame
static int dnn_detect_flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
Definition: vf_dnn_detect.c:348
dnn_detect_post_proc
static int dnn_detect_post_proc(AVFrame *frame, DNNData *output, uint32_t nb, AVFilterContext *filter_ctx)
Definition: vf_dnn_detect.c:213
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
DFT_ANALYTICS_DETECT
@ DFT_ANALYTICS_DETECT
Definition: dnn_interface.h:55
check_output_nb
static int check_output_nb(DnnDetectContext *ctx, DNNBackendType backend_type, int output_nb)
Definition: vf_dnn_detect.c:295
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
avpriv_fopen_utf8
FILE * avpriv_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
Definition: file_open.c:159
DnnDetectContext::confidence
float confidence
Definition: vf_dnn_detect.c:36
AVFilter
Filter definition.
Definition: avfilter.h:171
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVDetectionBBox::h
int h
Definition: detection_bbox.h:34
AVDetectionBBox::detect_confidence
AVRational detect_confidence
Definition: detection_bbox.h:42
av_dynarray_add_nofree
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:323
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVDetectionBBox::x
int x
Distance in pixels from the left/top edge of the frame, together with width and height,...
Definition: detection_bbox.h:31
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:415
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
OFFSET
#define OFFSET(x)
Definition: vf_dnn_detect.c:42
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:231
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
ff_dnn_init
int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
Definition: dnn_filter_common.c:54
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
dnn_detect_outputs
static const AVFilterPad dnn_detect_outputs[]
Definition: vf_dnn_detect.c:446
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
av_strlcpy
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:86
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_dnn_uninit
void ff_dnn_uninit(DnnContext *ctx)
Definition: dnn_filter_common.c:157
AVDetectionBBox
Definition: detection_bbox.h:26
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:285
dnn_detect_post_proc_tf
static int dnn_detect_post_proc_tf(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx)
Definition: vf_dnn_detect.c:138
ff_dnn_execute_model
int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
Definition: dnn_filter_common.c:120
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
DAST_NOT_READY
@ DAST_NOT_READY
Definition: dnn_interface.h:48
int
int
Definition: ffmpeg_filter.c:156
DNNAsyncStatusType
DNNAsyncStatusType
Definition: dnn_interface.h:45
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
snprintf
#define snprintf
Definition: snprintf.h:34
OFFSET2
#define OFFSET2(x)
Definition: vf_dnn_detect.c:43
detection_bbox.h
AV_FRAME_DATA_DETECTION_BBOXES
@ AV_FRAME_DATA_DETECTION_BBOXES
Bounding boxes for object detection and classification, as described by AVDetectionBBoxHeader.
Definition: frame.h:190