45#define OFFSET(x) offsetof(DnnProcessingContext, dnnctx.x)
46#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
49#if (CONFIG_LIBTENSORFLOW == 1)
52#if (CONFIG_LIBOPENVINO == 1)
55#if (CONFIG_LIBTORCH == 1)
58#if (CONFIG_LIBONNXRUNTIME == 1)
84#define LOG_FORMAT_CHANNEL_MISMATCH() \
85 av_log(ctx, AV_LOG_ERROR, \
86 "the frame's format %s does not match " \
87 "the model input channel %d\n", \
88 av_get_pix_fmt_name(fmt), \
89 model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)]);
95 int width_idx, height_idx;
100 if (model_input->
dims[height_idx] != -1 &&
101 model_input->
dims[height_idx] != inlink->
h) {
103 model_input->
dims[height_idx],
107 if (model_input->
dims[width_idx] != -1 &&
108 model_input->
dims[width_idx] != inlink->
w) {
110 model_input->
dims[width_idx],
144 return ff_dnn_zero_copy_supported_cuda(&dnn_ctx->
dnnctx, inlink);
192 if (inlink->
w != outlink->
w || inlink->
h != outlink->
h) {
197 ctx->sws_uv_height = inlink->
h >> 1;
207 ctx->sws_uv_height = sws_src_h;
239 if (!
ctx->sws_uv_scale) {
243 for (
int i = 1;
i < 3; ++
i) {
250 bytewidth, uv_height);
254 0,
ctx->sws_uv_height,
out->data + 1,
out->linesize + 1);
257 0,
ctx->sws_uv_height,
out->data + 1,
out->linesize + 1);
259 0,
ctx->sws_uv_height,
out->data + 2,
out->linesize + 2);
288 *out_pts = out_frame->
pts +
pts;
386 .p.name =
"dnn_processing",
388 .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_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 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.
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
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 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.
#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_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)
Describe the class of an AVClass context structure.
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,...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
struct SwsContext * sws_uv_scale
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 copy_uv_planes(DnnProcessingContext *ctx, AVFrame *out, const AVFrame *in)
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLink *inlink)
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.