Search code examples
encodingcameranvidiavideo-encodingvideo-compression

Getting corrupted output when using NVENCODE API


I’m trying to use the NVENC API (specifically the AppEncode application) available as part of Video Codec SDK 11.1.5 to encode a yuv video (saved from IMX490 sensor) using H.264 encoding.

After building the required libraries using CMake, I give the following command:

./AppEncCuda -i ~/Desktop/input-yuv420p.yuv -s 320x320 -tuninginfo lowlatency -rc cbr -gpu 0 -bitrate 2M -maxbitrate 4M -vbvbufsize 6M -vbvinit 25 -bf 0 -aq 0 -cq 20 -multipass qres -o ~/Desktop/output-yuv.h264

A bit of additional information: input-yuv420p.yuv has pixel format yuyv422(progressive), 2880x1860 All the flags set were based on recommended settings (NVENC Video Encoder API Programming Guide :: NVIDIA Video Codec SDK Documentation)

Hardware used: CUDA 11.4, NVIDIA GeForce RTX 3050 Ti

I also tried the equivalent using ffmpeg (h264_nvenc and h264_cuvid) and it works perfectly. However, when I try to encode just using the NVENC APIs I get corrupted outputs. I have tried converting the pixel format to yuv420p and encode, still doesn’t work. When I try to display by encoded files using VLC media player I get green pixels/lines and random colours.

enter image description here

enter image description here

I’m quite new to using NVENC API so I started right away with the Video SDK but I’m facing these issues. I’m not sure what’s causing it, so any advice would be really helpful!


Solution

  • It was as simple as changing -s 320x320 to -s 2880x1860. -s flag denotes the input resolution size rather than scale (which is what I initially assumed).

    Ideally a command like this should work smoothly:

    ./AppEncCuda -i ~/Desktop/input-yuv420p.yuv -s 2880x1860 -tuninginfo lowlatency -rc cbr -gpu 0 -bitrate 2M -maxbitrate 4M -vbvbufsize 6M -vbvinit 25 -bf 0 -aq 0 -cq 20 -multipass qres -o ~/Desktop/output-yuv.h264