Go to the documentation of this file.
43 #define OFFSET(x) offsetof(DnnProcessingContext, dnnctx.x)
44 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
47 #if (CONFIG_LIBTENSORFLOW == 1)
50 #if (CONFIG_LIBOPENVINO == 1)
53 #if (CONFIG_LIBTORCH == 1)
76 #define LOG_FORMAT_CHANNEL_MISMATCH() \
77 av_log(ctx, AV_LOG_ERROR, \
78 "the frame's format %s does not match " \
79 "the model input channel %d\n", \
80 av_get_pix_fmt_name(fmt), \
81 model_input->dims[dnn_get_channel_idx_by_layout(model_input->layout)]);
87 int width_idx, height_idx;
92 if (model_input->
dims[height_idx] != -1 &&
95 model_input->
dims[height_idx],
99 if (model_input->
dims[width_idx] != -1 &&
102 model_input->
dims[width_idx],
192 ctx->sws_uv_height = sws_src_h;
224 if (!
ctx->sws_uv_scale) {
228 for (
int i = 1;
i < 3; ++
i) {
235 bytewidth, uv_height);
239 0,
ctx->sws_uv_height,
out->data + 1,
out->linesize + 1);
242 0,
ctx->sws_uv_height,
out->data + 1,
out->linesize + 1);
244 0,
ctx->sws_uv_height,
out->data + 2,
out->linesize + 2);
273 *out_pts = out_frame->
pts +
pts;
371 .
name =
"dnn_processing",
380 .priv_class = &dnn_processing_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption dnn_processing_options[]
AVPixelFormat
Pixel format.
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
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
#define FILTER_PIXFMTS_ARRAY(array)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
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
void sws_freeContext(SwsContext *swsContext)
Free the swscaler context swsContext.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
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).
AVFILTER_DNN_DEFINE_CLASS(dnn_processing, DNN_TF|DNN_OV|DNN_TH)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
static av_cold int preinit(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
const char * name
Filter name.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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 ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
static int dnn_get_width_idx_by_layout(DNNLayout layout)
void * priv
private data for use by the filter
static FilteringContext * filter_ctx
int ff_dnn_filter_init_child_class(AVFilterContext *filter)
A filter pad used for either input or output.
static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define check(x, y, S, v)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
static int copy_uv_planes(DnnProcessingContext *ctx, AVFrame *out, const AVFrame *in)
#define AV_CEIL_RSHIFT(a, b)
static enum AVPixelFormat pix_fmt
static enum AVPixelFormat pix_fmts[]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int av_usleep(unsigned usec)
Sleep for a period of time.
#define FILTER_OUTPUTS(array)
#define AV_PIX_FMT_GRAYF32
static int check_modelinput_inlink(const DNNData *model_input, const AVFilterLink *inlink)
int ff_dnn_get_input(DnnContext *ctx, DNNData *input)
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
Describe the class of an AVClass context structure.
and forward the result(frame or status change) to the corresponding input. If nothing is possible
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static av_cold int init(AVFilterContext *context)
@ SWS_BICUBIC
2-tap cubic B-spline
static const AVFilterPad dnn_processing_inputs[]
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int ff_dnn_flush(DnnContext *ctx)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
const AVFilter ff_vf_dnn_processing
FF_FILTER_FORWARD_WANTED(outlink, inlink)
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.
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static int activate(AVFilterContext *filter_ctx)
const char * name
Pad name.
@ 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...
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.
int ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height)
int h
agreed upon image height
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.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
#define LOG_FORMAT_CHANNEL_MISMATCH()
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static int dnn_get_height_idx_by_layout(DNNLayout layout)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int dnn_get_channel_idx_by_layout(DNNLayout layout)
int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static int prepare_uv_scale(AVFilterLink *outlink)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
void ff_dnn_uninit(DnnContext *ctx)
int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
Main external API structure.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
struct SwsContext * sws_uv_scale
static const AVFilterPad dnn_processing_outputs[]
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.
static int config_output(AVFilterLink *outlink)