FFmpeg
Loading...
Searching...
No Matches
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 "config.h"
27#include "libavutil/opt.h"
28#include "libavutil/pixdesc.h"
29#include "libavutil/avassert.h"
30#include "libavutil/imgutils.h"
31#include "libavutil/hwcontext.h"
33#include "filters.h"
34#include "formats.h"
35#include "dnn_filter_common.h"
36#include "video.h"
37#include "libswscale/swscale.h"
38#include "libavutil/time.h"
39
40#if CONFIG_DNN_ONNX_D3D12
42#endif
43
51
52#define OFFSET(x) offsetof(DnnProcessingContext, dnnctx.x)
53#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
55 { "dnn_backend", "DNN backend", OFFSET(backend_type), AV_OPT_TYPE_INT, { .i64 = DNN_TF }, INT_MIN, INT_MAX, FLAGS, .unit = "backend" },
56#if (CONFIG_LIBTENSORFLOW == 1)
57 { "tensorflow", "tensorflow backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = DNN_TF }, 0, 0, FLAGS, .unit = "backend" },
58#endif
59#if (CONFIG_LIBOPENVINO == 1)
60 { "openvino", "openvino backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = DNN_OV }, 0, 0, FLAGS, .unit = "backend" },
61#endif
62#if (CONFIG_LIBTORCH == 1)
63 { "torch", "torch backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = DNN_TH }, 0, 0, FLAGS, "backend" },
64#endif
65#if (CONFIG_LIBONNXRUNTIME == 1)
66 { "onnx", "onnx backend flag", 0, AV_OPT_TYPE_CONST, { .i64 = DNN_ONNX }, 0, 0, FLAGS, "backend" },
67#endif
68 { NULL }
69};
70
72
73static av_cold int init(AVFilterContext *context)
74{
75 /*
76 * Model loading is deferred to config_input(): the ONNX Runtime
77 * backend's D3D12/DirectML path must bind its execution provider to
78 * the input's D3D12 device before the ORT session is created, and
79 * hw_frames_ctx is not available yet here.
80 */
81 return 0;
82}
83
98
99#define LOG_FORMAT_CHANNEL_MISMATCH() \
100 av_log(ctx, AV_LOG_ERROR, \
101 "the frame's format %s does not match " \
102 "the model input channel %d\n", \
103 av_get_pix_fmt_name(fmt), \
104 model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)]);
105
106static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLink *inlink,
107 DNNBackendType backend_type)
108{
109 AVFilterContext *ctx = inlink->dst;
110 enum AVPixelFormat fmt = inlink->format;
111 int width_idx, height_idx;
112
113 width_idx = dnn_get_width_idx_by_layout(model_input->layout);
114 height_idx = dnn_get_height_idx_by_layout(model_input->layout);
115 // the design is to add explicit scale filter before this filter
116 if (model_input->dims[height_idx] != -1 &&
117 model_input->dims[height_idx] != inlink->h) {
118 av_log(ctx, AV_LOG_ERROR, "the model requires frame height %d but got %d\n",
119 model_input->dims[height_idx],
120 inlink->h);
121 return AVERROR(EIO);
122 }
123 if (model_input->dims[width_idx] != -1 &&
124 model_input->dims[width_idx] != inlink->w) {
125 av_log(ctx, AV_LOG_ERROR, "the model requires frame width %d but got %d\n",
126 model_input->dims[width_idx],
127 inlink->w);
128 return AVERROR(EIO);
129 }
130 if (model_input->dt != DNN_FLOAT && model_input->dt != DNN_UINT8) {
131 avpriv_report_missing_feature(ctx, "data type other than DNN_FLOAT or DNN_UINT8");
132 return AVERROR(EIO);
133 }
134
135 if (model_input->dt == DNN_UINT8 && backend_type == DNN_TF) {
136 avpriv_report_missing_feature(ctx, "DNN_UINT8 input for the TensorFlow backend");
137 return AVERROR(EIO);
138 }
139
140 switch (fmt) {
141 case AV_PIX_FMT_RGB24:
142 case AV_PIX_FMT_BGR24:
143 if (model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)] != 3) {
145 return AVERROR(EIO);
146 }
147 return 0;
148 case AV_PIX_FMT_GRAY8:
155 case AV_PIX_FMT_NV12:
156 if (model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)] != 1) {
158 return AVERROR(EIO);
159 }
160 return 0;
161#if CONFIG_CUDA
162 case AV_PIX_FMT_CUDA:
163 {
164 DnnProcessingContext *dnn_ctx = ctx->priv;
165 return ff_dnn_zero_copy_supported_cuda(&dnn_ctx->dnnctx, inlink);
166 }
167#endif
168#if CONFIG_DNN_ONNX_D3D12
169 case AV_PIX_FMT_D3D12:
170 {
171 DnnProcessingContext *dnn_ctx = ctx->priv;
172 if (model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)] != 1) {
174 return AVERROR(EIO);
175 }
176 return ff_dnn_zero_copy_supported_d3d12(&dnn_ctx->dnnctx, inlink);
177 }
178#endif
179 default:
181 return AVERROR(EIO);
182 }
183
184 return 0;
185}
186
187static int config_input(AVFilterLink *inlink)
188{
189 AVFilterContext *context = inlink->dst;
190 DnnProcessingContext *ctx = context->priv;
191 int result;
192 DNNData model_input = { 0 };
193 int check;
194
195#if CONFIG_DNN_ONNX_D3D12
196 if (inlink->format == AV_PIX_FMT_D3D12) {
197 FilterLink *inl = ff_filter_link(inlink);
198 AVHWFramesContext *frames_ctx;
199
200 if (!inl->hw_frames_ctx) {
201 av_log(context, AV_LOG_ERROR,
202 "No hw_frames_ctx on the input link; D3D12 input requires "
203 "D3D12VA hardware frames (e.g. via hwupload or a "
204 "D3D12VA-accelerated decoder)\n");
205 return AVERROR(EINVAL);
206 }
207
208 frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
209 if (frames_ctx->sw_format != AV_PIX_FMT_NV12) {
210 av_log(context, AV_LOG_ERROR,
211 "D3D12 zero-copy currently only supports NV12 hardware "
212 "frames, got %s\n", av_get_pix_fmt_name(frames_ctx->sw_format));
213 return AVERROR(EINVAL);
214 }
215
216 result = ff_dnn_set_hw_frames_ctx(&ctx->dnnctx, inl->hw_frames_ctx);
217 if (result < 0)
218 return result;
219 }
220#endif
221
222 /*
223 * Deferred from init(): the DirectML EP must bind to
224 * ctx->dnnctx.hw_frames_ctx (set above for D3D12 input) before
225 * ff_dnn_init() creates the ORT session, but hw_frames_ctx isn't
226 * available until config_input() runs..
227 */
228 if (!ctx->dnnctx.model) {
229 result = ff_dnn_init(&ctx->dnnctx, DFT_PROCESS_FRAME, context);
230 if (result < 0)
231 return result;
232 }
233
234 result = ff_dnn_get_input(&ctx->dnnctx, &model_input);
235 if (result != 0) {
236 av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n");
237 return result;
238 }
239
240 check = check_modelinput_inlink(&model_input, inlink, ctx->dnnctx.backend_type);
241 if (check != 0) {
242 return check;
243 }
244
245 return 0;
246}
247
249{
252 return !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components == 3;
253}
254
255static int prepare_uv_scale(AVFilterLink *outlink)
256{
257 AVFilterContext *context = outlink->src;
258 DnnProcessingContext *ctx = context->priv;
259 AVFilterLink *inlink = context->inputs[0];
260 enum AVPixelFormat fmt = inlink->format;
261
262 if (isPlanarYUV(fmt)) {
263 if (inlink->w != outlink->w || inlink->h != outlink->h) {
264 if (fmt == AV_PIX_FMT_NV12) {
265 ctx->sws_uv_scale = sws_getContext(inlink->w >> 1, inlink->h >> 1, AV_PIX_FMT_YA8,
266 outlink->w >> 1, outlink->h >> 1, AV_PIX_FMT_YA8,
268 ctx->sws_uv_height = inlink->h >> 1;
269 } else {
271 int sws_src_h = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
272 int sws_src_w = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
273 int sws_dst_h = AV_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h);
274 int sws_dst_w = AV_CEIL_RSHIFT(outlink->w, desc->log2_chroma_w);
275 ctx->sws_uv_scale = sws_getContext(sws_src_w, sws_src_h, AV_PIX_FMT_GRAY8,
276 sws_dst_w, sws_dst_h, AV_PIX_FMT_GRAY8,
278 ctx->sws_uv_height = sws_src_h;
279 }
280 }
281 }
282
283 return 0;
284}
285
286#if CONFIG_DNN_ONNX_D3D12
287static int config_output_d3d12(AVFilterLink *outlink)
288{
289 AVFilterContext *context = outlink->src;
290 DnnProcessingContext *ctx = context->priv;
291 AVFilterLink *inlink = context->inputs[0];
292 FilterLink *inl = ff_filter_link(inlink);
293 FilterLink *outl = ff_filter_link(outlink);
294 AVHWFramesContext *in_frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
295 AVHWFramesContext *frames_ctx;
296 AVD3D12VAFramesContext *frames_hwctx;
297 int ret;
298
299 if (!ctx->dnnctx.zero_copy_negotiated) {
300 av_log(context, AV_LOG_ERROR,
301 "Failed to negotiate the D3D12/DirectML zero-copy path for "
302 "this model; dnn_processing cannot fall back to host-memory "
303 "processing on hardware frames. Check that device=dml, that "
304 "the input is a D3D12VA hwframe, that FFmpeg was built "
305 "with the DirectML-enabled ONNX Runtime (see dnn_onnx_d3d12 "
306 "in configure), and that DirectML.dll and d3dcompiler_47.dll "
307 "are available in the application directory or System32.\n");
308 return AVERROR(ENOSYS);
309 }
310
311 if ((inlink->w | inlink->h | outlink->w | outlink->h) & 1) {
312 av_log(context, AV_LOG_ERROR,
313 "D3D12 zero-copy requires even NV12 frame dimensions, got %dx%d -> %dx%d\n",
314 inlink->w, inlink->h, outlink->w, outlink->h);
315 return AVERROR(EINVAL);
316 }
317
318 av_buffer_unref(&ctx->hw_frames_ctx_out);
319
320 ctx->hw_frames_ctx_out = av_hwframe_ctx_alloc(in_frames_ctx->device_ref);
321 if (!ctx->hw_frames_ctx_out)
322 return AVERROR(ENOMEM);
323
324 frames_ctx = (AVHWFramesContext *)ctx->hw_frames_ctx_out->data;
325 frames_ctx->format = AV_PIX_FMT_D3D12;
326 frames_ctx->sw_format = AV_PIX_FMT_NV12;
327 frames_ctx->width = outlink->w;
328 frames_ctx->height = outlink->h;
329 frames_ctx->initial_pool_size = 10;
330 if (context->extra_hw_frames > 0)
331 frames_ctx->initial_pool_size += context->extra_hw_frames;
332
333 frames_hwctx = frames_ctx->hwctx;
334 frames_hwctx->format = DXGI_FORMAT_NV12;
335
336 ret = av_hwframe_ctx_init(ctx->hw_frames_ctx_out);
337 if (ret < 0) {
338 av_buffer_unref(&ctx->hw_frames_ctx_out);
339 return ret;
340 }
341
342 av_buffer_unref(&outl->hw_frames_ctx);
343 outl->hw_frames_ctx = av_buffer_ref(ctx->hw_frames_ctx_out);
344 if (!outl->hw_frames_ctx)
345 return AVERROR(ENOMEM);
346
347 return 0;
348}
349#endif
350
351static int config_output(AVFilterLink *outlink)
352{
353 AVFilterContext *context = outlink->src;
354 DnnProcessingContext *ctx = context->priv;
355 int result;
356 AVFilterLink *inlink = context->inputs[0];
357 FilterLink *inl = ff_filter_link(inlink);
358 FilterLink *outl = ff_filter_link(outlink);
359
360 // have a try run in case that the dnn model resize the frame
361 result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &outlink->w, &outlink->h);
362 if (result != 0) {
363 av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n");
364 return result;
365 }
366
367 prepare_uv_scale(outlink);
368
369 if (inl->hw_frames_ctx) {
370#if CONFIG_DNN_ONNX_D3D12
371 /* D3D12 needs its own pool sized to the model's output. */
372 if (inlink->format == AV_PIX_FMT_D3D12)
373 return config_output_d3d12(outlink);
374#endif
376 if (!outl->hw_frames_ctx)
377 return AVERROR(ENOMEM);
378 }
379
380 return 0;
381}
382
384{
386 int uv_height;
387
388 if (!ctx->sws_uv_scale) {
389 av_assert0(in->height == out->height && in->width == out->width);
391 uv_height = AV_CEIL_RSHIFT(in->height, desc->log2_chroma_h);
392 for (int i = 1; i < 3; ++i) {
393 int bytewidth = av_image_get_linesize(in->format, in->width, i);
394 if (bytewidth < 0) {
395 return AVERROR(EINVAL);
396 }
397 av_image_copy_plane(out->data[i], out->linesize[i],
398 in->data[i], in->linesize[i],
399 bytewidth, uv_height);
400 }
401 } else if (in->format == AV_PIX_FMT_NV12) {
402 sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 1), in->linesize + 1,
403 0, ctx->sws_uv_height, out->data + 1, out->linesize + 1);
404 } else {
405 sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 1), in->linesize + 1,
406 0, ctx->sws_uv_height, out->data + 1, out->linesize + 1);
407 sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 2), in->linesize + 2,
408 0, ctx->sws_uv_height, out->data + 2, out->linesize + 2);
409 }
410
411 return 0;
412}
413
414static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
415{
416 DnnProcessingContext *ctx = outlink->src->priv;
417 int ret;
418 DNNAsyncStatusType async_state;
419
420 ret = ff_dnn_flush(&ctx->dnnctx);
421 if (ret != 0) {
422 return -1;
423 }
424
425 do {
426 AVFrame *in_frame = NULL;
427 AVFrame *out_frame = NULL;
428 async_state = ff_dnn_get_result(&ctx->dnnctx, &in_frame, &out_frame);
429 if (out_frame) {
430 if (isPlanarYUV(in_frame->format))
431 copy_uv_planes(ctx, out_frame, in_frame);
432 av_frame_free(&in_frame);
433 ret = ff_filter_frame(outlink, out_frame);
434 if (ret < 0)
435 return ret;
436 if (out_pts)
437 *out_pts = out_frame->pts + pts;
438 }
439 av_usleep(5000);
440 } while (async_state >= DAST_NOT_READY);
441
442 return 0;
443}
444
446{
447 AVFilterLink *inlink = filter_ctx->inputs[0];
448 AVFilterLink *outlink = filter_ctx->outputs[0];
450 AVFrame *in = NULL, *out = NULL;
451 int64_t pts;
452 int ret, status;
453 int got_frame = 0;
454 int async_state;
455
456 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
457
458 do {
459 // drain all input frames
460 ret = ff_inlink_consume_frame(inlink, &in);
461 if (ret < 0)
462 return ret;
463 if (ret > 0) {
464 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
465 if (!out) {
466 av_frame_free(&in);
467 return AVERROR(ENOMEM);
468 }
470 if (out->width != in->width || out->height != in->height) {
471 out->crop_left = av_rescale(in->crop_left, out->width, in->width);
472 out->crop_right = av_rescale(in->crop_right, out->width, in->width);
473 out->crop_top = av_rescale(in->crop_top, out->height, in->height);
474 out->crop_bottom = av_rescale(in->crop_bottom, out->height, in->height);
475 }
476 if (ff_dnn_execute_model(&ctx->dnnctx, in, out) != 0) {
477 return AVERROR(EIO);
478 }
479 }
480 } while (ret > 0);
481
482 // drain all processed frames
483 do {
484 AVFrame *in_frame = NULL;
485 AVFrame *out_frame = NULL;
486 async_state = ff_dnn_get_result(&ctx->dnnctx, &in_frame, &out_frame);
487 if (out_frame) {
488 if (isPlanarYUV(in_frame->format))
489 copy_uv_planes(ctx, out_frame, in_frame);
490 av_frame_free(&in_frame);
491 ret = ff_filter_frame(outlink, out_frame);
492 if (ret < 0)
493 return ret;
494 got_frame = 1;
495 }
496 } while (async_state == DAST_SUCCESS);
497
498 // if frame got, schedule to next filter
499 if (got_frame)
500 return 0;
501
502 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
503 if (status == AVERROR_EOF) {
504 int64_t out_pts = pts;
505 ret = flush_frame(outlink, pts, &out_pts);
506 ff_outlink_set_status(outlink, status, out_pts);
507 return ret;
508 }
509 }
510
511 FF_FILTER_FORWARD_WANTED(outlink, inlink);
512
513 return 0;
514}
515
517{
518 DnnProcessingContext *context = ctx->priv;
519
521 ff_dnn_uninit(&context->dnnctx);
523}
524
526 {
527 .name = "default",
528 .type = AVMEDIA_TYPE_VIDEO,
529 .config_props = config_input,
530 },
531};
532
534 {
535 .name = "default",
536 .type = AVMEDIA_TYPE_VIDEO,
537 .config_props = config_output,
538 },
539};
540
542 .p.name = "dnn_processing",
543 .p.description = NULL_IF_CONFIG_SMALL("Apply DNN processing filter to the input."),
544 .p.priv_class = &dnn_processing_class,
545 .priv_size = sizeof(DnnProcessingContext),
547 .init = init,
548 .uninit = uninit,
552 .activate = activate,
553 .p.flags = AVFILTER_FLAG_HWDEVICE,
554 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
555};
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_dnn_processing
static FILE * out
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
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:1507
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1112
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:1560
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FLAGS
Definition cmdutils.c:596
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static enum AVPixelFormat pix_fmt
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_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
int ff_dnn_set_hw_frames_ctx(DnnContext *ctx, AVBufferRef *hw_frames_ctx)
int ff_dnn_get_input(DnnContext *ctx, DNNData *input)
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_filter_init_child_class(AVFilterContext *filter)
common functions for the dnn based filters
#define AVFILTER_DNN_DEFINE_CLASS(fname, backend_mask)
static int dnn_get_height_idx_by_layout(DNNLayout layout)
DNNAsyncStatusType
@ DAST_NOT_READY
@ DAST_SUCCESS
DNNBackendType
@ DNN_OV
@ DNN_ONNX
@ DNN_TH
@ DNN_TF
@ DFT_PROCESS_FRAME
static int dnn_get_width_idx_by_layout(DNNLayout layout)
@ DNN_UINT8
@ DNN_FLOAT
static int dnn_get_channel_idx_by_layout(DNNLayout layout)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
int ret
Definition ffplay.c:391
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition avfilter.h:193
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:602
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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
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
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:1695
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:2007
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
Definition utils.c:2338
@ SWS_BICUBIC
2-tap cubic B-spline
Definition swscale.h:199
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition hwcontext.c:347
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition hwcontext.c:267
An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
misc image utilities
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
Definition filters.h:279
#define FILTER_OUTPUTS(array)
Definition filters.h:280
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
Definition filters.h:744
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition filters.h:208
#define FILTER_PIXFMTS_ARRAY(array)
Definition filters.h:259
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:679
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition filters.h:689
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define av_always_inline
Definition attributes.h:72
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
const char * desc
Definition libsvtav1.c:83
#define check(x, y, S, v)
AVOptions.
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:3404
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition pixdesc.h:136
#define AV_PIX_FMT_GRAYF32
Definition pixfmt.h:591
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ 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
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
Definition pixfmt.h:440
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition pixfmt.h:260
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition pixfmt.h:80
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition pixfmt.h:140
static av_cold int preinit(AVBitStreamFilterContext *ctx)
Definition source.c:137
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Describe the class of an AVClass context structure.
Definition log.h:76
This struct is allocated as AVHWFramesContext.hwctx.
DXGI_FORMAT format
DXGI_FORMAT format.
An instance of a filter.
Definition avfilter.h:279
AVFilterLink ** inputs
array of pointers to input links
Definition avfilter.h:287
void * priv
private data for use by the filter
Definition avfilter.h:294
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition frame.h:581
size_t crop_right
Definition frame.h:808
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
int width
Definition frame.h:551
int height
Definition frame.h:551
size_t crop_top
Definition frame.h:805
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:524
size_t crop_left
Definition frame.h:807
size_t crop_bottom
Definition frame.h:806
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:566
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition hwcontext.h:200
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition hwcontext.h:153
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
int initial_pool_size
Initial size of the frame pool.
Definition hwcontext.h:190
int width
The allocated dimensions of the frames in this pool.
Definition hwcontext.h:220
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
DNNDataType dt
int dims[4]
DNNLayout layout
struct SwsContext * sws_uv_scale
AVBufferRef * hw_frames_ctx_out
Main external API structure.
Definition swscale.h:227
external API header
#define av_log(a,...)
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition time.c:93
static FilteringContext * filter_ctx
Definition transcode.c:52
static int64_t pts
static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLink *inlink, DNNBackendType backend_type)
static int copy_uv_planes(DnnProcessingContext *ctx, AVFrame *out, const AVFrame *in)
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
static int config_input(AVFilterLink *inlink)
static const AVFilterPad dnn_processing_outputs[]
static int prepare_uv_scale(AVFilterLink *outlink)
static int activate(AVFilterContext *filter_ctx)
static const AVOption dnn_processing_options[]
static av_cold void uninit(AVFilterContext *ctx)
#define LOG_FORMAT_CHANNEL_MISMATCH()
static const AVFilterPad dnn_processing_inputs[]
#define OFFSET(x)
static int config_output(AVFilterLink *outlink)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:120