Why cudacodec::VideoReader returns 4 channels?

Hi, I’m using nvcuvid to decode the video and do inference with tensorrt for acceleration. However, every time I call retrieve() method, it gives me a 4-channel GpuMat, instead of 3. I have to convert it to 3 channels, since there are thousands of frames in one video, this operation consumes more time. Is there a way to get a 3-channel GpuMat directly from cudacodec::VideoReader?

I guess the answer to your question is probably a result of the colour conversion routine trying to take advantage of the specific transaction size for memory writes on what ever hardware version was available at the time. That is if the transaction size is 128 bytes then writing 32(1 warp)*4 (BGRA bytes) = 128 bytes would involve the same memory overhead as 32(1 warp)*3 (BGR bytes) = 96 bytes. Other considerations may have been that it can be easier to pack and unpack 4 bytes (int, float) than 3.

If you want BGR instead you can change the colour format before each call to VideoReader::nextFrame()with VideoReader::set(cv::cudacodec::ColorFormat::BGR).

1 Like