part of Course 131 Data Munging Tips and Tricks
You can stitch images into a movie
ffmpeg -pattern_type glob -i '*.png' -y -c:v libx264 movie_name.mp4
Or break a movie's frames out into images
ffmpeg -i movie_name.mp4 img_%05d.png
Video is a natural way for us to understand three dimensional and time varying information. It's how we navigate the world. Converting images to video is a great way to level up your data science results. It helps you to communicate more clearly and it gives you eye-catching GIFs in the process.
You can go the other direction too and convert video to a sequence of images. This is helpful if you want to do frame-by-frame analysis on video in machine learning applications.
Prerequisites
- Install FFmpeg. It's a powerful open source audio video processing tool. It has a dizzying collection of cryptic command line options, so when you settle on the one that meets your needs, it's very much a Wingardium Leviosa moment. It's available on Linux, MacOS, and Windows.
- Make sure all the images are the same size - that they have the same number of pixel rows and columns.
-
Put all the
.png
images you want to use as video frames into a directory by themselves.
Images are ordered alphabetically by filename and stitched together to make your video.
For the adventurous, you can exercize absolute control over every step of this process. Want to change the frame rate? Use a different video filetype? Add music? Just read through the FFmpeg documentation.
You can help keep open source open
If this solution works for you, consider sending support to the FFmpeg project. Maybe enough to buy a cup of coffee. Or a coffee machine. It goes toward keeping their servers running. All the human work that goes into it is donated.
Good luck in your video production!