26#define MAX_SUPPORTED_OUTPUTS_NB 4
30 char *
val, **parsed_vals =
NULL;
32 if (!expr || !val_sep || !separated_nb) {
47 parsed_vals[val_num] =
val;
55 parsed_vals[val_num] =
NULL;
56 *separated_nb = val_num;
61 for (
int i = 0;
i < val_num;
i++)
88 if (!
ctx->model_filename) {
94 if (
ctx->model_inputname)
96 "inputname will be ignored.\n");
97 if (
ctx->model_outputnames)
99 "all outputname(s) will be ignored.\n");
101 }
else if (backend ==
DNN_TF) {
102 if (!
ctx->model_inputname) {
107 if (!
ctx->model_outputnames) {
113 if (
ctx->model_outputnames_string) {
115 if (!
ctx->model_outputnames) {
119 if (
ctx->nb_outputs != 1) {
121 "ONNX backend supports a single output name only\n");
128 if (!
ctx->dnn_module) {
132 if (!
ctx->dnn_module->load_model) {
137 if (
ctx->backend_options) {
141 "backend_configs is deprecated, please set backend options directly\n");
143 if (*(
const AVClass **)child == &
ctx->dnn_module->clazz) {
148 ctx->backend_options);
166 ctx->model->frame_pre_proc = pre_proc;
167 ctx->model->frame_post_proc = post_proc;
173 ctx->model->detect_post_proc = post_proc;
179 ctx->model->classify_post_proc = post_proc;
185 return ctx->model->get_input(
ctx->model, input,
ctx->model_inputname);
190 char * output_name =
ctx->model_outputnames &&
ctx->backend_type !=
DNN_TH ?
191 ctx->model_outputnames[0] :
NULL;
192 return ctx->model->get_output(
ctx->model,
ctx->model_inputname, input_width, input_height,
193 (
const char *)output_name, output_width, output_height);
199 .input_name =
ctx->model_inputname,
200 .output_names = (
const char **)
ctx->model_outputnames,
201 .nb_output =
ctx->nb_outputs,
202 .in_frame = in_frame,
203 .out_frame = out_frame,
205 return (
ctx->dnn_module->execute_model)(
ctx->model, &exec_params);
212 .input_name =
ctx->model_inputname,
213 .output_names = (
const char **)
ctx->model_outputnames,
214 .nb_output =
ctx->nb_outputs,
215 .in_frame = in_frame,
216 .out_frame = out_frame,
220 return (
ctx->dnn_module->execute_model)(
ctx->model, &class_params.
base);
225 return (
ctx->dnn_module->get_result)(
ctx->model, in_frame, out_frame);
230 return (
ctx->dnn_module->flush)(
ctx->model);
235 if (
ctx->dnn_module) {
236 (
ctx->dnn_module->free_model)(&
ctx->model);
238 if (
ctx->model_outputnames) {
239 for (
int i = 0;
i <
ctx->nb_outputs;
i++)
258 if (
ctx->batch_size > 1) {
275 "Zero-copy CUDA path currently only supports RGB24/BGR24 or RGB0/BGR0 variants.\n");
static double val(void *priv, double ch)
#define i(width, name, range_min, range_max)
static char ** separate_output_names(const char *expr, const char *val_sep, int *separated_nb)
void * ff_dnn_filter_child_next(void *obj, void *prev)
int ff_dnn_set_detect_post_proc(DnnContext *ctx, DetectPostProc post_proc)
void ff_dnn_uninit(DnnContext *ctx)
DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame)
int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
int ff_dnn_set_classify_post_proc(DnnContext *ctx, ClassifyPostProc post_proc)
int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
int ff_dnn_get_input(DnnContext *ctx, DNNData *input)
#define MAX_SUPPORTED_OUTPUTS_NB
int ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height)
int ff_dnn_flush(DnnContext *ctx)
int ff_dnn_set_frame_proc(DnnContext *ctx, FramePrePostProc pre_proc, FramePrePostProc post_proc)
int ff_dnn_filter_init_child_class(AVFilterContext *filter)
int ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target)
common functions for the dnn based filters
void * ff_dnn_child_next(DnnContext *obj, void *prev)
const DNNModule * ff_get_dnn_module(DNNBackendType backend_type, void *log_ctx)
void ff_dnn_init_child_class(DnnContext *ctx)
int(* FramePrePostProc)(AVFrame *frame, DNNData *model, AVFilterContext *filter_ctx)
int(* DetectPostProc)(AVFrame *frame, DNNData *output, uint32_t nb, AVFilterContext *filter_ctx)
int(* ClassifyPostProc)(AVFrame *frame, DNNData *output, uint32_t bbox_index, AVFilterContext *filter_ctx)
AVBufferRef * avfilter_link_get_hw_frames_ctx(AVFilterLink *link)
Get the hardware frames context of a filter link.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
A reference to a data buffer.
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
A link between two filters.
AVFilterContext * dst
dest filter
int format
agreed upon media format
This structure describes decoded (raw) audio or video data.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static AVFormatContext * ctx
static FilteringContext * filter_ctx