I have a simple C++ application that uses FFmpeg 3.2 to receive an H264 RTP stream. In order to save CPU, I'm doing the decoding part with the codec h264_cuvid. My FFmpeg 3.2 is compiled with hw acceleration enabled. In fact, if I do the command:
ffmpeg -hwaccels
I get
cuvid
This means that my FFmpeg setup has everything OK to "speak" with my NVIDIA card.
The frames that the function avcodec_decode_video2 provides me have the pixel format AV_PIX_FMT_CUDA. I need to convert those frames to new ones with AV_PIX_FMT_RGB. Unfortunately, I can't do the conversion using the well knwon functions sws_getContext and sws_scale because the pixel format AV_PIX_FMT_CUDA is not supported. If I try with swscale I get the error:
"cuda is not supported as input pixel format"
Do you know how to convert an FFmpeg AVFrame from AV_PIX_FMT_CUDA to AV_PIX_FMT_RGB ?
(pieces of code would be very appreciated)
You must use
vf_scale_nppto do this. You can use eithernppscale_deinterleaveornppscale_resizedepend on your needs.Both has same input parameters, which are AVFilterContext that should be initialize with
nppscale_init, NPPScaleStageContext which takes your in/out pixel format and two AVFrames which of course are your input and output frames.For more information you can see npplib\nppscale definition which will do the CUDA-accelerated format conversion and scaling since ffmpeg 3.1.
Anyway, I recommend to use NVIDIA Video Codec SDK directly for this purpose.