How to convert a video file (e.g. mpeg) to a collection of images?

How to convert a video file (e.g. mpeg) to a collection of images?

The ideal answer would cover both C ++ and Java using the available libraries, as well as how to manually cut individual frames from a video file for some common video format.

+5
source share
3 answers

To retrieve all lossless frames, use

ffmpeg -i "$input_file" -f image2 "outdir/%05d.png"

If you prefer a different output format, just change .png; by default ffmpegwill output the file type from the extension.

The option -f image2tells ffmpegto write to a series of images. "outdir/%05d.png"gives the file name pattern, in this case " 5-digit frame number.png".

n , -r n "$input_file". ( , n .)

, Motion JPEG (mjpeg), :

ffmpeg -i "$input_file" -vcodec copy -f image2 "outdir/%05d.jpg"

, , , .

/ . ( image2).

+6

, ffmpeg -vcodec png. , my_video.avi :

ffmpeg -i my_video.avi -vcodec png frame% 05d.png

. ffmpeg -codecs, .

+3

Perhaps you can use apiexample.cffmpeg in the library libavcodec, which will allow you to see how to take the frame buffer to easily encode it in the mpeg stream.

Alternatively, you can use Gstreamer , which is much more neat.

For Java, try using the Java Media Framework .

0
source

All Articles