35 return sizeof(uint8_t);
46 int linesize[4] = { 0 };
47 void **dst_data =
NULL;
48 void *middle_data =
NULL;
50 uint8_t *planar_data[4] = { 0 };
51 int plane_size =
frame->width *
frame->height *
sizeof(uint8_t);
69 "scale: %f, mean: %f\n", output->
scale, output->
mean);
73 dst_data = (
void **)
frame->data;
74 linesize[0] =
frame->linesize[0];
81 dst_data_buf[0] = middle_data;
82 dst_data = dst_data_buf;
83 linesize[0] =
frame->width * 3;
86 switch (
frame->format) {
90 if (output->
dims[channel_idx] != 3) {
92 "dnn_processing to a %s frame requires a 3-channel model "
93 "output, got %d channels; channel-reducing/expanding "
94 "models (e.g. single-channel matte output) are not "
95 "supported by this filter\n",
108 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
109 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
115 sws_scale(sws_ctx, (
const uint8_t *[4]){(
const uint8_t *)output->
data, 0, 0, 0},
116 (
const int[4]){
frame->width * 3 * src_datatype_size, 0, 0, 0}, 0,
frame->height,
117 (uint8_t *
const*)dst_data, linesize);
129 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
130 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
137 planar_data[0] = (uint8_t *)middle_data + plane_size;
138 planar_data[1] = (uint8_t *)middle_data + plane_size * 2;
139 planar_data[2] = (uint8_t *)middle_data;
141 planar_data[0] = (uint8_t *)middle_data + plane_size;
142 planar_data[1] = (uint8_t *)middle_data;
143 planar_data[2] = (uint8_t *)middle_data + plane_size * 2;
145 sws_scale(sws_ctx, (
const uint8_t *
const *)planar_data,
146 (
const int [4]){
frame->width *
sizeof(uint8_t),
147 frame->width *
sizeof(uint8_t),
148 frame->width *
sizeof(uint8_t), 0},
155 output->
data, bytewidth,
156 bytewidth,
frame->height);
173 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
174 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
180 sws_scale(sws_ctx, (
const uint8_t *[4]){(
const uint8_t *)output->
data, 0, 0, 0},
181 (
const int[4]){
frame->width * src_datatype_size, 0, 0, 0}, 0,
frame->height,
182 (uint8_t *
const*)
frame->data,
frame->linesize);
200 int linesize[4] = { 0 };
201 void **src_data =
NULL;
202 void *middle_data =
NULL;
204 uint8_t *planar_data[4] = { 0 };
205 int plane_size =
frame->width *
frame->height *
sizeof(uint8_t);
221 "scale: %f, mean: %f\n", input->
scale, input->
mean);
225 src_data = (
void **)
frame->data;
226 linesize[0] =
frame->linesize[0];
233 src_data_buf[0] = middle_data;
234 src_data = src_data_buf;
235 linesize[0] =
frame->width * 3;
238 switch (
frame->format) {
251 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
252 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
259 planar_data[0] = (uint8_t *)middle_data + plane_size;
260 planar_data[1] = (uint8_t *)middle_data + plane_size * 2;
261 planar_data[2] = (uint8_t *)middle_data;
263 planar_data[0] = (uint8_t *)middle_data + plane_size;
264 planar_data[1] = (uint8_t *)middle_data;
265 planar_data[2] = (uint8_t *)middle_data + plane_size * 2;
268 frame->linesize, 0,
frame->height, planar_data,
269 (
const int [4]){frame->width * sizeof(uint8_t),
270 frame->width * sizeof(uint8_t),
271 frame->width * sizeof(uint8_t), 0});
282 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
283 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
289 sws_scale(sws_ctx, (
const uint8_t **)src_data,
290 linesize, 0,
frame->height,
291 (uint8_t *
const [4]){input->data, 0, 0, 0},
292 (
const int [4]){frame->width * 3 * dst_datatype_size, 0, 0, 0});
298 bytewidth,
frame->height);
315 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
316 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
324 (uint8_t *
const [4]){input->data, 0, 0, 0},
325 (
const int [4]){frame->width * dst_datatype_size, 0, 0, 0});
341 switch (
data->order) {
347 av_assert0(!
"unsupported data pixel format.\n");
357 int src_linesize,
int w,
int h);
362 int offsetx[4], offsety[4];
363 uint8_t *bbox_data[4];
369 int width_idx, height_idx;
373 int max_step[4] = { 0 };
380 "scale: %f, mean: %f\n", input->
scale, input->
mean);
397 offsetx[0] = offsetx[3] =
left;
400 offsety[0] = offsety[3] = top;
403 for (
int k = 0;
frame->data[k]; k++)
404 bbox_data[k] =
frame->data[k] + offsety[k] *
frame->linesize[k] + offsetx[k] * max_step[k];
413 int tmp_linesize =
dst_w * 3;
423 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
430 sws_scale(sws_ctx, (
const uint8_t *
const *)&bbox_data,
frame->linesize,
432 (uint8_t *
const [4]){tmp_buf, 0, 0, 0},
433 (
const int [4]){tmp_linesize, 0, 0, 0});
441 input->
dims[width_idx],
442 input->
dims[height_idx], fmt,
446 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
449 input->
dims[width_idx],
450 input->
dims[height_idx]);
456 av_log(log_ctx,
AV_LOG_ERROR,
"unable to get linesizes with av_image_fill_linesizes");
461 sws_scale(sws_ctx, (
const uint8_t *
const *)&bbox_data,
frame->linesize,
463 (uint8_t *
const [4]){input->data, 0, 0, 0}, linesizes);
474 int src_linesize,
int w,
int h)
476 const size_t plane_size = (size_t)
w *
h;
482 for (
int c = 0;
c < 3;
c++)
483 for (
int y = 0; y <
h; y++) {
484 const uint8_t *row =
src + (ptrdiff_t)y * src_linesize;
485 for (
int x = 0; x <
w; x++)
486 dst[
c * plane_size + (
size_t)y *
w + x] = row[x * 3 +
c];
490 for (
int y = 0; y <
h; y++) {
491 const uint8_t *row =
src + (ptrdiff_t)y * src_linesize;
492 for (
int x = 0; x <
w * 3; x++)
493 dst[(
size_t)y *
w * 3 + x] = row[x];
499 for (
int c = 0;
c < 3;
c++)
500 for (
int y = 0; y <
h; y++) {
501 const uint8_t *row =
src + (ptrdiff_t)y * src_linesize;
502 for (
int x = 0; x <
w; x++)
503 dst[
c * plane_size + (
size_t)y *
w + x] = row[x * 3 +
c];
511 uint8_t *tmp_buf =
NULL;
515 int ret = 0, width_idx, height_idx, channel_idx;
519 switch (input->
order) {
529 "scale: %f, mean: %f\n", input->
scale, input->
mean);
535 "color order: %d\n", input->
order);
541 "data type: %d\n", input->
dt);
549 w = input->
dims[width_idx];
550 h = input->
dims[height_idx];
551 if (
w <= 0 ||
h <= 0) {
553 "dimensions: %dx%d\n",
w,
h);
558 if (!packed_u8 && input->
dims[channel_idx] != 3) {
560 "but the model has %d channels\n",
561 input->
dims[channel_idx]);
567 av_log(log_ctx,
AV_LOG_ERROR,
"unable to get linesizes with av_image_fill_linesizes");
576 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
577 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
584 (uint8_t *
const [4]){input->data, 0, 0, 0}, linesizes);
591 src_linesize =
frame->linesize[0];
595 if (
av_size_mult((
size_t)linesizes[0], (
size_t)
h, &tmp_size) < 0) {
607 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
608 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
616 (uint8_t *
const [4]){tmp_buf, 0, 0, 0}, linesizes);
621 src_linesize = linesizes[0];
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
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 dnn_get_channel_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)
static void detect_write_tensor(DNNData *input, const uint8_t *src, int src_linesize, int w, int h)
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.
int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
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.
int dst_h
Width and height of the destination frame.