writing to video file and reading file at same time

asked 2016-03-30 13:46:03 -0500

I am trying to write a web cam video and then read from the video file (on my HD), and display the frames, at same time. My reasoning is to be able to "rewind" or go back multiple frames, pause,etc while still capturing the video, and then to go back to live steam. I thought reading from the written file would be better/easier that having to creating a very long buffer.

Problem: After i start to write the video (which writes fine) and try to open a VideoCapture obj readVideo, the readVideo.isOpened() function returns false. I've tried to delay the readVideo instatiation by writing a bunch of frames( 30,60,100) first, but isOpened() always returns false.

If I create 2 separate programs (one to write a file, the other to read the same file) and then run each binary in two separate terminals (starting with the write file) i can write the file and read it at the same time, but of course there is a lag until the read gets to the end of file.

I'm Using: (Debian offshoot) Linux, and OpenCV 3.1

Maybe this is the wrong approach. Any ideas are appreciated.

edit retag flag offensive close merge delete

Comments

It is basically wrong to read and write to the same memory location at the same time. That is a bad way of programming. If you want to go back and forward in editing video for example, start by loading the original video in memory, process inside memory, then write the final result back to the HD. Also, avoid many reading and writing from HD, since it will cripple your application. Reading directly from memory is way better! And thus what you should do.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-03-31 04:47:20 -0500 )edit