cuvidDecodePicture decode video frame sync

I want use NVDecoder to decode h264 stream one by one. I use ffmpeg to read h264 data frame which can replace video source reading data from h264 file.but there is a question:
At the first time I pass frame data to “cuvidParseVideoData” function, the decode callback HandlePictureDecode function not be called.At the seconde time, pass frame to it, the HandlePictureDecode callback will been executed.So I suspect that the NvDecoder will decode the first frame, at the second calling “cuvidParseVideoData” function. It will has a frame decoded delay time.But I want to directly decode current frame sync, How can I do?
Thanks for replying.

It is not possible to get HandlePictureDisplay callbacks one-by-one corresponding to cuvidParseVideoData calls.

However, you can “decode h264 stream one by one”. You use one thread to continuously inject data but add pacing in the DisplayPicture call. Something like this:


// decoded picture available here
wait for signal from thread 2
continue with the call to deliver the picture

Thread 1:

Continuously inject data. Will be paced by the wait in DisplayPicture.

Thread 2:

When you want a decoded picture, set the signal to DisplayPicture.

This will let you get the decoded pictures one-by-one in display order.

I’m sorry I don’t understand what’s your meaning.Can you show me some code? Thanks

Just for your information:

I just tried to decode h264 stream one by one. And got HandlePictureDecode function every after cuvidParseVideoData call by using the following coding:


however, there is no valid data pointer at DisplayQueue on HandlePictureDisplay function.

I guess NVDEC cannot decode h264 stream one by one for now.

What part do you not understand? Can’t show you my proprietary code but I can try to help you understand things enough to write your own code.

You’re just putting a wait for signal before delivering the picture. That way you can get the pictures one-by-one. Nothing difficult here.