So this issue was opened many times before. Usually people having streams of packets and feeding them to the NVDEC. I understand that the problem with the CUVID parser callbacks not being called is usually caused by improper initialization of the stream according to this topic. According to this, this and this I understand that in h.265 there are NAL units, which are part of the encoded bitstream. They contain the information about the stream, especially SPS and PPS sections to properly setup the decoder. However, I can’t find the optimal way to solve my issue. Any assistance would be much appreciated!
So what I do now is:
- Encode input frames with FFmpeg and libx265
- Get the packet data
- Store it somewhere in a file and then reload in another app
- Send the packet data to nvdec - I am sending an I frame first followed by P frames
My question is: How do I ensure that the input packets to nvdec contain all the necessary information?
Do I need to manually create and inject the NAL units? I create the packets, they are not coming from any unknown sources, so is there any way to easily make them contain all the information? Can’t I force FFmpeg to include the necessary NAL modules in all packets? Or should I send a special packet to initialize the parser? I can even switch to raw NVENC if FFmpeg is not optimal for the encoding.
Right now this code executes with no error but none of the parser callbacks is called:
CUVIDSOURCEDATAPACKET packet{};
packet.payload = packetData;
packet.payload_size = packetSize;
packet.flags = CUVID_PKT_TIMESTAMP;
packet.timestamp = decodedNumber;
decodedNumber++;
if (packetPointer.size == 0)
packet.flags |= CUVID_PKT_ENDOFSTREAM;
if(cuvidParseVideoData(parser, &packet) != CUDA_SUCCESS)
throw std::runtime_error("Cannot parse packet.");
If you wish to see the rest of my code, here is the WIP commit I am using right now for the tests. I am trying now to get to the point where the parser actually tries to start the decoding.