Have you ever wondered what's inside a video file? Or maybe you need to convert a video to a different format for better compatibility or smaller file size. The command line tools FFmpeg and ffprobe are your secret weapons for these tasks. We'll walk you through how to install them and then use them to inspect and transcode a video.
Installing FFmpeg with Homebrew
If you're on a macOS, the easiest way to install FFmpeg is with Homebrew, the "missing package manager for macOS."
If you don't have Homebrew installed, you'll need to do that first by following the instructions on their official website. Once Homebrew is ready, installing FFmpeg is a breeze. Open your Terminal and type this command:
brew install ffmpeg
After the installation is complete, it's a good idea to confirm that everything is working. You can do this by checking the version of FFmpeg that was installed:
ffmpeg -version
If you see the version information displayed, you're all set!
Checking a Video's Codec with ffprobe
Before you change a video, it's smart to know what you're starting with. That's where ffprobe comes in. It's a powerful command-line tool that's part of the FFmpeg suite. It can gather a ton of information about your multimedia files, including the video and audio codecs.
To find out the codec of a video file named input.mp4
, simply run this command in your Terminal:
ffprobe ./input.mp4
This will print out a detailed report about the video, including its codec, resolution, framerate, and more. Look for the "Stream #0:0(eng): Video:" section to find the codec information.
Transcoding to H.264 with ffmpeg
Now for the fun part: changing the video! Transcoding is the process of converting a video file from one codec or format to another. The H.264 codec is a widely used and highly compatible standard, making it a great choice for web videos, mobile devices, and more.
The ffmpeg
command has many options, and it can seem a bit intimidating at first. Let's break down a common command used to transcode a video to H.264:
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4
Let's dissect this command:
-
-i input.mp4
: This is the input file. It tellsffmpeg
which video to process. -
-c:v libx264
: This is the video codec. We're tellingffmpeg
to use thelibx264
encoder, which is the H.264 implementation. -
-crf 23
: This stands for Constant Rate Factor. It's a quality setting for the video. A lower number means higher quality and a larger file size, while a higher number means lower quality and a smaller file size. A value of23
is a good starting point for a balanced output. -
-preset medium
: This option controls the encoding speed. Faster presets (likeultrafast
) result in lower quality and larger file sizes, while slower presets (likeveryslow
) result in higher quality and smaller file sizes.medium
is a great balance. -
-c:a aac
: This is the audio codec. We're specifying the AAC (Advanced Audio Coding) codec, which is a common and efficient choice. -
-b:a 128k
: This sets the audio bitrate to128k
, which is a good quality for most purposes. -
output.mp4
: This is the output file name.ffmpeg
will save the transcoded video to this file.
After running this command, you'll have a new video file named output.mp4
that's ready for its new purpose!
Top comments (0)