FFmpeg has a reputation for being intimidating. The command syntax is unusual, there are thousands of options, and error messages aren't always helpful. But the truth is, most of what people actually need to do with FFmpeg comes down to about a dozen commands.
This guide focuses on practical, real-world usage. Every command here is tested and ready to copy-paste.
What you'll learn
- How FFmpeg commands are structured
- Converting between video formats
- Extracting and converting audio
- Compressing video while maintaining quality
- Cutting, trimming, and merging clips
- Changing resolution and frame rate
- Adding subtitles
- Creating video from images
How FFmpeg Commands Are Structured
Every FFmpeg command follows this pattern:
ffmpeg [input options] -i input_file [output options] output_file
The position of options matters. Options placed before -i apply to the input. Options placed after -i apply to the output. This is different from most CLI tools and trips up a lot of newcomers.
Some examples:
# Simplest possible command — just convert the format
ffmpeg -i input.mp4 output.avi
# Input option: seek to a specific position before reading
ffmpeg -ss 00:01:00 -i input.mp4 output_trimmed.mp4
# Output option: set the bitrate of the output
ffmpeg -i input.mp4 -b:v 1M output.mp4
Quick reference for common option prefixes:
-c:v= video codec-c:a= audio codec-b:v= video bitrate-b:a= audio bitrate-r= frame rate-s= resolution (size)-ss= seek start position-t= duration in seconds-to= end timestamp
Converting Video Formats
Convert MP4 to AVI (or any other format)
ffmpeg -i input.mp4 output.avi
FFmpeg reads the file extensions and automatically picks appropriate codecs. For simple format changes, this is all you need.
Change the container without re-encoding
ffmpeg -i input.mp4 -c copy output.mkv
-c copy tells FFmpeg to copy all streams as-is, without re-encoding. This is instant and lossless — it just changes the wrapper format (MP4 to MKV, for example).
Convert iPhone MOV to MP4
ffmpeg -i input.mov -c:v libx264 -c:a aac output.mp4
A common use case when sharing iPhone videos with people who aren't on Apple devices.
Extracting and Converting Audio
Extract audio from a video file
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3
What each option does:
-vn= no video (skip the video stream)-c:a libmp3lame= encode audio as MP3-q:a 2= audio quality (0 is best, 9 is worst; 2 is excellent quality)
For higher quality, use AAC instead:
ffmpeg -i input.mp4 -vn -c:a aac -b:a 192k output.m4a
Convert between audio formats
# WAV to MP3
ffmpeg -i input.wav -c:a libmp3lame -b:a 320k output.mp3
# MP3 to FLAC (lossless)
ffmpeg -i input.mp3 -c:a flac output.flac
# Reduce audio bitrate (smaller file)
ffmpeg -i input.mp3 -b:a 128k output_compressed.mp3
Compressing Video
Reducing file size while preserving quality is probably the most common FFmpeg use case.
Compress with H.265 (HEVC)
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -c:a aac output.mp4
The -crf value controls the quality-compression tradeoff:
| CRF range | Quality | File size |
|---|---|---|
| Below 18 | Nearly lossless | Large |
| 18–23 | High quality (typical use) | Medium |
| 24–28 | Acceptable (web delivery) | Small |
| Above 28 | Visible degradation | Very small |
H.265 delivers roughly the same quality as H.264 at half the file size. The tradeoff is longer encoding time.
Compress with H.264
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4
H.264 has much broader device compatibility than H.265. The -preset option lets you trade speed for file size:
| Preset | Encoding speed | File size |
|---|---|---|
| ultrafast | Very fast | Largest |
| fast | Fast | Larger |
| medium | Balanced (default) | Medium |
| slow | Slow | Smaller |
| veryslow | Slowest | Smallest |
# Speed priority (processing lots of videos quickly)
ffmpeg -i input.mp4 -c:v libx264 -preset fast -crf 23 output.mp4
# Quality priority (archival)
ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 18 output.mp4
Trimming and Cutting Video
Cut a specific time range
ffmpeg -ss 00:01:30 -to 00:05:00 -i input.mp4 -c copy output_clip.mp4
-ss 00:01:30= start at 1 minute 30 seconds-to 00:05:00= end at 5 minutes 0 seconds-c copy= no re-encoding (instant, lossless)
Important: Placing -ss before -i uses input seeking, which jumps directly to the position without decoding everything before it. This makes trimming nearly instant even for very long videos.
To specify duration instead of an end time, use -t:
# Extract 60 seconds starting at 1:30
ffmpeg -ss 00:01:30 -t 60 -i input.mp4 -c copy output_clip.mp4
Merging Multiple Videos
Concatenate videos using a file list
First, create a text file listing all the videos to join (filelist.txt):
file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'
Then run the merge command:
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output_merged.mp4
-f concat= use the concat input format-safe 0= allow relative and absolute paths in the file list-c copy= no re-encoding
This is the fastest method and works perfectly when all videos share the same codec and resolution.
Merge videos with different formats or resolutions
When combining videos with different properties, re-encoding is required:
ffmpeg -i video1.mp4 -i video2.mp4 \
-filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output_merged.mp4
Changing Resolution and Frame Rate
Resize video
# Resize to 1920x1080
ffmpeg -i input.mp4 -s 1920x1080 output.mp4
# Resize width to 1280px, maintain aspect ratio
ffmpeg -i input.mp4 -vf scale=1280:-2 output.mp4
# Resize height to 720px, maintain aspect ratio
ffmpeg -i input.mp4 -vf scale=-2:720 output.mp4
Using -2 for one dimension tells FFmpeg to calculate that dimension automatically to preserve the original aspect ratio. (-2 ensures the width is rounded to the nearest even number, which is required by most codecs)
Change frame rate
# Convert to 30fps
ffmpeg -i input.mp4 -r 30 output.mp4
# Convert to 60fps
ffmpeg -i input.mp4 -r 60 output.mp4
Reducing the frame rate (e.g., 60fps to 30fps) significantly reduces file size with minimal perceived quality loss for most content.
Adding Subtitles
Soft subtitles (stored separately, togglable)
ffmpeg -i input.mp4 -i subtitle.srt -c:v copy -c:a copy -c:s mov_text output.mp4
The subtitle data is stored inside the MP4 file but not burned into the video. Players that support it let users turn subtitles on or off.
Hard subtitles (burned into the video)
ffmpeg -i input.mp4 -vf subtitles=subtitle.srt output.mp4
This permanently renders the subtitles onto the video frames. They'll always be visible regardless of player, but can't be removed later.
Creating Video from Images
Make a video from a numbered image sequence
# From image001.png, image002.png, image003.png...
ffmpeg -framerate 24 -i image%03d.png -c:v libx264 -pix_fmt yuv420p output.mp4
-framerate 24= 24 frames per secondimage%03d.png= 3-digit zero-padded sequence (001, 002, 003...)-pix_fmt yuv420p= compatibility mode for most players
Useful for time-lapse videos and animated sequences.
Loop a single image into a video
# Turn a single image into a 10-second video
ffmpeg -loop 1 -i input.jpg -t 10 -c:v libx264 -pix_fmt yuv420p output.mp4
Common Questions
How do I adjust audio volume?
# Double the volume
ffmpeg -i input.mp4 -af volume=2.0 output.mp4
# Halve the volume
ffmpeg -i input.mp4 -af volume=0.5 output.mp4
How do I rotate a video?
# Rotate 90 degrees clockwise
ffmpeg -i input.mp4 -vf transpose=1 output.mp4
# Rotate 180 degrees (use hflip and vflip combined)
ffmpeg -i input.mp4 -vf "hflip,vflip" output.mp4
How do I change playback speed?
# 2x speed (both video and audio)
ffmpeg -i input.mp4 -vf setpts=0.5*PTS -af atempo=2.0 output.mp4
# 0.5x speed (slow motion)
ffmpeg -i input.mp4 -vf setpts=2.0*PTS -af atempo=0.5 output.mp4
How do I inspect a file's metadata?
ffprobe -v quiet -print_format json -show_format -show_streams input.mp4
How do I force overwrite an existing output file?
ffmpeg -y -i input.mp4 output.mp4
The -y flag skips the "file already exists, overwrite?" prompt.
Summary
Here's a quick reference table for the most common operations:
| Task | Key options |
|---|---|
| Format conversion | ffmpeg -i input.mp4 output.avi |
| Audio extraction | -vn -c:a libmp3lame |
| Video compression | -c:v libx265 -crf 28 |
| Trim a clip | -ss start -to end -c copy |
| Merge clips | -f concat -i filelist.txt |
| Resize | -vf scale=1280:-2 |
| Burn subtitles | -vf subtitles=subtitle.srt |
The best way to learn FFmpeg is to start with one concrete task — say, extracting audio from a video — and then gradually explore from there. The official FFmpeg documentation is thorough, and ffmpeg -help full dumps everything to the terminal if you need it.