About the 04_video_dec_trt

hi ,now i read the 04_video_dec_trt source code ,i found that sample decode data to the abgr32 format ,but when do algorithm use the following source code,i want to know whether it can convert the abgr32 to bgr24?because i haved get the answer the nano is not supported bgr24 data
// map eglimage into GPU address
CUeglFrame eglFrame = dec_ctx->dma_egl_map.find(dma_buf_fd)->second;
convertEglFrameIntToFloat(&eglFrame,
ctx->trt_ctx->getNetWidth(),
ctx->trt_ctx->getNetHeight(),
(TRT_MODEL == GOOGLENET_THREE_CLASS || TRT_MODEL == RESNET_THREE_CLASS) ? COLOR_FORMAT_BGR : COLOR_FORMAT_RGB,
(char *)cuda_buf + batch_offset * sizeof(float),
ctx->trt_ctx->getOffsets(),
ctx->trt_ctx->getScales(),
dec_ctx->pStream_conversion);

1 Like

Hi,
BGR format is not supported by hardware VIC engine. In the sample, it utilizes CUDA programming to re-sample RGBA to BGR. You may take a look at

/usr/src/jetson_multimedia_api/samples/common/algorithm/cuda
1 Like

thanks for your answer, another question is that i found that nvjpeg lib at the following link ,i want to know the differences with the lib libnvjpeg on nano,because i found that lib can decode to bgr
https://developer.nvidia.com/nvjpeg

Hi,
The link is for desktop GPUs. For Jetson platforms, please look at
https://docs.nvidia.com/jetson/l4t-multimedia/l4t_mm_jpeg_decode.html
Output format is YUV420.

1 Like

hi DaneLLL,thanks for your help ,now i have a question is that ,when i dec a jpeg dec_dma_fd ,and then i use the NvBufferTransform to another out_fd ,then i use the following source code to convert the int to float

EGLImageKHR eglImage = NULL;
eglImage = NvEGLImageFromFd(ctx->egl_display, ctx->out_fd);
mapEGLImage2Float(&eglImage,net_width,net_width,COLOR_FORMAT_BGR,(char *)cuda_buf,offsets,scales);

but that will have the following failed:
cuCtxSynchronize failed after memcpy
cuGraphicsEGLUnRegisterResource failed: 719

so why

Hi,
You probably don’t convert the buffer to V4L2_PIX_FMT_ABGR32.

hi Danelll,thanks for your help,i have convert to the abgr32 with using the follwing function

NvBufferTransform

Hi,
You probably don’t allocate the buffers correctly. Please refer to the sample code:

        void *cuda_buf, *off, *scale;
        int offsets[3] = {0, 0, 0};
        float input_scale[3] = {1.0f, 1.0f, 1.0f};
        cudaMalloc(&cuda_buf, width*height*3*sizeof(float));
        cudaMalloc(&off, sizeof(int)*3);
        cudaMalloc(&scale, sizeof(float)*3);
        cudaMemcpy(off, (void*)&offsets, sizeof(int)*3, cudaMemcpyHostToDevice);
        cudaMemcpy(scale, (void*)&input_scale, sizeof(float)*3, cudaMemcpyHostToDevice);
        mapEGLImage2Float(&ctx->egl_image,
                width,
                height,
                COLOR_FORMAT_BGR,
                (char *)cuda_buf,
                (char *)off,
                (char *)scale);
        cudaFree(cuda_buf);
        cudaFree(off);
        cudaFree(scale);
1 Like

my parameter is set the same with you ,but it stills have the error,i think may be the Algorithm Engineer init the algorithm error,now we can do not focus on this issue.another question is that whether convertIntToFloatKernelBGR function cuda_buf data is bgr24? if i want to save the cuda memory data but the data is float
from the function convertIntToFloatKernelBGR,so how can i get the int type data or char type data.can you give me some function like the convertIntToFloatKernelBGR

Hi,
The code is open source in

/usr/src/jetson_multimedia_api/samples/common/algorithm/cuda

You can refer to it and implement the function. Please note convertIntToFloatKernelBGR() is to re-sample single int RGBA plane, into three float planes(one float B plane, one float G plane, and one float R plane).

1 Like