sumit
sumit

Reputation: 141

How can i save video frames into a buffer?

I was using VideoCapture to read frames from a webcam and write into a directory using VideoWriter. But a new idea has come to my mind like if i want to save the video on the press of a PUSH BUTTON with 50 frames back the time the button is pressed and then continue with the live frames. Is there any way to do it. As i have observed that writing from a source should be continous, if we are changing the source we need to reinitialize the VideoWriter.open().

Upvotes: 0

Views: 1522

Answers (1)

MBo
MBo

Reputation: 80187

So you need to store last 50 frames and write them into video file by demand.

You can use ring buffer (circular queue). Fill it with incoming frames, and every time update the oldest frame with new one. What are webcam frame format and goal OS/computer platform? In some cases memory consumption might be a problem.

When recoding starts, extract frames one-by-one and add them to VideoWriter. During this process, insert incoming frames in the buffer to avoid frame loss, until buffer is empty.

Upvotes: 1

Related Questions