How to Get Frames from a Video Using FFmpeg
This page was partly generated by ChatGPT AI.
FFmpeg is a free tool that helps you work with videos and audio files. One cool thing you can do with it is take pictures (frames) out of a video, like an MP4 file. Here’s how you can do that step by step.
MP4 will be used in the following commands, but FFmpeg also supports other video formats like AVI, MOV, MKV and MPEG.
What You Need
Before you start, make sure you have:
-
FFmpeg Installed:
- Download FFmpeg from the official FFmpeg website. Make sure to download the "full" build.
- Follow the setup instructions for your computer.
-
Command Line Access:
- Use the terminal (Linux/macOS) or command prompt (Windows) to run FFmpeg commands.
-
A Video File:
- Have an MP4, AVI, MOV, MKV or MPEG video file ready to use.
Before You Start
Before running any commands, make sure to prepare the following:
Enable File Extensions
-
It’s important to see file extensions like
.mp4or.aviwhen renaming your video file.-
On Windows:
- Open File Explorer.
- Click on the "View" tab at the top.
- Check the box that says "File name extensions."
-
On macOS:
- Open Finder.
- Click on "Finder" in the menu bar and select "Preferences."
- Go to the "Advanced" tab and check the box for "Show all filename extensions."
-
Create an Output Folder
- Create a folder named
output_framesin the directory where the FFmpeg executable is located. This is where your extracted frames will be saved.
Prepare Your Video File
- Place the video file you want to extract frames from in the same directory as the FFmpeg executable.
- Rename the video file to
inputfollowed by its file extension (e.g.,input.mp4,input.avi, etc.). This ensures that the commands below will work without modification.
How to Open FFmpeg
Before you can use FFmpeg, you need to open it using the command line. Here’s how you can do it step by step on Windows and macOS.
On Windows:
-
Open the Command Prompt:
- Press the
Windowskey and theRkey at the same time to open the Run box. - Type
cmdand press Enter. This opens the Command Prompt.
- Press the
-
Go to the FFmpeg Folder:
- You need to tell the computer where FFmpeg is located. Use the
cdcommand to go to the folder where you saved FFmpeg. - For example, if FFmpeg is in a folder called
ffmpeg-2024\binon your desktop, type this:(Replace "YourUsername" with your actual username on the computer.)cd C:\Users\YourUsername\Desktop\ffmpeg-2024\bin
- You need to tell the computer where FFmpeg is located. Use the
-
Check That FFmpeg Works:
- To make sure FFmpeg is working, type this command:
ffmpeg -version - If it’s working, you’ll see information about FFmpeg appear on the screen.
- To make sure FFmpeg is working, type this command:
On macOS:
-
Open the Terminal:
- Press
CommandandSpaceat the same time to open Spotlight Search. - Type
Terminaland press Enter to open it.
- Press
-
Go to the FFmpeg Folder:
- Use the
cdcommand to go to the folder where you saved FFmpeg. - For example, if FFmpeg is in your
Downloadsfolder, type this:cd ~/Downloads/ffmpeg-2024/bin
- Use the
-
Check That FFmpeg Works:
- To make sure FFmpeg is ready, type this command:
./ffmpeg -version - If FFmpeg is working, you’ll see details about it appear on the screen.
- To make sure FFmpeg is ready, type this command:
How to Save All Frames
To save all frames from a video, use this command:
ffmpeg -i input.mp4 output_frames/%d.png
What This Means:
-i input.mp4: This is your input video file. It should be in the same directory as the FFmpeg executable. Make sure to changeinput.mp4to the correct file name and extension.output_frames/frame_%04d.png: This is how the frames will be saved:output_frames/: Saves all frames in a folder calledoutput_frames.%d.png: The frames will be named using numbers like1.png,2.png, and so on, keeping them in order.
Save Frames at Certain Times
If you don’t want all the frames, you can save one frame every second (or other intervals). Use this command:
ffmpeg -i input.mp4 -vf "fps=1" output_frames/%d.png
What This Means:
-i input.mp4: This is your input video file. It should be in the same directory as the FFmpeg executable. Make sure to changeinput.mp4to the correct file name and extension.-vf "fps=1": This saves one frame per second. Change the1to another number if you want frames more or less often (e.g.,fps=0.5saves one frame every two seconds, andfps=2saves two frames every second).output_frames/%d.png: Saves the frames in a folder namedoutput_frameswith names like1.png,2.png, and so on.
Change the Size and Quality of Frames
You can also adjust the size and quality of the frames you save. Here’s how:
ffmpeg -i input.mp4 -vf "scale=1280:720" -q:v 2 output_frames/%d.png
What This Means:
-i input.mp4: This is your input video file. It should be in the same directory as the FFmpeg executable. Make sure to changeinput.mp4to the correct file name and extension.-vf "scale=1280:720": Changes the frame size to 1280x720 pixels.-q:v 2: Sets the picture quality (1 is best, higher numbers mean lower quality).output_frames/%d.png: Saves the frames in a folder namedoutput_frameswith names like1.png,2.png, and so on.
Tips for Saving Frames
-
Save Space:
- If the video is long, you can save frames at intervals instead of saving every frame. This is especially useful for when using them as FMA animation frames in FancyMenu.
-
Learn More:
- Run
ffmpeg -hin your terminal to see all the cool things FFmpeg can do.
- Run
Now you’re ready to use FFmpeg to save frames from your video!