Extract Frames From Video with FFmpeg in One Minute

Liang Han Sheng
2 min readSep 11, 2021

--

Outcomes:

  1. FFmpeg Installation
  2. Learn how to extract frames from video using FFmpeg

Installation

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:

  1. Download FFmpeg release essentials here.
  2. 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.

Extraction

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.

Demo (Video source)

References

  1. https://github.com/FFmpeg/FFmpeg

About Author

This article is written by Han Sheng, Technical Lead in Arkmind, Malaysia. He has a passion for Software Design/Architecture related stuff, 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 Github profile.

--

--

Liang Han Sheng
Liang Han Sheng

Written by Liang Han Sheng

Loan Origination Solutions Provider | Full Stack AI Application Development

No responses yet