TL;DR
ffmpeg is the go-to tool for audio/video processing. Core syntax: ffmpeg [global options] [input options] -i input [output options] output. Run ffprobe first to inspect the file; -c copy is fastest (no re-encode) but requires a compatible container.
Inspect Files
| Need | Command |
|---|
| Basic media info | ffprobe input.mp4 |
| All stream details | ffprobe -show_streams input.mp4 |
| List encoders / filters | ffmpeg -encoders / ffmpeg -filters |
Transcoding & Format Conversion
| Need | Command |
|---|
| Generic conversion (auto codec) | ffmpeg -i input.flv output.mp4 |
| H.264 + AAC (best compatibility) | ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac output.mp4 |
| Set resolution | ffmpeg -i input.mp4 -vf "scale=1280:720" -c:a copy output.mp4 |
| Extract audio as MP3 | ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3 |
| Extract audio (keep original codec) | ffmpeg -i input.mp4 -vn -c:a copy output.aac |
Trim Clips
| Need | Command |
|---|
| Fast trim (from 2:00, 30s, no re-encode) | ffmpeg -ss 00:02:00 -i input.mp4 -t 30 -c copy output.mp4 |
| Accurate trim (re-encode, frame-aligned) | ffmpeg -i input.mp4 -ss 00:02:00 -t 30 -c:v libx264 -c:a aac output.mp4 |
Note: -ss before -i seeks fast (lands on the nearest keyframe; with -c copy expect up to seconds of error). For frame-accurate cuts, put -ss on the output side and re-encode.
Concat
| Need | Command |
|---|
| Merge via list file (identical streams) | ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4 |
| list.txt format | one file '1.mp4' per line, relative paths, UTF-8 |
Compression & Common Filters
| Need | Command |
|---|
| CRF compression (18–28, lower = better) | ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset faster output.mp4 |
| Convert to GIF | ffmpeg -i input.mp4 -vf "fps=15,scale=480:-1" output.gif |
| Extract frames (1 fps) | ffmpeg -i input.mp4 -r 1 frame_%03d.jpg |
| 2x speed (halve video PTS + atempo audio) | ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" output.mp4 |
| Rotate 90° | ffmpeg -i input.mp4 -vf "transpose=1" output.mp4 |
Troubleshooting
- Output is 0 bytes or exits instantly: run
ffprobe to confirm the input is readable; check disk space; -c copy errors: container/codec mismatch — drop -c copy and re-encode instead;- No audio / no video: select streams explicitly with
-map 0:v, -map 0:a; - Concat glitches: all segments must share identical encode parameters (resolution / codec / fps); normalize first if not.
Sources
- FFmpeg official docs (ffmpeg.org/documentation.html)
- Tech-Service Wiki & FFmpeg practical command tutorials (verified Aug 2026)
最后更新:2026-08-03