Terminal 101: 3 Cool Uses for ffmpeg
Posted 11/04/2012 at 9:16pm
| by Cory Bohon
Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!
Last week, we installed and talked about how to use ffmpeg to convert videos to various formats right from the terminal, without any additional software on your Mac, but this week, we’re going to take that a bit further by showing you 3 cool uses for ffmpeg. From grabbing images from the video, to separating the audio track, we’ll show that the ffmpeg tool is extremely useful.
1. Grab a Still Picture from Video
Grabbing a still photo from a video can be done with a screenshot, but if you want the full quality of the video, then ffmpeg can greatly oblige your request.
If you want to extract all of the images form a video with ffmpeg, then use the following command:
ffmpeg -i video.mp4 img%d.jpg
This will create 25 images for every second of the video file. The output images will be in the same directory that you initiate the command from, and will be named image1.jpg, image2.jpg, etc.
You can change the capture frame rate by specifying the number of frames you wish to capture per second of video by using the following command:
ffmpeg -i video.mp4 -r 10 image%d.jpg
Change the “10” above to be the number of images you wish captured for every second of video.

Optionally, you can also tell the ffmpeg program to only extract the images between a certain time frame in the vieo. You’ll use the following command, along with the “-ss” and “-t” flags:
ffmpeg -i video.mp4 -r 15 -ss 00:00:10 -t 00:00:20 img%d.jpg
Here, the command will capture 15 images for every second of video, starting (-ss) on the 10th second and continuing for 20 seconds (-t).
2. Separate the Audio Track
Sometimes you may wish to separate the audio track from a video file without launching any additional tools on your Mac.
We’ll use a tool called ffprobe to figure out what type of audio is used in the video that you wish to separate the audio track from. Type the following command:
ffprobe video.avi
Replace “video.avi” with the name of the video file you’d like to learn more information about. In the text that gets presented to the screen, locate the Metadata section that lists the audio format of the video file (highlighted part in the screenshot). This will list the audio format, and some other specifications.

Once you know the audio format in the video file, the command is simple to extract the audio from the video:
ffmpeg -i video.avi -vn -acodec copy output.aac
Replace “.aac” in “output.aac” with the format that was found during the ffprobe command. When you press enter, the audio file will be outputted to the working directory.
3. Convert Audio Files to Another Format
The ffmpeg tool can do more than just work with video files. You can convert (almost) any audio format into another format by running the following command:
ffmpeg -i input.mp3 output.ogg
Replace “input.mp3” with the original filename and extension that you wish to change the format of; and, replace “output.ogg” with the output filename and extension that the original file will be converted to.
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.