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},
156 output->
data, bytewidth,
157 bytewidth,
frame->height);
170 (
const uint8_t *[4]){(
const uint8_t *)output->
data, 0, 0, 0},
171 (
const int[4]){
frame->width * src_datatype_size, 0, 0, 0},
173 (uint8_t *
const*)
frame->data,
frame->linesize);
192 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
193 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
199 sws_scale(sws_ctx, (
const uint8_t *[4]){(
const uint8_t *)output->
data, 0, 0, 0},
200 (
const int[4]){
frame->width * src_datatype_size, 0, 0, 0}, 0,
frame->height,
201 (uint8_t *
const*)
frame->data,
frame->linesize);
219 int linesize[4] = { 0 };
220 void **src_data =
NULL;
221 void *middle_data =
NULL;
223 uint8_t *planar_data[4] = { 0 };
224 int plane_size =
frame->width *
frame->height *
sizeof(uint8_t);
240 "scale: %f, mean: %f\n", input->
scale, input->
mean);
244 src_data = (
void **)
frame->data;
245 linesize[0] =
frame->linesize[0];
252 src_data_buf[0] = middle_data;
253 src_data = src_data_buf;
254 linesize[0] =
frame->width * 3;
257 switch (
frame->format) {
270 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
271 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
278 planar_data[0] = (uint8_t *)middle_data + plane_size;
279 planar_data[1] = (uint8_t *)middle_data + plane_size * 2;
280 planar_data[2] = (uint8_t *)middle_data;
282 planar_data[0] = (uint8_t *)middle_data + plane_size;
283 planar_data[1] = (uint8_t *)middle_data;
284 planar_data[2] = (uint8_t *)middle_data + plane_size * 2;
287 frame->linesize, 0,
frame->height, planar_data,
288 (
const int [4]){frame->width * sizeof(uint8_t),
289 frame->width * sizeof(uint8_t),
290 frame->width * sizeof(uint8_t), 0});
301 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
302 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
308 sws_scale(sws_ctx, (
const uint8_t **)src_data,
309 linesize, 0,
frame->height,
310 (uint8_t *
const [4]){input->data, 0, 0, 0},
311 (
const int [4]){frame->width * 3 * dst_datatype_size, 0, 0, 0});
318 bytewidth,
frame->height);
330 (
const uint8_t *[4]){
frame->data[0], 0, 0, 0},
331 (
const int[4]){
frame->linesize[0], 0, 0, 0},
333 (uint8_t *
const[4]){input->
data, 0, 0, 0},
334 (
const int[4]){
frame->width * dst_datatype_size, 0, 0, 0});
353 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
354 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
362 (uint8_t *
const [4]){input->data, 0, 0, 0},
363 (
const int [4]){frame->width * dst_datatype_size, 0, 0, 0});
379 switch (
data->order) {
385 av_assert0(!
"unsupported data pixel format.\n");
395 int src_linesize,
int w,
int h);
400 int offsetx[4], offsety[4];
401 uint8_t *bbox_data[4];
407 int width_idx, height_idx;
411 int max_step[4] = { 0 };
418 "scale: %f, mean: %f\n", input->
scale, input->
mean);
435 offsetx[0] = offsetx[3] =
left;
438 offsety[0] = offsety[3] = top;
441 for (
int k = 0;
frame->data[k]; k++)
442 bbox_data[k] =
frame->data[k] + offsety[k] *
frame->linesize[k] + offsetx[k] * max_step[k];
451 int tmp_linesize =
dst_w * 3;
461 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
468 sws_scale(sws_ctx, (
const uint8_t *
const *)&bbox_data,
frame->linesize,
470 (uint8_t *
const [4]){tmp_buf, 0, 0, 0},
471 (
const int [4]){tmp_linesize, 0, 0, 0});
479 input->
dims[width_idx],
480 input->
dims[height_idx], fmt,
484 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
487 input->
dims[width_idx],
488 input->
dims[height_idx]);
494 av_log(log_ctx,
AV_LOG_ERROR,
"unable to get linesizes with av_image_fill_linesizes");
499 sws_scale(sws_ctx, (
const uint8_t *
const *)&bbox_data,
frame->linesize,
501 (uint8_t *
const [4]){input->data, 0, 0, 0}, linesizes);
512 int src_linesize,
int w,
int h)
514 const size_t plane_size = (size_t)
w *
h;
520 for (
int c = 0;
c < 3;
c++)
521 for (
int y = 0; y <
h; y++) {
522 const uint8_t *row =
src + (ptrdiff_t)y * src_linesize;
523 for (
int x = 0; x <
w; x++)
524 dst[
c * plane_size + (
size_t)y *
w + x] = row[x * 3 +
c];
528 for (
int y = 0; y <
h; y++) {
529 const uint8_t *row =
src + (ptrdiff_t)y * src_linesize;
530 for (
int x = 0; x <
w * 3; x++)
531 dst[(
size_t)y *
w * 3 + x] = row[x];
537 for (
int c = 0;
c < 3;
c++)
538 for (
int y = 0; y <
h; y++) {
539 const uint8_t *row =
src + (ptrdiff_t)y * src_linesize;
540 for (
int x = 0; x <
w; x++)
541 dst[
c * plane_size + (
size_t)y *
w + x] = row[x * 3 +
c];
549 uint8_t *tmp_buf =
NULL;
553 int ret = 0, width_idx, height_idx, channel_idx;
557 switch (input->
order) {
567 "scale: %f, mean: %f\n", input->
scale, input->
mean);
573 "color order: %d\n", input->
order);
579 "data type: %d\n", input->
dt);
587 w = input->
dims[width_idx];
588 h = input->
dims[height_idx];
589 if (
w <= 0 ||
h <= 0) {
591 "dimensions: %dx%d\n",
w,
h);
596 if (!packed_u8 && input->
dims[channel_idx] != 3) {
598 "but the model has %d channels\n",
599 input->
dims[channel_idx]);
605 av_log(log_ctx,
AV_LOG_ERROR,
"unable to get linesizes with av_image_fill_linesizes");
614 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
615 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
622 (uint8_t *
const [4]){input->data, 0, 0, 0}, linesizes);
629 src_linesize =
frame->linesize[0];
633 if (
av_size_mult((
size_t)linesizes[0], (
size_t)
h, &tmp_size) < 0) {
645 av_log(log_ctx,
AV_LOG_ERROR,
"Impossible to create scale context for the conversion "
646 "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
654 (uint8_t *
const [4]){tmp_buf, 0, 0, 0}, linesizes);
659 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.