FFMPEG Commands Cheatsheet — Essential Reference
FFmpeg is a powerful, open-source command-line tool for handling multimedia files. It can convert, record, stream, and manipulate audio and video in various formats.
RECOMMENDED
Master FFMPEG with Top Reference Books
Level up your DevOps skills. Find the best guide books and cheatsheet references for your engineering stack.
Commands
| Command | Description | Example |
|---|---|---|
ffmpeg -i input.mp4 output.avi |
Convert a video file from one format to another. | ffmpeg -i video.mp4 output.webm |
ffmpeg -i input.mp4 -vn output.mp3 |
Extract audio from a video file. | ffmpeg -i concert.mp4 -vn concert_audio.mp3 |
ffmpeg -i input.mp4 -ss 00:01:00 -t 00:00:30 -c copy output.mp4 |
Trim a video file (start at 1 minute, for 30 seconds). | ffmpeg -i long_video.mp4 -ss 00:05:00 -t 00:01:30 -c copy trimmed_video.mp4 |
ffmpeg -i input.mp4 -vf scale=640:-1 output.mp4 |
Resize a video to a specific width, maintaining aspect ratio. | ffmpeg -i original.mp4 -vf scale=1280:-1 resized.mp4 |
ffmpeg -i input.mp4 -r 1 -f image2 image-%03d.png |
Extract frames from a video as images (1 frame per second). | ffmpeg -i movie.mp4 -r 0.5 -f image2 frame-%04d.jpg |
ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k output.mp4 |
Compress a video file with H.264 encoding and AAC audio. | ffmpeg -i high_res.mov -c:v libx264 -preset slow -crf 28 -c:a aac -b:a 96k compressed.mp4 |
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex '[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]' -map '[v]' -map '[a]' output.mp4 |
Concatenate (join) two video files. | ffmpeg -i part1.mp4 -i part2.mp4 -filter_complex '[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]' -map '[v]' -map '[a]' combined.mp4 |
ffmpeg -i input.mp4 -vf 'drawtext=text="Hello World":x=10:y=10:fontsize=24:fontcolor=white' output.mp4 |
Add text overlay to a video. | ffmpeg -i video.mp4 -vf 'drawtext=text="My Watermark":x=W-tw-10:y=H-th-10:fontsize=30:fontcolor=yellow' watermarked.mp4 |
Pro Tips
- Use `-c copy` to avoid re-encoding when possible, which is much faster and preserves original quality.
- Experiment with `-preset` (e.g., `ultrafast`, `medium`, `slow`) and `-crf` (Constant Rate Factor, lower is better quality, larger file size) for H.264/H.265 encoding to balance quality and file size.
- Always specify output formats explicitly (e.g., `.mp4`, `.webm`) to ensure FFmpeg uses the correct container and codecs.
- For complex operations, use the `-filter_complex` option to chain multiple filters together.
- Check the FFmpeg documentation (`ffmpeg -h full`) for a comprehensive list of options and filters.
Frequently Asked Questions
What is ffmpeg used for?
FFmpeg is a versatile command-line tool used for converting, streaming, recording, and manipulating audio and video files. It supports a vast array of formats and codecs, making it indispensable for multimedia tasks.
How do I install ffmpeg?
On macOS, use Homebrew: `brew install ffmpeg`. On Linux (Debian/Ubuntu), use APT: `sudo apt update && sudo apt install ffmpeg`. On Windows, download the binaries from the official FFmpeg website and add them to your system's PATH environment variable.