FFmpeg
vf_dnn_processing.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Guo Yejun
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * implementing a generic image processing filter using deep learning networks.
24  */
25 
26 #include "libavutil/opt.h"
27 #include "libavutil/pixdesc.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/imgutils.h"
30 #include "filters.h"
31 #include "dnn_filter_common.h"
32 #include "video.h"
33 #include "libswscale/swscale.h"
34 #include "libavutil/time.h"
35 
36 typedef struct DnnProcessingContext {
37  const AVClass *class;
42 
43 #define OFFSET(x) offsetof(DnnProcessingContext, dnnctx.x)
44 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
45 static const AVOption dnn_processing_options[] = {
46  { "dnn_backend", "DNN backend", OFFSET(backend_type), AV_OPT_TYPE_INT, { .i64 = DNN_TF }, INT_MIN, INT_MAX, FLAGS, .unit = "backend" },
47 #if (CONFIG_LIBTENSORFLOW == 1)
48  { "tensorflow", "tensorflow backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = DNN_TF }, 0, 0, FLAGS, .unit = "backend" },
49 #endif
50 #if (CONFIG_LIBOPENVINO == 1)
51  { "openvino", "openvino backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = DNN_OV }, 0, 0, FLAGS, .unit = "backend" },
52 #endif
53 #if (CONFIG_LIBTORCH == 1)
54  { "torch", "torch backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = DNN_TH }, 0, 0, FLAGS, "backend" },
55 #endif
56 #if (CONFIG_LIBONNXRUNTIME == 1)
57  { "onnx", "onnx backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = DNN_ONNX }, 0, 0, FLAGS, "backend" },
58 #endif
59  { NULL }
60 };
61 
63 
65 {
67  return ff_dnn_init(&ctx->dnnctx, DFT_PROCESS_FRAME, context);
68 }
69 
70 static const enum AVPixelFormat pix_fmts[] = {
77 };
78 
79 #define LOG_FORMAT_CHANNEL_MISMATCH() \
80  av_log(ctx, AV_LOG_ERROR, \
81  "the frame's format %s does not match " \
82  "the model input channel %d\n", \
83  av_get_pix_fmt_name(fmt), \
84  model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)]);
85 
86 static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLink *inlink)
87 {
88  AVFilterContext *ctx = inlink->dst;
89  enum AVPixelFormat fmt = inlink->format;
90  int width_idx, height_idx;
91 
92  width_idx = dnn_get_width_idx_by_layout(model_input->layout);
93  height_idx = dnn_get_height_idx_by_layout(model_input->layout);
94  // the design is to add explicit scale filter before this filter
95  if (model_input->dims[height_idx] != -1 &&
96  model_input->dims[height_idx] != inlink->h) {
97  av_log(ctx, AV_LOG_ERROR, "the model requires frame height %d but got %d\n",
98  model_input->dims[height_idx],
99  inlink->h);
100  return AVERROR(EIO);
101  }
102  if (model_input->dims[width_idx] != -1 &&
103  model_input->dims[width_idx] != inlink->w) {
104  av_log(ctx, AV_LOG_ERROR, "the model requires frame width %d but got %d\n",
105  model_input->dims[width_idx],
106  inlink->w);
107  return AVERROR(EIO);
108  }
109  if (model_input->dt != DNN_FLOAT) {
110  avpriv_report_missing_feature(ctx, "data type rather than DNN_FLOAT");
111  return AVERROR(EIO);
112  }
113 
114  switch (fmt) {
115  case AV_PIX_FMT_RGB24:
116  case AV_PIX_FMT_BGR24:
117  if (model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)] != 3) {
119  return AVERROR(EIO);
120  }
121  return 0;
122  case AV_PIX_FMT_GRAY8:
123  case AV_PIX_FMT_GRAYF32:
124  case AV_PIX_FMT_YUV420P:
125  case AV_PIX_FMT_YUV422P:
126  case AV_PIX_FMT_YUV444P:
127  case AV_PIX_FMT_YUV410P:
128  case AV_PIX_FMT_YUV411P:
129  case AV_PIX_FMT_NV12:
130  if (model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)] != 1) {
132  return AVERROR(EIO);
133  }
134  return 0;
135  default:
137  return AVERROR(EIO);
138  }
139 
140  return 0;
141 }
142 
144 {
147  int result;
148  DNNData model_input;
149  int check;
150 
151  result = ff_dnn_get_input(&ctx->dnnctx, &model_input);
152  if (result != 0) {
153  av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n");
154  return result;
155  }
156 
157  check = check_modelinput_inlink(&model_input, inlink);
158  if (check != 0) {
159  return check;
160  }
161 
162  return 0;
163 }
164 
166 {
168  av_assert0(desc);
169  return !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components == 3;
170 }
171 
172 static int prepare_uv_scale(AVFilterLink *outlink)
173 {
174  AVFilterContext *context = outlink->src;
176  AVFilterLink *inlink = context->inputs[0];
177  enum AVPixelFormat fmt = inlink->format;
178 
179  if (isPlanarYUV(fmt)) {
180  if (inlink->w != outlink->w || inlink->h != outlink->h) {
181  if (fmt == AV_PIX_FMT_NV12) {
182  ctx->sws_uv_scale = sws_getContext(inlink->w >> 1, inlink->h >> 1, AV_PIX_FMT_YA8,
183  outlink->w >> 1, outlink->h >> 1, AV_PIX_FMT_YA8,
185  ctx->sws_uv_height = inlink->h >> 1;
186  } else {
188  int sws_src_h = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
189  int sws_src_w = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
190  int sws_dst_h = AV_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h);
191  int sws_dst_w = AV_CEIL_RSHIFT(outlink->w, desc->log2_chroma_w);
192  ctx->sws_uv_scale = sws_getContext(sws_src_w, sws_src_h, AV_PIX_FMT_GRAY8,
193  sws_dst_w, sws_dst_h, AV_PIX_FMT_GRAY8,
195  ctx->sws_uv_height = sws_src_h;
196  }
197  }
198  }
199 
200  return 0;
201 }
202 
203 static int config_output(AVFilterLink *outlink)
204 {
205  AVFilterContext *context = outlink->src;
207  int result;
208  AVFilterLink *inlink = context->inputs[0];
209 
210  // have a try run in case that the dnn model resize the frame
211  result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &outlink->w, &outlink->h);
212  if (result != 0) {
213  av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n");
214  return result;
215  }
216 
217  prepare_uv_scale(outlink);
218 
219  return 0;
220 }
221 
223 {
224  const AVPixFmtDescriptor *desc;
225  int uv_height;
226 
227  if (!ctx->sws_uv_scale) {
228  av_assert0(in->height == out->height && in->width == out->width);
230  uv_height = AV_CEIL_RSHIFT(in->height, desc->log2_chroma_h);
231  for (int i = 1; i < 3; ++i) {
232  int bytewidth = av_image_get_linesize(in->format, in->width, i);
233  if (bytewidth < 0) {
234  return AVERROR(EINVAL);
235  }
236  av_image_copy_plane(out->data[i], out->linesize[i],
237  in->data[i], in->linesize[i],
238  bytewidth, uv_height);
239  }
240  } else if (in->format == AV_PIX_FMT_NV12) {
241  sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 1), in->linesize + 1,
242  0, ctx->sws_uv_height, out->data + 1, out->linesize + 1);
243  } else {
244  sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 1), in->linesize + 1,
245  0, ctx->sws_uv_height, out->data + 1, out->linesize + 1);
246  sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 2), in->linesize + 2,
247  0, ctx->sws_uv_height, out->data + 2, out->linesize + 2);
248  }
249 
250  return 0;
251 }
252 
253 static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
254 {
255  DnnProcessingContext *ctx = outlink->src->priv;
256  int ret;
257  DNNAsyncStatusType async_state;
258 
259  ret = ff_dnn_flush(&ctx->dnnctx);
260  if (ret != 0) {
261  return -1;
262  }
263 
264  do {
265  AVFrame *in_frame = NULL;
266  AVFrame *out_frame = NULL;
267  async_state = ff_dnn_get_result(&ctx->dnnctx, &in_frame, &out_frame);
268  if (out_frame) {
269  if (isPlanarYUV(in_frame->format))
270  copy_uv_planes(ctx, out_frame, in_frame);
271  av_frame_free(&in_frame);
272  ret = ff_filter_frame(outlink, out_frame);
273  if (ret < 0)
274  return ret;
275  if (out_pts)
276  *out_pts = out_frame->pts + pts;
277  }
278  av_usleep(5000);
279  } while (async_state >= DAST_NOT_READY);
280 
281  return 0;
282 }
283 
285 {
286  AVFilterLink *inlink = filter_ctx->inputs[0];
287  AVFilterLink *outlink = filter_ctx->outputs[0];
289  AVFrame *in = NULL, *out = NULL;
290  int64_t pts;
291  int ret, status;
292  int got_frame = 0;
293  int async_state;
294 
296 
297  do {
298  // drain all input frames
300  if (ret < 0)
301  return ret;
302  if (ret > 0) {
303  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
304  if (!out) {
305  av_frame_free(&in);
306  return AVERROR(ENOMEM);
307  }
309  if (ff_dnn_execute_model(&ctx->dnnctx, in, out) != 0) {
310  return AVERROR(EIO);
311  }
312  }
313  } while (ret > 0);
314 
315  // drain all processed frames
316  do {
317  AVFrame *in_frame = NULL;
318  AVFrame *out_frame = NULL;
319  async_state = ff_dnn_get_result(&ctx->dnnctx, &in_frame, &out_frame);
320  if (out_frame) {
321  if (isPlanarYUV(in_frame->format))
322  copy_uv_planes(ctx, out_frame, in_frame);
323  av_frame_free(&in_frame);
324  ret = ff_filter_frame(outlink, out_frame);
325  if (ret < 0)
326  return ret;
327  got_frame = 1;
328  }
329  } while (async_state == DAST_SUCCESS);
330 
331  // if frame got, schedule to next filter
332  if (got_frame)
333  return 0;
334 
336  if (status == AVERROR_EOF) {
337  int64_t out_pts = pts;
338  ret = flush_frame(outlink, pts, &out_pts);
339  ff_outlink_set_status(outlink, status, out_pts);
340  return ret;
341  }
342  }
343 
345 
346  return 0;
347 }
348 
350 {
352 
353  sws_freeContext(context->sws_uv_scale);
354  ff_dnn_uninit(&context->dnnctx);
355 }
356 
358  {
359  .name = "default",
360  .type = AVMEDIA_TYPE_VIDEO,
361  .config_props = config_input,
362  },
363 };
364 
366  {
367  .name = "default",
368  .type = AVMEDIA_TYPE_VIDEO,
369  .config_props = config_output,
370  },
371 };
372 
374  .p.name = "dnn_processing",
375  .p.description = NULL_IF_CONFIG_SMALL("Apply DNN processing filter to the input."),
376  .p.priv_class = &dnn_processing_class,
377  .priv_size = sizeof(DnnProcessingContext),
379  .init = init,
380  .uninit = uninit,
384  .activate = activate,
385 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:89
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_dnn_processing.c:349
dnn_processing_options
static const AVOption dnn_processing_options[]
Definition: vf_dnn_processing.c:45
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:140
out
static FILE * out
Definition: movenc.c:55
OFFSET
#define OFFSET(x)
Definition: vf_dnn_processing.c:43
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1068
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
av_cold
#define av_cold
Definition: attributes.h:119
int64_t
long long int64_t
Definition: coverity.c:34
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
sws_freeContext
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition: utils.c:2297
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:568
DnnProcessingContext
Definition: vf_dnn_processing.c:36
AVFrame::width
int width
Definition: frame.h:538
AVOption
AVOption.
Definition: opt.h:428
filters.h
ff_vf_dnn_processing
const FFFilter ff_vf_dnn_processing
Definition: vf_dnn_processing.c:373
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
preinit
static av_cold int preinit(AVFilterContext *ctx)
Definition: af_aresample.c:48
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_dnn_processing.c:143
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:219
dnn_filter_common.h
video.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:487
av_image_copy_plane
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:374
av_always_inline
#define av_always_inline
Definition: attributes.h:76
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:1516
dnn_get_width_idx_by_layout
static int dnn_get_width_idx_by_layout(DNNLayout layout)
Definition: dnn_interface.h:209
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:288
DnnContext
Definition: dnn_interface.h:151
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:244
filter_ctx
static FilteringContext * filter_ctx
Definition: transcode.c:52
ff_dnn_filter_init_child_class
int ff_dnn_filter_init_child_class(AVFilterContext *filter)
Definition: dnn_filter_common.c:70
pts
static int64_t pts
Definition: transcode_aac.c:649
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:40
flush_frame
static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
Definition: vf_dnn_processing.c:253
avassert.h
DNN_TF
@ DNN_TF
Definition: dnn_interface.h:36
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FFFilter
Definition: filters.h:267
check
#define check(x, y, S, v)
Definition: motion_est_template.c:405
copy_uv_planes
static int copy_uv_planes(DnnProcessingContext *ctx, AVFrame *out, const AVFrame *in)
Definition: vf_dnn_processing.c:222
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:265
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
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:629
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_dnn_processing.c:70
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
DNNData
Definition: dnn_interface.h:70
ff_dnn_get_result
DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame)
Definition: dnn_filter_common.c:221
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
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:73
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:582
check_modelinput_inlink
static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLink *inlink)
Definition: vf_dnn_processing.c:86
ff_dnn_get_input
int ff_dnn_get_input(DnnContext *ctx, DNNData *input)
Definition: dnn_filter_common.c:181
DNN_OV
@ DNN_OV
Definition: dnn_interface.h:37
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:76
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:599
init
static av_cold int init(AVFilterContext *context)
Definition: vf_dnn_processing.c:64
SWS_BICUBIC
@ SWS_BICUBIC
2-tap cubic B-spline
Definition: swscale.h:201
time.h
dnn_processing_inputs
static const AVFilterPad dnn_processing_inputs[]
Definition: vf_dnn_processing.c:357
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
ff_dnn_flush
int ff_dnn_flush(DnnContext *ctx)
Definition: dnn_filter_common.c:226
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:1463
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
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:88
DAST_SUCCESS
@ DAST_SUCCESS
Definition: dnn_interface.h:54
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
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.
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:553
DNNData::dt
DNNDataType dt
Definition: dnn_interface.h:74
DNN_ONNX
@ DNN_ONNX
Definition: dnn_interface.h:39
DNNData::layout
DNNLayout layout
Definition: dnn_interface.h:76
DNN_FLOAT
@ DNN_FLOAT
Definition: dnn_interface.h:42
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
av_image_get_linesize
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
Definition: imgutils.c:76
activate
static int activate(AVFilterContext *filter_ctx)
Definition: vf_dnn_processing.c:284
DnnProcessingContext::sws_uv_height
int sws_uv_height
Definition: vf_dnn_processing.c:40
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:46
DnnProcessingContext::dnnctx
DnnContext dnnctx
Definition: vf_dnn_processing.c:38
ret
ret
Definition: filter_design.txt:187
AVFILTER_DNN_DEFINE_CLASS
AVFILTER_DNN_DEFINE_CLASS(dnn_processing, DNN_TF|DNN_OV|DNN_TH|DNN_ONNX)
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:96
sws_getContext
SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:1966
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:264
AVFrame::height
int height
Definition: frame.h:538
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
ff_dnn_get_output
int ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height)
Definition: dnn_filter_common.c:186
sws_scale
int attribute_align_arg sws_scale(SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
Definition: swscale.c:1586
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:258
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:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:273
isPlanarYUV
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
Definition: vf_dnn_processing.c:165
LOG_FORMAT_CHANNEL_MISMATCH
#define LOG_FORMAT_CHANNEL_MISMATCH()
Definition: vf_dnn_processing.c:79
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:639
DNNData::dims
int dims[4]
Definition: dnn_interface.h:72
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:271
DNN_TH
@ DNN_TH
Definition: dnn_interface.h:38
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:77
dnn_get_height_idx_by_layout
static int dnn_get_height_idx_by_layout(DNNLayout layout)
Definition: dnn_interface.h:214
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
dnn_get_channel_idx_by_layout
static int dnn_get_channel_idx_by_layout(DNNLayout layout)
Definition: dnn_interface.h:219
ff_dnn_init
int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
Definition: dnn_filter_common.c:82
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:80
imgutils.h
prepare_uv_scale
static int prepare_uv_scale(AVFilterLink *outlink)
Definition: vf_dnn_processing.c:172
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:511
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:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FLAGS
#define FLAGS
Definition: vf_dnn_processing.c:44
ff_dnn_uninit
void ff_dnn_uninit(DnnContext *ctx)
Definition: dnn_filter_common.c:231
ff_dnn_execute_model
int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
Definition: dnn_filter_common.c:194
DAST_NOT_READY
@ DAST_NOT_READY
Definition: dnn_interface.h:53
SwsContext
Main external API structure.
Definition: swscale.h:229
DNNAsyncStatusType
DNNAsyncStatusType
Definition: dnn_interface.h:50
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:298
DFT_PROCESS_FRAME
@ DFT_PROCESS_FRAME
Definition: dnn_interface.h:59
DnnProcessingContext::sws_uv_scale
struct SwsContext * sws_uv_scale
Definition: vf_dnn_processing.c:39
swscale.h
dnn_processing_outputs
static const AVFilterPad dnn_processing_outputs[]
Definition: vf_dnn_processing.c:365
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3376
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_dnn_processing.c:203