Overview
FFmpeg is one of the most powerful open-source tools for audio and video processing. It powers many video platforms and conversion services. This cheat sheet collects the most useful FFmpeg commands for common tasks.
Install FFmpeg
| Platform | Install method |
|---|---|
| Windows | Download from the FFmpeg official download page, extract, and add bin to PATH |
| macOS | brew install ffmpeg |
| Ubuntu / Debian | sudo apt update && sudo apt install ffmpeg |
| CentOS / RHEL | sudo yum install ffmpeg after enabling EPEL |
Check Media Information
ffprobe -v error -show_format -show_streams input.mp4
This shows codec, resolution, frame rate, bitrate, audio codec, sample rate, and more.
Convert Formats
| Conversion | Command |
|---|---|
| MOV to MP4 | ffmpeg -i input.mov -c:v libx264 -crf 23 output.mp4 |
| MKV to MP4 without re-encoding | ffmpeg -i input.mkv -c copy output.mp4 |
| MP4 to GIF | ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1" output.gif |
| Extract audio to MP3 | ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3 |
Compress Video
Use CRF for Quality Control
ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset medium -c:a aac -b:a 96k output.mp4
CRF ranges from 0 to 51. Lower values mean higher quality and larger files.
- CRF 18–23: Visually lossless, good for archiving
- CRF 24–28: Balanced quality and size, good for web sharing
- CRF 29–35: High compression, good for mobile previews
Use Target Bitrate
ffmpeg -i input.mp4 -b:v 1500k -b:a 128k output.mp4
Trim Video
Lossless Trim
ffmpeg -ss 00:00:10 -to 00:01:00 -i input.mp4 -c copy output.mp4
This cuts from 10 seconds to 1 minute without re-encoding.
Resize Video
ffmpeg -i input.mp4 -vf "scale=1280:-1" output.mp4
-1 keeps the aspect ratio automatically.
Audio Commands
# Extract audio as MP3
ffmpeg -i input.mp4 -vn -c:a libmp3lame output.mp3
# Increase volume to 1.5x
ffmpeg -i input.mp3 -af "volume=1.5" output.mp3
# Merge two audio files
ffmpeg -i a.mp3 -i b.mp3 -filter_complex "amix=inputs=2:duration=longest" output.mp3
Merge Videos
echo "file 'part1.mp4'" > list.txt
echo "file 'part2.mp4'" >> list.txt
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
Add a Watermark
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4
Use overlay=W-w-10:H-h-10 for the bottom-right corner.
Troubleshooting
| Problem | Cause | Solution |
|---|---|---|
| Slow encoding | CPU software encoding | Add -c:v h264_nvenc for NVIDIA hardware encoding |
| No audio in output | Audio stream dropped | Add -c:a aac |
| Audio and video out of sync after trimming | -ss placed after -i | Place -ss before -i |
| Merge fails | Different codecs or parameters | Re-encode all clips with the same settings first |
