35 return sizeof(uint8_t);
46 int linesize[4] = { 0 };
47 void **dst_data =
NULL;
48 void *middle_data =
NULL;
49 uint8_t *planar_data[4] = { 0 };
50 int plane_size =
frame->width *
frame->height *
sizeof(uint8_t);
67 "scale: %f, mean: %f\n", output->
scale, output->
mean);
71 dst_data = (
void **)
frame->data;
72 linesize[0] =
frame->linesize[0];
79 dst_data = &middle_data;
80 linesize[0] =
frame->width * 3;
83 switch (
frame->format) {
95 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
101 sws_scale(sws_ctx, (
const uint8_t *[4]){(
const uint8_t *)output->
data, 0, 0, 0},
102 (
const int[4]){
frame->width * 3 * src_datatype_size, 0, 0, 0}, 0,
frame->height,
103 (uint8_t *
const*)dst_data, linesize);
115 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
116 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
123 planar_data[0] = (uint8_t *)middle_data + plane_size;
124 planar_data[1] = (uint8_t *)middle_data + plane_size * 2;
125 planar_data[2] = (uint8_t *)middle_data;
127 planar_data[0] = (uint8_t *)middle_data + plane_size;
128 planar_data[1] = (uint8_t *)middle_data;
129 planar_data[2] = (uint8_t *)middle_data + plane_size * 2;
131 sws_scale(sws_ctx, (
const uint8_t *
const *)planar_data,
132 (
const int [4]){
frame->width *
sizeof(uint8_t),
133 frame->width *
sizeof(uint8_t),
134 frame->width *
sizeof(uint8_t), 0},
141 output->
data, bytewidth,
142 bytewidth,
frame->height);
159 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
160 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
166 sws_scale(sws_ctx, (
const uint8_t *[4]){(
const uint8_t *)output->
data, 0, 0, 0},
167 (
const int[4]){
frame->width * src_datatype_size, 0, 0, 0}, 0,
frame->height,
168 (uint8_t *
const*)
frame->data,
frame->linesize);
186 int linesize[4] = { 0 };
187 void **src_data =
NULL;
188 void *middle_data =
NULL;
189 uint8_t *planar_data[4] = { 0 };
190 int plane_size =
frame->width *
frame->height *
sizeof(uint8_t);
206 "scale: %f, mean: %f\n", input->
scale, input->
mean);
210 src_data = (
void **)
frame->data;
211 linesize[0] =
frame->linesize[0];
218 src_data = &middle_data;
219 linesize[0] =
frame->width * 3;
222 switch (
frame->format) {
235 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
236 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
243 planar_data[0] = (uint8_t *)middle_data + plane_size;
244 planar_data[1] = (uint8_t *)middle_data + plane_size * 2;
245 planar_data[2] = (uint8_t *)middle_data;
247 planar_data[0] = (uint8_t *)middle_data + plane_size;
248 planar_data[1] = (uint8_t *)middle_data;
249 planar_data[2] = (uint8_t *)middle_data + plane_size * 2;
252 frame->linesize, 0,
frame->height, planar_data,
253 (
const int [4]){frame->width * sizeof(uint8_t),
254 frame->width * sizeof(uint8_t),
255 frame->width * sizeof(uint8_t), 0});
266 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
267 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
273 sws_scale(sws_ctx, (
const uint8_t **)src_data,
274 linesize, 0,
frame->height,
275 (uint8_t *
const [4]){input->data, 0, 0, 0},
276 (
const int [4]){frame->width * 3 * dst_datatype_size, 0, 0, 0});
282 bytewidth,
frame->height);
299 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
300 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
308 (uint8_t *
const [4]){input->data, 0, 0, 0},
309 (
const int [4]){frame->width * dst_datatype_size, 0, 0, 0});
325 switch (
data->order) {
331 av_assert0(!
"unsupported data pixel format.\n");
343 int offsetx[4], offsety[4];
344 uint8_t *bbox_data[4];
350 int width_idx, height_idx;
354 int max_step[4] = { 0 };
361 "scale: %f, mean: %f\n", input->
scale, input->
mean);
366 av_log(log_ctx,
AV_LOG_ERROR,
"dnn_classify input data doesn't support layout: NCHW\n");
383 input->
dims[width_idx],
384 input->
dims[height_idx], fmt,
388 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
391 input->
dims[width_idx],
392 input->
dims[height_idx]);
398 av_log(log_ctx,
AV_LOG_ERROR,
"unable to get linesizes with av_image_fill_linesizes");
405 offsetx[0] = offsetx[3] =
left;
408 offsety[0] = offsety[3] = top;
411 for (
int k = 0;
frame->data[k]; k++)
412 bbox_data[k] =
frame->data[k] + offsety[k] *
frame->linesize[k] + offsetx[k] * max_step[k];
414 sws_scale(sws_ctx, (
const uint8_t *
const *)&bbox_data,
frame->linesize,
416 (uint8_t *
const [4]){input->data, 0, 0, 0}, linesizes);
427 int ret = 0, width_idx, height_idx;
434 "scale: %f, mean: %f\n", input->
scale, input->
mean);
439 av_log(log_ctx,
AV_LOG_ERROR,
"dnn_detect input data doesn't support layout: NCHW\n");
447 input->
dims[width_idx],
448 input->
dims[height_idx], fmt,
451 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
452 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
455 input->
dims[height_idx]);
461 av_log(log_ctx,
AV_LOG_ERROR,
"unable to get linesizes with av_image_fill_linesizes");
467 (uint8_t *
const [4]){input->data, 0, 0, 0}, linesizes);
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define AV_CEIL_RSHIFT(a, b)
static __device__ float fabsf(float a)
static av_always_inline AVDetectionBBox * av_get_detection_bbox(const AVDetectionBBoxHeader *header, unsigned int idx)
static int dnn_get_height_idx_by_layout(DNNLayout layout)
static int dnn_get_width_idx_by_layout(DNNLayout layout)
static int get_datatype_size(DNNDataType dt)
int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx)
int ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx)
int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index, void *log_ctx)
static enum AVPixelFormat get_pixel_format(DNNData *data)
int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx)
DNN input&output process between AVFrame and DNNData.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
@ AV_FRAME_DATA_DETECTION_BBOXES
Bounding boxes for object detection and classification, as described by AVDetectionBBoxHeader.
#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 av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
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_FAST_BILINEAR
Scaler selection options.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
Memory handling functions.
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_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_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_GBRP
planar GBR 4:4:4 24bpp
static const uint8_t header[24]
int x
Distance in pixels from the left/top edge of the frame, together with width and height,...
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Main external API structure.