40#if CONFIG_DNN_ONNX_D3D12
52#define OFFSET(x) offsetof(DnnProcessingContext, dnnctx.x)
53#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
56#if (CONFIG_LIBTENSORFLOW == 1)
59#if (CONFIG_LIBOPENVINO == 1)
62#if (CONFIG_LIBTORCH == 1)
65#if (CONFIG_LIBONNXRUNTIME == 1)
93#if CONFIG_DNN_ONNX_D3D12
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)]);
111 int width_idx, height_idx;
116 if (model_input->
dims[height_idx] != -1 &&
117 model_input->
dims[height_idx] != inlink->
h) {
119 model_input->
dims[height_idx],
123 if (model_input->
dims[width_idx] != -1 &&
124 model_input->
dims[width_idx] != inlink->
w) {
126 model_input->
dims[width_idx],
165 return ff_dnn_zero_copy_supported_cuda(&dnn_ctx->
dnnctx, inlink);
168#if CONFIG_DNN_ONNX_D3D12
176 return ff_dnn_zero_copy_supported_d3d12(&dnn_ctx->
dnnctx, inlink);
195#if CONFIG_DNN_ONNX_D3D12
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");
211 "D3D12 zero-copy currently only supports NV12 hardware "
228 if (!
ctx->dnnctx.model) {
263 if (inlink->
w != outlink->
w || inlink->
h != outlink->
h) {
268 ctx->sws_uv_height = inlink->
h >> 1;
278 ctx->sws_uv_height = sws_src_h;
286#if CONFIG_DNN_ONNX_D3D12
299 if (!
ctx->dnnctx.zero_copy_negotiated) {
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");
311 if ((inlink->w | inlink->h | outlink->w | outlink->h) & 1) {
313 "D3D12 zero-copy requires even NV12 frame dimensions, got %dx%d -> %dx%d\n",
314 inlink->w, inlink->h, outlink->w, outlink->h);
321 if (!
ctx->hw_frames_ctx_out)
327 frames_ctx->
width = outlink->w;
328 frames_ctx->
height = outlink->h;
330 if (context->extra_hw_frames > 0)
333 frames_hwctx = frames_ctx->
hwctx;
334 frames_hwctx->
format = DXGI_FORMAT_NV12;
344 if (!outl->hw_frames_ctx)
370#if CONFIG_DNN_ONNX_D3D12
373 return config_output_d3d12(outlink);
388 if (!
ctx->sws_uv_scale) {
392 for (
int i = 1;
i < 3; ++
i) {
399 bytewidth, uv_height);
403 0,
ctx->sws_uv_height,
out->data + 1,
out->linesize + 1);
406 0,
ctx->sws_uv_height,
out->data + 1,
out->linesize + 1);
408 0,
ctx->sws_uv_height,
out->data + 2,
out->linesize + 2);
437 *out_pts = out_frame->
pts +
pts;
542 .p.name =
"dnn_processing",
544 .p.priv_class = &dnn_processing_class,
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_dnn_processing
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.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define i(width, name, range_min, range_max)
#define AV_CEIL_RSHIFT(a, b)
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)
static int dnn_get_width_idx_by_layout(DNNLayout layout)
static int dnn_get_channel_idx_by_layout(DNNLayout layout)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_EOF
End of file.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
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.
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.
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.
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.
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
@ SWS_BICUBIC
2-tap cubic B-spline
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
#define FILTER_PIXFMTS_ARRAY(array)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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[]
#define check(x, y, S, v)
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_PIX_FMT_GRAYF32
AVPixelFormat
Pixel format.
@ 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...
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
static av_cold int preinit(AVBitStreamFilterContext *ctx)
A reference to a data buffer.
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
This struct is allocated as AVHWFramesContext.hwctx.
DXGI_FORMAT format
DXGI_FORMAT format.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int initial_pool_size
Initial size of the frame pool.
int width
The allocated dimensions of the frames in this pool.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
struct SwsContext * sws_uv_scale
AVBufferRef * hw_frames_ctx_out
Link properties exposed to filter code, but not external callers.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
Main external API structure.
int av_usleep(unsigned usec)
Sleep for a period of time.
static FilteringContext * filter_ctx
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[]
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.