I just wanted to split a video file in each single frame and did not find a program that solves this problem. A colleague recommended videodub, but when I see DLL’s or a .exe I get insane! I’ve been working a little bit with OpenCV before and coded my own solution, containing only a few lines.

The heart of my solution consists of the following 13 lines:

CvCapture *capture = cvCaptureFromAVI(video.c_str());
if (capture)
{
	IplImage* frame;
	while (frame = cvQueryFrame(capture))
	{
		stringstream file;
		file < < prefix << iteration << ".png";
		cvSaveImage(file.str ().c_str (), frame);
		iteration++;
	}
}
cvReleaseCapture( &capture );

It just queries each frame of the AVI and writes it to an image file. Thus, not a big deal.

The complete code can be downloaded here. All you need is OpenCV and a C++ compiler:

g++ -I /usr/local/include/opencv -lhighgui -o vidsplit.out vidsplit.cpp

Just start it with for example:

./vidsplit.out --input video.avi --prefix myframes_

If you prefer JPG images (or other types) just change the extension string form .png to .jpg .

Download: C++: vidsplit.cpp (Please take a look at the man-page. Browse bugs and feature requests.)

Martin Scharm

stuff. just for the records.


Post a comment

read more about submitting comments