What Is FFmpeg and Why Should You Learn It?
FFmpeg is the Swiss Army knife of multimedia. It is a free, open-source command-line tool that can convert, compress, trim, merge, split, and manipulate virtually any audio or video format in existence. Every major tech company uses it -- YouTube, Netflix, Spotify, VLC, OBS, and thousands of other applications are built on FFmpeg's libraries.
Learning FFmpeg gives you complete control over your media files. No subscription fees, no upload limits, no waiting for cloud processing. Everything happens on your machine, at full speed, with pixel-perfect control over every parameter. A single FFmpeg command can replace an entire desktop application.
The learning curve can feel steep at first, but the core concepts are simple. This guide will take you from zero to confidently converting, compressing, and processing media files with FFmpeg.

Installing FFmpeg
macOS
The easiest method is Homebrew:
# Install Homebrew if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install FFmpeg
brew install ffmpeg
Windows
- Download the latest build from ffmpeg.org
- Extract the ZIP to
C:\ffmpeg - Add
C:\ffmpeg\binto your system PATH:- Search "Environment Variables" in Windows
- Edit the Path variable under System Variables
- Add
C:\ffmpeg\bin
- Open a new Command Prompt and verify:
ffmpeg -version
Linux (Ubuntu/Debian)
sudo apt update
sudo apt install ffmpeg
Linux (Fedora/RHEL)
sudo dnf install ffmpeg
Verify Installation
After installation, run:
ffmpeg -version
You should see version information and a list of enabled features. If you see "command not found," the installation did not complete correctly or FFmpeg is not in your PATH.
Understanding FFmpeg Command Structure
Every FFmpeg command follows this basic pattern:
ffmpeg [global options] -i input_file [output options] output_file
The key components:
-i input_file-- Specifies the input file (you can have multiple inputs)- Output options -- Codec settings, filters, quality parameters
output_file-- The output filename (FFmpeg infers the format from the extension)
Here is the simplest possible conversion:
ffmpeg -i input.mov output.mp4
FFmpeg automatically selects appropriate codecs based on the output format. But you will almost always want to specify settings explicitly for predictable results.
Essential Conversions
Convert Video Formats
The most common task -- converting between video container formats:
# MOV to MP4 (re-encode with H.264)
ffmpeg -i input.mov -c:v libx264 -c:a aac output.mp4
# MKV to MP4 (stream copy -- no re-encoding, instant)
ffmpeg -i input.mkv -c copy output.mp4
# AVI to MP4
ffmpeg -i input.avi -c:v libx264 -c:a aac output.mp4
# WebM to MP4
ffmpeg -i input.webm -c:v libx264 -c:a aac output.mp4
The difference between -c copy (stream copy) and -c:v libx264 (re-encode) is critical:
| Method | Speed | Quality | File Size Change | When to Use |
|---|---|---|---|---|
-c copy | Near-instant | Identical to original | Minimal | Changing container only (MKV to MP4) |
-c:v libx264 | Slow (CPU-bound) | Depends on settings | Adjustable | Changing codec, compressing, resizing |
-c:v h264_nvenc | Fast (GPU) | Good (slightly lower than libx264) | Adjustable | Speed-critical encoding with NVIDIA GPU |
-c:v h264_videotoolbox | Fast (GPU) | Good | Adjustable | Speed-critical encoding on Apple Silicon |
For detailed format comparisons, the video codecs explained guide covers H.264, H.265, VP9, and AV1 in depth.
Convert Audio Formats
# WAV to MP3 (standard quality)
ffmpeg -i input.wav -c:a libmp3lame -b:a 192k output.mp3
# FLAC to MP3
ffmpeg -i input.flac -c:a libmp3lame -b:a 320k output.mp3
# MP4/MOV to MP3 (extract audio)
ffmpeg -i video.mp4 -vn -c:a libmp3lame -b:a 192k output.mp3
# WAV to AAC
ffmpeg -i input.wav -c:a aac -b:a 256k output.m4a
# MP3 to OGG Vorbis
ffmpeg -i input.mp3 -c:a libvorbis -q:a 5 output.ogg
The -vn flag means "no video" -- essential when extracting audio from video files. For more audio extraction techniques, see how to extract audio from video.
Controlling Quality: CRF, Bitrate, and Presets
CRF (Constant Rate Factor) -- The Recommended Method
CRF lets you set a target quality level. FFmpeg adjusts the bitrate automatically to maintain consistent quality throughout the video:
ffmpeg -i input.mov -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4
CRF values for H.264 (libx264):
| CRF Value | Quality | Use Case | Approximate File Size (1 min 1080p) |
|---|---|---|---|
| 0 | Lossless | Archiving (huge files) | 1-3 GB |
| 15-17 | Visually lossless | Master copies, editing | 200-400 MB |
| 18-20 | Excellent | High-quality delivery | 80-200 MB |
| 21-23 | Good (default) | General use, streaming | 40-100 MB |
| 24-28 | Acceptable | Web, social media, email | 15-50 MB |
| 29-35 | Low | Previews, thumbnails | 5-20 MB |
| 51 | Worst possible | Never use this | <5 MB |
Presets -- Speed vs Compression Tradeoff
The -preset flag controls encoding speed. Slower presets produce smaller files at the same quality:
# Fastest encoding (largest file)
ffmpeg -i input.mov -c:v libx264 -crf 23 -preset ultrafast -c:a aac output.mp4
# Best compression (slowest encoding)
ffmpeg -i input.mov -c:v libx264 -crf 23 -preset veryslow -c:a aac output.mp4
Available presets (fastest to slowest): ultrafast, superfast, veryfast, faster, fast, medium (default), slow, slower, veryslow.
For most use cases, medium or slow is the sweet spot. The difference between slow and veryslow is typically only 2-5% file size reduction for 2-4x longer encoding time.
Pro Tip: The CRF value has a much bigger impact on file size than the preset. Changing CRF by 6 roughly doubles or halves the file size. Changing from medium to slow preset only saves about 5-10% at the same CRF. Adjust CRF first, then fine-tune with the preset.
For a complete understanding of bitrate and quality tradeoffs, the video bitrate explained guide goes much deeper.

Common Operations
Resize / Scale Video
# Scale to 1080p (maintain aspect ratio)
ffmpeg -i input.mov -vf "scale=1920:1080" -c:v libx264 -crf 23 -c:a aac output.mp4
# Scale to 720p (maintain aspect ratio, auto-calculate height)
ffmpeg -i input.mov -vf "scale=1280:-2" -c:v libx264 -crf 23 -c:a aac output.mp4
# Scale to 50% of original size
ffmpeg -i input.mov -vf "scale=iw/2:ih/2" -c:v libx264 -crf 23 -c:a aac output.mp4
The -2 value means "auto-calculate this dimension while keeping it divisible by 2" (required for H.264).
Trim / Cut Video
# Cut from 00:01:30 to 00:03:45
ffmpeg -i input.mp4 -ss 00:01:30 -to 00:03:45 -c copy trimmed.mp4
# Cut first 30 seconds (with re-encoding for frame accuracy)
ffmpeg -ss 00:00:00 -i input.mp4 -t 30 -c:v libx264 -c:a aac first_30s.mp4
# Remove first 10 seconds
ffmpeg -ss 00:00:10 -i input.mp4 -c copy from_10s.mp4
Using -c copy is fast but may have keyframe alignment issues (cut might start a few frames early). Re-encoding with -c:v libx264 gives precise cuts. For GUI-based trimming, use the video trimmer.
Extract Audio from Video
# Extract to MP3
ffmpeg -i video.mp4 -vn -c:a libmp3lame -b:a 192k audio.mp3
# Extract to WAV (uncompressed)
ffmpeg -i video.mp4 -vn -c:a pcm_s16le audio.wav
# Extract to AAC (copy without re-encoding, if source is AAC)
ffmpeg -i video.mp4 -vn -c:a copy audio.aac
The extract audio tool provides a drag-and-drop interface for this task.
Create GIF from Video
# Basic GIF (low quality, large file)
ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1" output.gif
# High-quality GIF with optimized palette
ffmpeg -i input.mp4 -vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
The palette optimization method produces significantly better color reproduction. The GIF maker handles this automatically.
Add Subtitles
# Burn subtitles into video (hardcode)
ffmpeg -i input.mp4 -vf "subtitles=subs.srt" -c:v libx264 -c:a copy output.mp4
# Add subtitles as a separate track (softcode)
ffmpeg -i input.mp4 -i subs.srt -c copy -c:s mov_text output.mp4
Change Video Speed
# 2x speed (video and audio)
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4
# 0.5x speed (slow motion)
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" output.mp4
Working with Multiple Files
Concatenate / Merge Videos
Create a text file listing the videos to merge:
# filelist.txt
file 'part1.mp4'
file 'part2.mp4'
file 'part3.mp4'
Then merge:
ffmpeg -f concat -safe 0 -i filelist.txt -c copy merged.mp4
This only works if all files have the same codec, resolution, and frame rate. If they differ, re-encode:
ffmpeg -f concat -safe 0 -i filelist.txt -c:v libx264 -crf 23 -c:a aac merged.mp4
Batch Convert
# Convert all MOV files to MP4 (macOS/Linux)
for f in *.mov; do
ffmpeg -i "$f" -c:v libx264 -crf 23 -preset medium -c:a aac "${f%.mov}.mp4"
done
# Convert all WAV files to MP3
for f in *.wav; do
ffmpeg -i "$f" -c:a libmp3lame -b:a 192k "${f%.wav}.mp3"
done
For more batch processing techniques, the batch processing guide covers advanced workflows.
On Windows (PowerShell):
Get-ChildItem *.mov | ForEach-Object {
ffmpeg -i $_.FullName -c:v libx264 -crf 23 -preset medium -c:a aac ($_.BaseName + ".mp4")
}
Advanced: Filters and Effects
FFmpeg's filter system is incredibly powerful. Here are the most useful filters:
Video Filters (-vf)
# Rotate 90 degrees clockwise
ffmpeg -i input.mp4 -vf "transpose=1" -c:a copy rotated.mp4
# Crop to center 1080x1080 square
ffmpeg -i input.mp4 -vf "crop=1080:1080" -c:a copy cropped.mp4
# Add text overlay
ffmpeg -i input.mp4 -vf "drawtext=text='Hello World':fontsize=48:fontcolor=white:x=50:y=50" output.mp4
# Adjust brightness and contrast
ffmpeg -i input.mp4 -vf "eq=brightness=0.1:contrast=1.2" output.mp4
# Denoise
ffmpeg -i input.mp4 -vf "nlmeans=s=3:p=7:r=15" denoised.mp4
Audio Filters (-af)
# Normalize audio volume
ffmpeg -i input.mp4 -af "loudnorm=I=-16:TP=-1.5:LRA=11" normalized.mp4
# Fade audio in/out (5-second fade in, 5-second fade out)
ffmpeg -i input.mp4 -af "afade=t=in:st=0:d=5,afade=t=out:st=55:d=5" faded.mp4
# Remove silence
ffmpeg -i input.mp3 -af "silenceremove=start_periods=1:start_silence=0.5:start_threshold=-50dB" no_silence.mp3

Quick Reference: Most-Used Commands
| Task | Command |
|---|---|
| Convert MOV to MP4 | ffmpeg -i input.mov -c:v libx264 -crf 23 -c:a aac output.mp4 |
| Compress video | ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset slow output.mp4 |
| Extract audio | ffmpeg -i video.mp4 -vn -c:a libmp3lame -b:a 192k audio.mp3 |
| Trim video | ffmpeg -i input.mp4 -ss 00:01:00 -to 00:02:00 -c copy trim.mp4 |
| Resize to 720p | ffmpeg -i input.mp4 -vf "scale=1280:-2" -c:v libx264 output.mp4 |
| Create GIF | ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1" output.gif |
| Remove audio | ffmpeg -i input.mp4 -an -c:v copy silent.mp4 |
| Get file info | ffprobe -v quiet -show_format -show_streams input.mp4 |
| Screenshot at timestamp | ffmpeg -i input.mp4 -ss 00:00:30 -frames:v 1 screenshot.jpg |
| Merge videos | ffmpeg -f concat -safe 0 -i filelist.txt -c copy merged.mp4 |
Common Errors and Solutions
"Unknown encoder 'libx264'"
FFmpeg was compiled without H.264 support. Reinstall with full codec support:
# macOS
brew install ffmpeg
# Ubuntu
sudo apt install ffmpeg libavcodec-extra
"Invalid data found when processing input"
The input file is corrupted or the format is not recognized. Try:
ffmpeg -err_detect ignore_err -i input.mp4 -c:v libx264 -c:a aac output.mp4
For more on repairing corrupted files, see the corrupted video repair guide.
"height not divisible by 2"
H.264 requires even dimensions. Use -2 in your scale filter:
ffmpeg -i input.mp4 -vf "scale=1280:-2" output.mp4
Encoding is extremely slow
Use hardware acceleration or a faster preset:
# Faster preset (larger file but much faster)
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset fast -c:a aac output.mp4
# GPU acceleration (NVIDIA)
ffmpeg -i input.mp4 -c:v h264_nvenc -cq 23 -c:a aac output.mp4
When to Use FFmpeg vs Online Tools
FFmpeg is the better choice when you:
- Need to process files larger than online limits allow
- Want complete control over encoding parameters
- Are batch processing many files
- Need privacy (files never leave your machine)
- Work offline
Online tools like the MP4 converter or video compressor are better when you:
- Need a quick, one-off conversion
- Are not comfortable with command lines
- Are on a device where you cannot install software
- Want a visual interface with previews
Pro Tip: You do not have to choose one or the other. Many professionals use FFmpeg for heavy lifting and online tools for quick conversions. Having both in your toolkit makes you more productive.
Related Resources
- Video Codecs Explained -- Understanding H.264, H.265, VP9, and AV1
- How to Convert MOV to MP4 -- Detailed MOV conversion guide
- How to Convert MKV to MP4 -- MKV to MP4 conversion
- Frame Rate Guide: 24, 30, 60 FPS -- Understanding frame rates
- How to Convert Large Files Online -- Handling oversized files
Summary
FFmpeg is the most powerful media conversion tool available, and its basic usage is surprisingly straightforward. The core pattern -- ffmpeg -i input [options] output -- covers 90% of what you need. Start with simple conversions, learn the CRF quality system, and gradually explore filters and batch processing as you grow more comfortable. The investment in learning FFmpeg pays off every time you need to convert, compress, trim, or manipulate a media file without uploading it to a third-party service.



