Do and VideoWriter.write() interact with each other


I am having a camera, which I am reading frames from, using cv::VideoCapture. Those frames are then saved into a Q, which another Thread is reading from, doing some image modification and writing them into a Video File using cv::VideoWriter.

Once upon a time it seems VideoWriter.write() and happen at the same time. I thought, this should have no interaction, however in these events returns false and an empty image (took me quite some time to figure that out). My programm storage for the new image to be read and for the old image to be written is for sure not the same. Is there any interdependency within those two classes, that leads to failing, when VideoWriter.write() is doing it’s magic?
I tried to look into the source Code but only found, that both call CV_INSTRUMENT_REGION(), but did not get very deep, before getting completely confused.

Cheers Daniel

no, they act independantly of each other.

Except when opening a file, where one waits on the other unless you explicity set OPENCV_FFMPEG_IS_THREAD_SAFE==true

1 Like

Thanks for your answers!
Is there any other possible way can fail immediately (without timeout), when it worked several times before and also works thereafter (I am using OpenCV 4.8 on Linux compiled without GStreamer)?
Also this only happens in the VideoWriter Context. When I modify the Writer Thread and it does not write the images into a Video FIle, but just grabs and discards the images a Million Frames go by just fine. No exception otherwise also. It just returns false every let’s say 500-1000 Frames. Any idea, that could lead me on the right track?

there have been other people who witnessed this “intermittent” failure of VideoCapture.

for now, you could just continue to read, regardless of one read() call’s failure. perhaps give up after several failed calls.