I suppose that source stream has a fixed FPS.
You could reopen the video file, read the frames and save them into a new file with right FPS.. this will introduce big overhead specially for big videos
You could catch your video stream for a couple of seconds to measure source frame rate. Create your video file using measured frame rate. Sincerely 2 or 3 frame should be enough
- If you need to include initial part of the stream you have to cache it.
- If your process is fast enough you can to cache just 1st part
- If your process speed is close to source frame rate you need a tread that receives frames from video stream and write them a FIFO queue and a threads that reads frames from FIFO queue and save them into video file
finally if your process is slower than source frame rate you have to take some countermeasure because you can going into buffer overflow
unless you can cache all your images somehow, - no way, how things are atm.