Reputation: 3564
I am currently trying to create a program that takes a video file, usually an AVI, and trying to convert it into images. So far I got the process working perfectly and could be left alone if needed. However, I would like to see if it was possible to optimize it for speed. So my question is if it is possible to load a portion of a video file into memory chunk by chunk instead of streaming it. Maybe load up a 2 - 3 minute clip into a buffer, process it, and reuse it for the next 2 - 3 minutes of video. I have looked into Direct Show and OpenCV into loading and playing video files, but so far haven't been able to find anything regarding loading videos into a buffer. Any links to tutorials or concepts is greatly appreciated.
This will be developed on a Windows XP/7 machine if it helps.
Upvotes: 2
Views: 1983
Reputation:
What you can do is to load a few frames, lets call it a chunk of N frames, into a queue from the disk. Once you set a limit for the buffer, you then pull the frames out and process them. You can do this in parallel by using two queues (Q1 and Q2) and two threads (T1 and T2). While processing frames from Q1 using T2, you can load Q2 using T1. You will be doing a context-switching one queue when it is full and pull the frames out and process them while the other queue is being loaded with frames from the disk. Of course you will need to handle the threading/parallelization intricacies associated with such an approach, in which case, BOOST threading might be helpful.
Upvotes: 3
Reputation: 93410
The bottleneck of an application like that is reading the file from the disk, and converting each frame to an image. You can't escape from those tasks. Unless you are doing it in the wrong way, there's nothing you can do to significantly speed up the execution of the application.
Hopefully you don't have to write those images back to the disk.
Upvotes: 1