FFmpeg is a single command-line tool that can convert, compress, trim, merge, subtitle, watermark, and even batch-process videos. This guide gives you copy-pasteable recipes and quick explanations so you can automate your day-to-day work fast.
What is FFmpeg?
FFmpeg is a free, open-source toolkit that works with nearly any audio/video format. If you handle videos—even casually—FFmpeg lets you automate those repetitive chores into single commands or small scripts.
Install & Verify
macOS: brew install ffmpeg
(with Homebrew).
Ubuntu/Debian: sudo apt update && sudo apt install ffmpeg
.
Windows: Use a prebuilt zip (add its bin folder to PATH).
ffmpeg -version
ffprobe -v error -show_format -show_streams -i input.mp4
Tip: Use ffprobe
to inspect codecs, durations, and bitrates before deciding your automation strategy.
Make Web-Ready MP4 (“Fast Start”)
ffmpeg -i input.mov -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k \
-movflags +faststart -pix_fmt yuv420p output.mp4
Compress/Resize for Sharing
ffmpeg -i input.mp4 -vf "scale=-2:1080" -c:v libx264 -crf 24 -preset slow \
-c:a aac -b:a 128k -movflags +faststart -pix_fmt yuv420p output_1080p.mp4
Trim & Clip (Frame-Accurate)
ffmpeg -ss 00:00:05 -to 00:00:12 -i input.mp4 -c:v libx264 -crf 20 -preset medium \
-c:a aac -b:a 128k clip.mp4
Merge/Concatenate Clips
file 'part1.mp4'
file 'part2.mp4'
file 'part3.mp4'
ffmpeg -f concat -safe 0 -i list.txt -c copy merged.mp4
Extract or Replace Audio
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 audio.mp3
Thumbnails & GIFs
ffmpeg -ss 00:00:10 -i input.mp4 -vframes 1 -q:v 2 thumb.jpg
Watermarks & Text
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=10:10" -c:a copy marked.mp4
Add Subtitles
ffmpeg -i input.mp4 -i subs.srt -c:v copy -c:a copy -c:s mov_text video_with_subs.mp4
Speed Up / Slow Down
ffmpeg -i input.mp4 -filter_complex "setpts=0.5*PTS;atempo=2.0" fast.mp4
Batch Processing
#!/usr/bin/env bash
for f in *.mov; do
base="${f%.*}"
ffmpeg -y -i "$f" -vf "scale=-2:1080" -c:v libx264 -crf 23 -preset medium \
-c:a aac -b:a 128k -movflags +faststart -pix_fmt yuv420p "${base}.mp4"
done
Cheat-Sheet
Task | Command |
---|---|
Convert | ffmpeg -i in.mov -c:v libx264 -c:a aac out.mp4 |
Compress | -vf "scale=-2:1080" -crf 24 -preset slow |
Trim | -ss 00:00:05 -to 00:00:12 -c:v libx264 |
Extract Audio | -vn -c:a libmp3lame -q:a 2 out.mp3 |
No comments:
Post a Comment