Extract Frames From Video with FFmpeg in One Minute
- FFmpeg Installation
- Learn how to extract frames from video using FFmpeg
First, download or install the FFmpeg packages.
For MacOS, simply do
brew install ffmpeg and for Ubuntu, use
sudo apt install ffmpeg. For Windows, it’s a bit trickier, you will have to download FFmpeg build and set it up manually. You will need the two steps below:
- Download FFmpeg release essentials here.
- Add the bin folder to Windows Environment Path Variable to run this tool without having to specify the full path every time.
For more details, check out the previous Medium article I had written — FFmpeg — Your powerful video/audio helper in your application.
You can run the following command to extract every frame in the video.
- -i : input file(s)
ffmpeg -i video.mp4 output%06d.png
You can further specify how many frames to extract per second. For example, the command below with fps=2 will extract 2 frames per second.
- -vf : per-stream -filter option for video
ffmpeg -i video.mp4 -vf fps=2 output%06d.png
And fps=1/10 will extract 1 frame per 10 seconds.
ffmpeg -i video.mp4 -vf fps=1/10 output%06d.png
To read more about the FFmpeg, feel free to checkout their documentation.
Here is a quick demo.
This article is written by Han Sheng, Junior Artificial Intelligence Engineer in CertifAI, Penang, Malaysia. He has a passion for Deep Learning, Computer Vision and also Edge Devices. He made several AI-based Web/Mobile Applications to help clients solving real-world problems. Feel free to read about him via his portfolio or Github profile.