How can I convert a video file (mpeg, for example) into a collection of images?
Ideal answer would cover both C++ and Java using available libraries, and also how to manually strip the individual frames out of a video file for some common video format.
To extract all frames losslessly, use
If you prefer a different output format, just change
.png; by defaultffmpegwill infer the file type from the extension.The option
-f image2tellsffmpegto write to a series of images. The"outdir/%05d.png"gives a filename pattern, in this case “5-digit frame number.png“.If you only want to extract n frames per second, add the option
-r nafter"$input_file". (I think n can be floating-point.)In the case that your video is Motion JPEG (mjpeg), instead use:
This unpacks the frames directly from the video stream, which is faster and obviously uses less disk space.
For more information/other options, see the man page or the documentation (search for
image2).