FFmpeg Commands Worth Keeping Nearby
FFmpeg has hundreds of options, but most of my day-to-day jobs start the same way: name an input with -i, choose what should happen, and name the output.
ffmpeg -i input.avi output.mp4
FFmpeg infers the output container from .mp4. It may also choose codecs for you, which is convenient until you need a specific balance of compatibility, quality, and file size.
Install it from a maintained source
On macOS, Homebrew is the simplest route if you already use it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Read Homebrew’s current installation instructions before running a downloaded script. Then install FFmpeg:
brew install ffmpeg
On Windows, use the downloads linked by the official FFmpeg project or a current package manager. The old Zeranoe builds page referenced by earlier guides is no longer the source I would recommend.
Linux packages are normally available from the distribution repository. This Linux installation guide covers several distributions, although package names and versions can change.
Confirm the installation with ffmpeg -version.
Inspect before converting
Run FFmpeg with only an input to see its streams, codecs, dimensions, frame rate, and audio details:
ffmpeg -i input.mp4
That output often explains a compatibility problem before another random conversion does.
Convert or compress a video
A more deliberate MP4 conversion uses H.264 video and AAC audio:
ffmpeg -i input.avi -c:v libx264 -crf 23 -c:a aac -b:a 192k output.mp4
With libx264, a lower CRF usually means higher quality and a larger file. Start around 23 and adjust after looking at the actual output. Presets trade encoding time for compression efficiency; they do not simply mean visual quality.
If the streams are already compatible with the new container, copy them without re-encoding:
ffmpeg -i input.mov -c copy output.mp4
That is much faster and avoids generation loss, but it only works when the target container supports the existing codecs.
Trim a clip
Start at 30 seconds and create a 10-second clip:
ffmpeg -ss 00:00:30 -i input.mp4 -t 10 -c copy clip.mp4
Stream copying is fast but may cut at a nearby keyframe rather than the exact frame. Re-encode when precise cuts matter.
Extract the audio
The original command in this article converted audio to MP3:
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
A clearer modern spelling is:
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -b:a 192k sound.mp3
-vn removes video, -ar sets the sample rate, -ac sets two audio channels, and -b:a sets the audio bitrate.
Add a filter
Filters can scale, crop, blur, overlay, and transform streams. For example:
ffmpeg -i input.mp4 -vf "scale=1280:-2" output.mp4
The original article also included this filter expression for random selection, blur, and interleaving:
select='if(gt(random(0), 0.2), 1, 2)':n=2 [tmp], boxblur=2:2, [tmp] interleave
Complex filter graphs are sensitive to labels, quoting, and input streams. Treat that expression as a fragment to adapt, not a complete command to paste unchanged.
Process a directory
A shell loop can convert every AVI file in the current directory:
for file in *.avi; do
ffmpeg -i "$file" "${file%.avi}.mp4"
done
Try the command on one file before starting the loop, and write outputs to a separate directory when overwriting would be costly.
FFmpeg’s command line looks hostile because it exposes the details. That is also why it remains useful. Keep a few commands that match your real files, inspect the streams, and change one option at a time.