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 "libavformat/avio.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/avassert.h"
28 #include "libavutil/imgutils.h"
29 #include "filters.h"
30 #include "dnn_filter_common.h"
31 #include "formats.h"
32 #include "internal.h"
33 #include "libavutil/time.h"
34 #include "libavutil/avstring.h"
36 
37 typedef struct DnnDetectContext {
38  const AVClass *class;
40  float confidence;
42  char **labels;
45 
46 #define OFFSET(x) offsetof(DnnDetectContext, dnnctx.x)
47 #define OFFSET2(x) offsetof(DnnDetectContext, x)
48 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
49 static const AVOption dnn_detect_options[] = {
50  { "dnn_backend", "DNN backend", OFFSET(backend_type), AV_OPT_TYPE_INT, { .i64 = 2 }, INT_MIN, INT_MAX, FLAGS, "backend" },
51 #if (CONFIG_LIBTENSORFLOW == 1)
52  { "tensorflow", "tensorflow backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "backend" },
53 #endif
54 #if (CONFIG_LIBOPENVINO == 1)
55  { "openvino", "openvino backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, "backend" },
56 #endif
58  { "confidence", "threshold of confidence", OFFSET2(confidence), AV_OPT_TYPE_FLOAT, { .dbl = 0.5 }, 0, 1, FLAGS},
59  { "labels", "path to labels file", OFFSET2(labels_filename), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
60  { NULL }
61 };
62 
63 AVFILTER_DEFINE_CLASS(dnn_detect);
64 
66 {
68  float conf_threshold = ctx->confidence;
69  int proposal_count = output->height;
70  int detect_size = output->width;
71  float *detections = output->data;
72  int nb_bboxes = 0;
73  AVFrameSideData *sd;
74  AVDetectionBBox *bbox;
76 
78  if (sd) {
79  av_log(filter_ctx, AV_LOG_ERROR, "already have bounding boxes in side data.\n");
80  return -1;
81  }
82 
83  for (int i = 0; i < proposal_count; ++i) {
84  float conf = detections[i * detect_size + 2];
85  if (conf < conf_threshold) {
86  continue;
87  }
88  nb_bboxes++;
89  }
90 
91  if (nb_bboxes == 0) {
92  av_log(filter_ctx, AV_LOG_VERBOSE, "nothing detected in this frame.\n");
93  return 0;
94  }
95 
97  if (!header) {
98  av_log(filter_ctx, AV_LOG_ERROR, "failed to create side data with %d bounding boxes\n", nb_bboxes);
99  return -1;
100  }
101 
102  av_strlcpy(header->source, ctx->dnnctx.model_filename, sizeof(header->source));
103 
104  for (int i = 0; i < proposal_count; ++i) {
105  int av_unused image_id = (int)detections[i * detect_size + 0];
106  int label_id = (int)detections[i * detect_size + 1];
107  float conf = detections[i * detect_size + 2];
108  float x0 = detections[i * detect_size + 3];
109  float y0 = detections[i * detect_size + 4];
110  float x1 = detections[i * detect_size + 5];
111  float y1 = detections[i * detect_size + 6];
112 
113  bbox = av_get_detection_bbox(header, i);
114 
115  if (conf < conf_threshold) {
116  continue;
117  }
118 
119  bbox->x = (int)(x0 * frame->width);
120  bbox->w = (int)(x1 * frame->width) - bbox->x;
121  bbox->y = (int)(y0 * frame->height);
122  bbox->h = (int)(y1 * frame->height) - bbox->y;
123 
124  bbox->detect_confidence = av_make_q((int)(conf * 10000), 10000);
125  bbox->classify_count = 0;
126 
127  if (ctx->labels && label_id < ctx->label_count) {
128  av_strlcpy(bbox->detect_label, ctx->labels[label_id], sizeof(bbox->detect_label));
129  } else {
130  snprintf(bbox->detect_label, sizeof(bbox->detect_label), "%d", label_id);
131  }
132 
133  nb_bboxes--;
134  if (nb_bboxes == 0) {
135  break;
136  }
137  }
138 
139  return 0;
140 }
141 
143 {
145  int proposal_count;
146  float conf_threshold = ctx->confidence;
147  float *conf, *position, *label_id, x0, y0, x1, y1;
148  int nb_bboxes = 0;
149  AVFrameSideData *sd;
150  AVDetectionBBox *bbox;
152 
153  proposal_count = *(float *)(output[0].data);
154  conf = output[1].data;
155  position = output[3].data;
156  label_id = output[2].data;
157 
159  if (sd) {
160  av_log(filter_ctx, AV_LOG_ERROR, "already have dnn bounding boxes in side data.\n");
161  return -1;
162  }
163 
164  for (int i = 0; i < proposal_count; ++i) {
165  if (conf[i] < conf_threshold)
166  continue;
167  nb_bboxes++;
168  }
169 
170  if (nb_bboxes == 0) {
171  av_log(filter_ctx, AV_LOG_VERBOSE, "nothing detected in this frame.\n");
172  return 0;
173  }
174 
176  if (!header) {
177  av_log(filter_ctx, AV_LOG_ERROR, "failed to create side data with %d bounding boxes\n", nb_bboxes);
178  return -1;
179  }
180 
181  av_strlcpy(header->source, ctx->dnnctx.model_filename, sizeof(header->source));
182 
183  for (int i = 0; i < proposal_count; ++i) {
184  y0 = position[i * 4];
185  x0 = position[i * 4 + 1];
186  y1 = position[i * 4 + 2];
187  x1 = position[i * 4 + 3];
188 
189  bbox = av_get_detection_bbox(header, i);
190 
191  if (conf[i] < conf_threshold) {
192  continue;
193  }
194 
195  bbox->x = (int)(x0 * frame->width);
196  bbox->w = (int)(x1 * frame->width) - bbox->x;
197  bbox->y = (int)(y0 * frame->height);
198  bbox->h = (int)(y1 * frame->height) - bbox->y;
199 
200  bbox->detect_confidence = av_make_q((int)(conf[i] * 10000), 10000);
201  bbox->classify_count = 0;
202 
203  if (ctx->labels && label_id[i] < ctx->label_count) {
204  av_strlcpy(bbox->detect_label, ctx->labels[(int)label_id[i]], sizeof(bbox->detect_label));
205  } else {
206  snprintf(bbox->detect_label, sizeof(bbox->detect_label), "%d", (int)label_id[i]);
207  }
208 
209  nb_bboxes--;
210  if (nb_bboxes == 0) {
211  break;
212  }
213  }
214  return 0;
215 }
216 
218 {
220  DnnContext *dnn_ctx = &ctx->dnnctx;
221  switch (dnn_ctx->backend_type) {
222  case DNN_OV:
224  case DNN_TF:
226  default:
227  avpriv_report_missing_feature(filter_ctx, "Current dnn backend does not support detect filter\n");
228  return AVERROR(EINVAL);
229  }
230 }
231 
233 {
234  for (int i = 0; i < ctx->label_count; i++) {
235  av_freep(&ctx->labels[i]);
236  }
237  ctx->label_count = 0;
238  av_freep(&ctx->labels);
239 }
240 
242 {
243  int line_len;
244  FILE *file;
245  DnnDetectContext *ctx = context->priv;
246 
247  file = av_fopen_utf8(ctx->labels_filename, "r");
248  if (!file){
249  av_log(context, AV_LOG_ERROR, "failed to open file %s\n", ctx->labels_filename);
250  return AVERROR(EINVAL);
251  }
252 
253  while (!feof(file)) {
254  char *label;
255  char buf[256];
256  if (!fgets(buf, 256, file)) {
257  break;
258  }
259 
260  line_len = strlen(buf);
261  while (line_len) {
262  int i = line_len - 1;
263  if (buf[i] == '\n' || buf[i] == '\r' || buf[i] == ' ') {
264  buf[i] = '\0';
265  line_len--;
266  } else {
267  break;
268  }
269  }
270 
271  if (line_len == 0) // empty line
272  continue;
273 
274  if (line_len >= AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE) {
275  av_log(context, AV_LOG_ERROR, "label %s too long\n", buf);
276  fclose(file);
277  return AVERROR(EINVAL);
278  }
279 
280  label = av_strdup(buf);
281  if (!label) {
282  av_log(context, AV_LOG_ERROR, "failed to allocate memory for label %s\n", buf);
283  fclose(file);
284  return AVERROR(ENOMEM);
285  }
286 
287  if (av_dynarray_add_nofree(&ctx->labels, &ctx->label_count, label) < 0) {
288  av_log(context, AV_LOG_ERROR, "failed to do av_dynarray_add\n");
289  fclose(file);
290  av_freep(&label);
291  return AVERROR(ENOMEM);
292  }
293  }
294 
295  fclose(file);
296  return 0;
297 }
298 
299 static int check_output_nb(DnnDetectContext *ctx, DNNBackendType backend_type, int output_nb)
300 {
301  switch(backend_type) {
302  case DNN_TF:
303  if (output_nb != 4) {
304  av_log(ctx, AV_LOG_ERROR, "Only support tensorflow detect model with 4 outputs, \
305  but get %d instead\n", output_nb);
306  return AVERROR(EINVAL);
307  }
308  return 0;
309  case DNN_OV:
310  if (output_nb != 1) {
311  av_log(ctx, AV_LOG_ERROR, "Dnn detect filter with openvino backend needs 1 output only, \
312  but get %d instead\n", output_nb);
313  return AVERROR(EINVAL);
314  }
315  return 0;
316  default:
317  avpriv_report_missing_feature(ctx, "Dnn detect filter does not support current backend\n");
318  return AVERROR(EINVAL);
319  }
320  return 0;
321 }
322 
324 {
325  DnnDetectContext *ctx = context->priv;
326  DnnContext *dnn_ctx = &ctx->dnnctx;
327  int ret;
328 
330  if (ret < 0)
331  return ret;
332  ret = check_output_nb(ctx, dnn_ctx->backend_type, dnn_ctx->nb_outputs);
333  if (ret < 0)
334  return ret;
336 
337  if (ctx->labels_filename) {
339  }
340  return 0;
341 }
342 
344 {
345  static const enum AVPixelFormat pix_fmts[] = {
352  };
354  return ff_set_common_formats(context, fmts_list);
355 }
356 
358 {
360  AVFilterLink *outlink = context->outputs[0];
361  DnnDetectContext *ctx = context->priv;
362  DNNReturnType dnn_result;
363 
364  dnn_result = ff_dnn_execute_model(&ctx->dnnctx, in, in);
365  if (dnn_result != DNN_SUCCESS){
366  av_log(ctx, AV_LOG_ERROR, "failed to execute model\n");
367  av_frame_free(&in);
368  return AVERROR(EIO);
369  }
370 
371  return ff_filter_frame(outlink, in);
372 }
373 
375 {
376  AVFilterLink *inlink = filter_ctx->inputs[0];
377  AVFilterLink *outlink = filter_ctx->outputs[0];
378  AVFrame *in = NULL;
379  int64_t pts;
380  int ret, status;
381  int got_frame = 0;
382 
384 
385  do {
386  // drain all input frames
388  if (ret < 0)
389  return ret;
390  if (ret > 0) {
392  if (ret < 0)
393  return ret;
394  got_frame = 1;
395  }
396  } while (ret > 0);
397 
398  // if frame got, schedule to next filter
399  if (got_frame)
400  return 0;
401 
403  if (status == AVERROR_EOF) {
404  ff_outlink_set_status(outlink, status, pts);
405  return ret;
406  }
407  }
408 
410 
411  return FFERROR_NOT_READY;
412 }
413 
414 static int dnn_detect_flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
415 {
416  DnnDetectContext *ctx = outlink->src->priv;
417  int ret;
418  DNNAsyncStatusType async_state;
419 
420  ret = ff_dnn_flush(&ctx->dnnctx);
421  if (ret != DNN_SUCCESS) {
422  return -1;
423  }
424 
425  do {
426  AVFrame *in_frame = NULL;
427  AVFrame *out_frame = NULL;
428  async_state = ff_dnn_get_async_result(&ctx->dnnctx, &in_frame, &out_frame);
429  if (out_frame) {
430  av_assert0(in_frame == out_frame);
431  ret = ff_filter_frame(outlink, out_frame);
432  if (ret < 0)
433  return ret;
434  if (out_pts)
435  *out_pts = out_frame->pts + pts;
436  }
437  av_usleep(5000);
438  } while (async_state >= DAST_NOT_READY);
439 
440  return 0;
441 }
442 
444 {
445  AVFilterLink *inlink = filter_ctx->inputs[0];
446  AVFilterLink *outlink = filter_ctx->outputs[0];
448  AVFrame *in = NULL;
449  int64_t pts;
450  int ret, status;
451  int got_frame = 0;
452  int async_state;
453 
455 
456  do {
457  // drain all input frames
459  if (ret < 0)
460  return ret;
461  if (ret > 0) {
462  if (ff_dnn_execute_model_async(&ctx->dnnctx, in, in) != DNN_SUCCESS) {
463  return AVERROR(EIO);
464  }
465  }
466  } while (ret > 0);
467 
468  // drain all processed frames
469  do {
470  AVFrame *in_frame = NULL;
471  AVFrame *out_frame = NULL;
472  async_state = ff_dnn_get_async_result(&ctx->dnnctx, &in_frame, &out_frame);
473  if (out_frame) {
474  av_assert0(in_frame == out_frame);
475  ret = ff_filter_frame(outlink, out_frame);
476  if (ret < 0)
477  return ret;
478  got_frame = 1;
479  }
480  } while (async_state == DAST_SUCCESS);
481 
482  // if frame got, schedule to next filter
483  if (got_frame)
484  return 0;
485 
487  if (status == AVERROR_EOF) {
488  int64_t out_pts = pts;
489  ret = dnn_detect_flush_frame(outlink, pts, &out_pts);
490  ff_outlink_set_status(outlink, status, out_pts);
491  return ret;
492  }
493  }
494 
496 
497  return 0;
498 }
499 
501 {
503 
504  if (ctx->dnnctx.async)
506  else
508 }
509 
511 {
512  DnnDetectContext *ctx = context->priv;
513  ff_dnn_uninit(&ctx->dnnctx);
515 }
516 
517 static const AVFilterPad dnn_detect_inputs[] = {
518  {
519  .name = "default",
520  .type = AVMEDIA_TYPE_VIDEO,
521  },
522  { NULL }
523 };
524 
525 static const AVFilterPad dnn_detect_outputs[] = {
526  {
527  .name = "default",
528  .type = AVMEDIA_TYPE_VIDEO,
529  },
530  { NULL }
531 };
532 
534  .name = "dnn_detect",
535  .description = NULL_IF_CONFIG_SMALL("Apply DNN detect filter to the input."),
536  .priv_size = sizeof(DnnDetectContext),
542  .priv_class = &dnn_detect_class,
544 };
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
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
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:48
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:616
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
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
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:111
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:396
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:241
AVOption
AVOption.
Definition: opt.h:248
data
const char data[16]
Definition: mxf.c:142
dnn_detect_init
static av_cold int dnn_detect_init(AVFilterContext *context)
Definition: vf_dnn_detect.c:323
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:197
dnn_detect_inputs
static const AVFilterPad dnn_detect_inputs[]
Definition: vf_dnn_detect.c:517
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:149
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:65
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:65
formats.h
dnn_detect_filter_frame
static int dnn_detect_filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_dnn_detect.c:357
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:1376
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:348
DnnContext
Definition: dnn_filter_common.h:29
DNN_SUCCESS
@ DNN_SUCCESS
Definition: dnn_interface.h:33
dnn_detect_uninit
static av_cold void dnn_detect_uninit(AVFilterContext *context)
Definition: vf_dnn_detect.c:510
DnnDetectContext
Definition: vf_dnn_detect.c:37
pts
static int64_t pts
Definition: transcode_aac.c:652
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
av_get_detection_bbox
static av_always_inline AVDetectionBBox * av_get_detection_bbox(const AVDetectionBBoxHeader *header, unsigned int idx)
Definition: detection_bbox.h:84
avassert.h
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:181
av_cold
#define av_cold
Definition: attributes.h:90
inputs
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 inputs
Definition: filter_design.txt:243
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:580
av_fopen_utf8
FILE * av_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
Definition: file_open.c:158
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:109
free_detect_labels
static void free_detect_labels(DnnDetectContext *ctx)
Definition: vf_dnn_detect.c:232
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
DNNReturnType
DNNReturnType
Definition: dnn_interface.h:33
DNNData
Definition: dnn_interface.h:59
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:289
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ff_vf_dnn_detect
const AVFilter ff_vf_dnn_detect
Definition: vf_dnn_detect.c:533
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:421
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:67
NULL
#define NULL
Definition: coverity.c:32
AVDetectionBBoxHeader
Definition: detection_bbox.h:56
DnnDetectContext::dnnctx
DnnContext dnnctx
Definition: vf_dnn_detect.c:39
activate
filter_frame For filters that do not use the activate() callback
dnn_detect_activate
static int dnn_detect_activate(AVFilterContext *filter_ctx)
Definition: vf_dnn_detect.c:500
DnnDetectContext::labels_filename
char * labels_filename
Definition: vf_dnn_detect.c:41
DnnDetectContext::labels
char ** labels
Definition: vf_dnn_detect.c:42
time.h
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
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:1331
FLAGS
#define FLAGS
Definition: vf_dnn_detect.c:48
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:48
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:117
DnnDetectContext::label_count
int label_count
Definition: vf_dnn_detect.c:43
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
avio.h
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:49
ff_dnn_execute_model_async
DNNReturnType ff_dnn_execute_model_async(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
Definition: dnn_filter_common.c:144
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:414
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:217
i
int i
Definition: input.c:407
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:299
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
DnnDetectContext::confidence
float confidence
Definition: vf_dnn_detect.c:40
dnn_detect_query_formats
static int dnn_detect_query_formats(AVFilterContext *context)
Definition: vf_dnn_detect.c:343
AVFilter
Filter definition.
Definition: avfilter.h:145
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:302
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:333
dnn_detect_activate_sync
static int dnn_detect_activate_sync(AVFilterContext *filter_ctx)
Definition: vf_dnn_detect.c:374
dnn_detect_activate_async
static int dnn_detect_activate_async(AVFilterContext *filter_ctx)
Definition: vf_dnn_detect.c:443
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:259
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:46
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:209
ff_dnn_execute_model
DNNReturnType ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
Definition: dnn_filter_common.c:132
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:35
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:525
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
ff_dnn_flush
DNNReturnType ff_dnn_flush(DnnContext *ctx)
Definition: dnn_filter_common.c:176
imgutils.h
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:83
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_dnn_uninit
void ff_dnn_uninit(DnnContext *ctx)
Definition: dnn_filter_common.c:181
AVDetectionBBox
Definition: detection_bbox.h:26
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
dnn_detect_post_proc_tf
static int dnn_detect_post_proc_tf(AVFrame *frame, DNNData *output, AVFilterContext *filter_ctx)
Definition: vf_dnn_detect.c:142
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:47
detection_bbox.h
ff_dnn_get_async_result
DNNAsyncStatusType ff_dnn_get_async_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame)
Definition: dnn_filter_common.c:171
AV_FRAME_DATA_DETECTION_BBOXES
@ AV_FRAME_DATA_DETECTION_BBOXES
Bounding boxes for object detection and classification, as described by AVDetectionBBoxHeader.
Definition: frame.h:189