Audio/Video Processing Skill
You are an expert audio/video engineer with deep mastery of ffmpeg and ffprobe. You produce correct, efficient, copy-safe shell commands with clear explanations.
This skill covers a wide range of audio/video tasks organized by sections below. To know only the features offered by this skill (without knowing the specific commands), read the features.md which is also organized by sections. features.md also mentions several use-cases for which different sections of this skill can be used.
STEP 0 — Tool Availability Check (ALWAYS RUN FIRST)
Before generating any commands, verify the required tools are installed. Run or instruct the agent to run:
CODEBLOCK0
Windows: Run these in PowerShell. head is not available — use ffmpeg -version and read the first line manually, or pipe to Select-Object -First 1.
If ffmpeg/ffprobe is NOT installed:
Stop immediately and provide platform-specific installation instructions:
macOS
CODEBLOCK1
Linux (Ubuntu/Debian)
CODEBLOCK2
Linux (RHEL/Fedora/CentOS)
CODEBLOCK3
Windows
CODEBLOCK4
Docker (any platform)
CODEBLOCK5
Do not proceed with any other steps until ffmpeg is confirmed installed.
STEP 1 — Media Analysis (Always Probe Before Processing)
Always inspect input files before building commands. Load references/ffprobe-analysis.md for full probe patterns.
Quick probe
CODEBLOCK6
Key facts to extract before any operation:
- - Video: codec, resolution (WxH), fps, bitrate, pixel format, color space
- Audio: codec, sample rate, channels, bitrate, layout (stereo/5.1/etc.)
- Container: format, duration, total size, nb_streams
- Subtitles/attachments: subtitle streams, embedded fonts
STEP 2 — Command Construction Rules
Load references/ffmpeg-flags.md for the complete flag reference.
Universal Safety Rules
- 1. Never overwrite without explicit
-y flag — use -n to skip existing files by default - Always specify
-map for multi-stream operations — prevents silent stream loss - Prefer
-c copy (stream copy) when no re-encoding is needed — faster, lossless - Use
-crf for quality-based encoding, -b:v for bitrate-based — never both together - Validate output: run
ffprobe on output to confirm expected streams - Use
-progress pipe:1 for scriptable progress tracking - Set
-loglevel warning in production scripts to suppress info spam - Always use
-movflags +faststart for web MP4s (moves moov atom to front) - Quote all file paths — spaces and special characters will break commands
- Use
-ss before -i for fast seek (keyframe seek), after -i for accurate seek
Command Template
ffmpeg \
[global options] \
[input options] -i "input_file" \
[output options] \
"output_file"
SECTION A — Format Conversion & Transcoding
Load references/codecs-containers.md for codec compatibility matrix.
A1. Video Transcoding
MP4 → High-quality H.264 (universal compatibility)
ffmpeg -i "input.mov" \
-c:v libx264 -crf 23 -preset slow \
-c:a aac -b:a 192k \
-movflags +faststart \
"output.mp4"
INLINECODE20 : lower = better quality/larger file. preset: ultrafast→veryslow (speed vs compression).
H.265/HEVC (better compression, modern devices)
ffmpeg -i "input.mp4" \
-c:v libx265 -crf 28 -preset slow \
-c:a aac -b:a 128k \
-tag:v hvc1 \
"output_h265.mp4"
INLINECODE22 required for Apple device compatibility.
AV1 (best compression, slowest encode)
CODEBLOCK10
VP9 / WebM (web-optimized, royalty-free)
CODEBLOCK11
Hardware-accelerated encoding (macOS VideoToolbox)
CODEBLOCK12
Hardware-accelerated encoding (NVIDIA NVENC)
CODEBLOCK13
Hardware-accelerated encoding (Intel QSV)
CODEBLOCK14
A2. Container Remuxing (No Re-encoding)
CODEBLOCK15
A3. Image Sequence → Video
CODEBLOCK16
A4. Video → Image Sequence
# Extract all frames
ffmpeg -i "input.mp4" "frames/frame_%04d.png"
# Extract at specific fps (1 frame per second)
ffmpeg -i "input.mp4" -vf fps=1 "frames/frame_%04d.jpg"
# Extract keyframes only
# Note: -vsync vfr is deprecated since ffmpeg 5.1; use -fps_mode vfr on newer builds
ffmpeg -i "input.mp4" -vf "select=eq(pict_type\,I)" -fps_mode vfr "keyframe_%04d.jpg"
SECTION B — Audio Processing
B1. Audio Extraction
CODEBLOCK18
B2. Audio Conversion
CODEBLOCK19
B3. Audio Normalization (EBU R128 Loudness)
CODEBLOCK20
B4. Audio Filters
CODEBLOCK21
B5. Advanced Audio Processing
# Trim silence (remove leading/trailing silence)
ffmpeg -i "input.wav" -af "silenceremove=start_periods=1:start_silence=0.1:start_threshold=0.01:stop_periods=-1:stop_silence=0.1:stop_threshold=0.01" "output.wav"
# Speed change (pitch preserved using atempo, supports 0.5–2.0 range)
ffmpeg -i "input.wav" -af "atempo=1.5" "output.wav"
# Pitch shift (without tempo change, shift up by 2 semitones)
ffmpeg -i "input.wav" -af "asetrate=44100*1.122,aresample=44100,atempo=0.891" "output.wav"
# Generate waveform data (stats/loudness info)
ffprobe -v quiet -of json -show_streams "input.wav"
ffmpeg -i "input.wav" -af "astats" -f null - 2>&1
# Generate spectrogram PNG
ffmpeg -i "input.wav" -lavfi "showspectrumpic=s=1024x512:mode=combined" -update 1 "spectrogram.png"
SECTION C — Video Editing
C1. Trimming & Cutting
CODEBLOCK23
C2. Concatenation
CODEBLOCK24
C3. Scaling & Resolution
CODEBLOCK25
C4. Frame Rate Conversion
CODEBLOCK26
C5. Rotation & Flipping
CODEBLOCK27
C6. Cropping
CODEBLOCK28
C7. Overlays & Watermarks
CODEBLOCK29
C8. Color Correction & Grading
# Brightness, contrast, saturation
ffmpeg -i "input.mp4" \
-vf "eq=brightness=0.06:contrast=1.2:saturation=1.5:gamma=1.0" \
-c:a copy "output_color.mp4"
# LUT (Look-Up Table) color grading
ffmpeg -i "input.mp4" \
-vf "lut3d=file='film_emulation.cube'" \
-c:a copy "output_graded.mp4"
# Curves adjustment (S-curve for punch)
ffmpeg -i "input.mp4" \
-vf "curves=r='0/0 0.5/0.6 1/1':g='0/0 0.5/0.52 1/1':b='0/0 0.5/0.44 1/1'" \
-c:a copy "output_curves.mp4"
# Hue/saturation shift
ffmpeg -i "input.mp4" \
-vf "hue=h=30:s=1.2" \
-c:a copy "output_hue.mp4"
SECTION D — Subtitles & Captions
D1. Subtitle Operations
# Burn subtitles into video (hard subtitles)
ffmpeg -i "input.mp4" -vf "subtitles=subs.srt" -c:a copy "output_burned.mp4"
# Add SRT as soft subtitle track (selectable, not burned)
ffmpeg -i "input.mp4" -i "subs.srt" \
-c copy -c:s mov_text \
-metadata:s:s:0 language=eng \
"output_soft_subs.mp4"
# Add ASS/SSA subtitles to MKV
ffmpeg -i "input.mkv" -i "subs.ass" \
-c copy -c:s copy \
"output.mkv"
# Extract subtitle track
ffmpeg -i "input.mkv" -map 0:s:0 "subtitles.srt"
# Convert SRT → ASS
ffmpeg -i "subs.srt" "subs.ass"
SECTION E — Thumbnails & Screenshots
E1. Thumbnail Generation
# Single thumbnail at specific timestamp
ffmpeg -i "input.mp4" -ss 00:00:05 -vframes 1 "thumbnail.jpg"
# High-quality thumbnail (PNG)
ffmpeg -i "input.mp4" -ss 00:00:05 -vframes 1 -q:v 2 "thumbnail.png"
# Thumbnail at best frame (highest quality scene)
ffmpeg -i "input.mp4" -vf "thumbnail,scale=640:-1" -vframes 1 "best_thumb.jpg"
# Sprite sheet / contact sheet (multiple thumbnails in a grid)
ffmpeg -i "input.mp4" \
-vf "fps=1/10,scale=160:90,tile=10x10" \
-vframes 1 \
"sprite_sheet.jpg"
# Thumbnail every 10 seconds
ffmpeg -i "input.mp4" -vf "fps=1/10,scale=320:-1" "thumbs/thumb_%04d.jpg"
SECTION F — Streaming & Adaptive Bitrate
F1. HLS (HTTP Live Streaming)
CODEBLOCK33
F2. DASH (Dynamic Adaptive Streaming over HTTP)
CODEBLOCK34
F3. RTMP Live Streaming
# Stream to RTMP endpoint (YouTube, Twitch, etc.)
ffmpeg -re -i "input.mp4" \
-c:v libx264 -preset veryfast -b:v 4500k -maxrate 4500k -bufsize 9000k \
-pix_fmt yuv420p -g 60 \
-c:a aac -b:a 160k -ar 44100 \
-f flv "rtmp://live.twitch.tv/app/YOUR_STREAM_KEY"
# Screen capture + stream (macOS)
ffmpeg \
-f avfoundation -framerate 30 -i "1:0" \
-c:v libx264 -preset veryfast -b:v 4500k \
-c:a aac -b:a 160k \
-f flv "rtmp://YOUR_RTMP_ENDPOINT"
SECTION G — Screen & Webcam Capture
G1. Screen Recording
CODEBLOCK36
G2. Webcam Capture
# macOS
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0" \
-c:v libx264 -crf 23 "webcam.mp4"
# Linux (v4l2)
ffmpeg -f v4l2 -framerate 30 -video_size 1280x720 -i /dev/video0 \
-c:v libx264 -crf 23 "webcam.mp4"
# Windows (dshow)
ffmpeg -f dshow -i video="Integrated Camera" \
-c:v libx264 -crf 23 "webcam.mp4"
SECTION H — GIF & Animated Images
H1. Video → GIF (High Quality)
CODEBLOCK38
H2. GIF → Video
CODEBLOCK39
H3. WebP Animation
ffmpeg -i "input.mp4" -vf "fps=24,scale=480:-1:flags=lanczos" \
-loop 0 -preset default -an -fps_mode passthrough \
"output.webp"
# Note: -vsync 0 is deprecated since ffmpeg 5.1; use -fps_mode passthrough
SECTION I — Batch Processing & Scripting
I1. Batch Convert (Shell)
CODEBLOCK41
I2. Progress Monitoring
CODEBLOCK42
I3. Two-Pass Encoding (Precise Bitrate Control)
# Pass 1 (analysis only)
ffmpeg -y -i "input.mp4" \
-c:v libx264 -b:v 2M -pass 1 -an -f null -
# Pass 2 (encode with target bitrate)
ffmpeg -i "input.mp4" \
-c:v libx264 -b:v 2M -pass 2 \
-c:a aac -b:a 192k \
"output_2pass.mp4"
SECTION J — Advanced Filtergraphs
J1. Complex Filter Examples
CODEBLOCK44
J2. Audio/Video Sync Repair
# Fix audio delay (audio is 500ms late)
ffmpeg -i "input.mp4" -itsoffset -0.5 -i "input.mp4" \
-map 1:v -map 0:a -c copy "output_synced.mp4"
# Add audio delay (audio is 500ms early)
ffmpeg -i "input.mp4" -itsoffset 0.5 -i "input.mp4" \
-map 0:v -map 1:a -c copy "output_synced.mp4"
SECTION K — Quality Analysis & Verification
K1. Quality Metrics
CODEBLOCK46
K2. Output Validation Checklist
After every encode, verify:
CODEBLOCK47
SECTION L — Platform-Specific Presets
L1. Web (HTML5 video)
CODEBLOCK48
L2. YouTube Upload
CODEBLOCK49
L3. Instagram / TikTok (Vertical 9:16)
CODEBLOCK50
L4. Apple ProRes (Post-production)
CODEBLOCK51
L5. Discord / Messaging (8MB limit)
# Calculate target bitrate for 8MB / duration
DURATION=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "input.mp4")
TARGET_KBPS=$(python3 -c "print(int(8*1024*8 / $DURATION - 128))")
ffmpeg -i "input.mp4" \
-c:v libx264 -b:v "${TARGET_KBPS}k" -pass 1 -an -f null - && \
ffmpeg -i "input.mp4" \
-c:v libx264 -b:v "${TARGET_KBPS}k" -pass 2 \
-c:a aac -b:a 128k \
"discord_clip.mp4"
SECTION M — Video Stabilization
Stabilize shaky footage from handheld cameras, drones, or action cameras. Uses a two-pass approach: pass 1 analyzes motion, pass 2 applies correction.
Check libvidstab availability
CODEBLOCK53
If not available: Install a full-featured ffmpeg build.
- - macOS:
brew install ffmpeg-full or INLINECODE24 - Linux:
sudo apt install ffmpeg (Ubuntu 20.04+ includes libvidstab) - Windows: Download from https://www.gyan.dev/ffmpeg/builds/ (full build includes libvidstab)
Pass 1 — Detect motion (analyze shakiness)
CODEBLOCK54
Pass 2 — Apply stabilization
CODEBLOCK55
One-liner (both passes)
CODEBLOCK56
Windows (PowerShell)
CODEBLOCK57
Parameter tuning
| Goal | Settings |
|---|
| Mild stabilization | INLINECODE26 |
| Heavy stabilization |
shakiness=8:smoothing=50:zoom=5 |
| Preserve full frame |
zoom=0 (black borders may appear) |
| Action cam footage |
shakiness=10:accuracy=15:smoothing=30:zoom=2 |
SECTION N — 360° / VR Video
Handle 360° footage from cameras like GoPro Max, Insta360, Ricoh Theta. Convert between projections and inject spherical metadata so platforms (YouTube VR, Facebook 360) recognize the video correctly.
Check v360 filter availability
CODEBLOCK58
Convert equirectangular → cubemap (3x2 layout)
CODEBLOCK59
Convert cubemap → equirectangular
CODEBLOCK60
Inject spherical metadata (YouTube VR / Facebook 360)
CODEBLOCK61
Note: For full YouTube VR compliance, use Google's spatial-media tool after encoding to inject the proper XMP metadata atom. FFmpeg metadata injection is a best-effort fallback.
Reframe / extract a flat view from 360° video
CODEBLOCK62
macOS / Linux / Windows
The
v360 filter works identically on all platforms — no platform-specific flags needed.
SECTION O — HDR / Color Science
Handle HDR10 content from modern phones (iPhone, Android) and cameras. Convert HDR to SDR for web delivery, or tag files with correct color metadata.
Check color filters availability
CODEBLOCK63
If zscale is missing: Install with --enable-libzimg. macOS: brew install ffmpeg-full. Linux: sudo apt install ffmpeg (20.04+). Windows: use full build from gyan.dev.
HDR10 → SDR tone mapping (real HDR source required)
CODEBLOCK64
Colorspace conversion (SDR bt2020 → bt709)
CODEBLOCK65
Encode HDR10 output (for archival/editing)
CODEBLOCK66
Tag existing file with correct color metadata (no re-encode)
CODEBLOCK67
Tone mapping algorithm comparison
| Algorithm | Description | Best for |
|---|
| INLINECODE34 | Filmic, preserves highlights | General use |
| INLINECODE35 |
Simple, global | Fast previews |
|
mobius | Smooth, natural | Skin tones |
|
clip | Hard clip at white | Technical use |
Windows / Linux / macOS
Commands are identical across platforms. Ensure ffmpeg is built with
--enable-libzimg.
SECTION P — Advanced Streaming
SRT (Secure Reliable Transport) — low-latency streaming
SRT handles packet loss and network jitter, making it ideal for unstable connections (cellular, satellite, long-distance contribution).
CODEBLOCK68
Windows: Same commands work in PowerShell. SRT is included in full ffmpeg builds from gyan.dev.
Multi-endpoint restreaming (tee muxer)
Stream to YouTube, Twitch, and Facebook simultaneously from one ffmpeg process:
CODEBLOCK69
Rolling window DVR recording
Continuous loop recording — keeps only the last N segments (useful for security cameras, broadcast monitoring):
CODEBLOCK70
SECTION Q — Repair & Recovery
Recover from corrupt or truncated files
CODEBLOCK71
VFR → CFR conversion (fix audio sync drift)
Variable frame rate (VFR) footage — common from phones and screen recorders — causes audio sync drift in editing software. Convert to constant frame rate (CFR):
CODEBLOCK72
Fix audio/video sync offset
CODEBLOCK73
Rebuild broken index / moov atom
CODEBLOCK74
Windows / Linux / macOS
All recovery commands are platform-independent. On Windows PowerShell, use backtick `
`
for line continuation instead of \
.
---
## SECTION R — Metadata Management
### Embed key/value metadata tags
CODEBLOCK75
### Strip all metadata (privacy)
CODEBLOCK76
### Add chapter markers
CODEBLOCK77
> **Windows (PowerShell):** Write chapters.txt manually with a text editor, then run the ffmpeg step 2 command.
### Embed cover art into audio file (MP3, M4A, AAC)
CODEBLOCK78
### Multi-language audio/subtitle track management
CODEBLOCK79
### Read all metadata
CODEBLOCK80
---
## SECTION S — Testing & Debugging
### Generate SMPTE color bars + tone (calibration signal)
CODEBLOCK81
### Packet-level analysis (find corruption, missing keyframes)
CODEBLOCK82
### Encoding benchmark (compare presets)
CODEBLOCK83
### Bit stream filter debugging
CODEBLOCK84
---
## STEP 3 — Output Review
After generating any command, always:
1. **Explain what each flag does** — never leave flags unexplained
2. **State the expected output** — codec, resolution, duration, approximate file size
3. **Flag potential issues** — codec availability, platform support, quality trade-offs
4. **Provide the validation command** — so the agent/user can confirm success
5. **Suggest optimizations** — if a faster or better approach exists, mention it
---
## Quick Decision Reference
| Goal | Recommended Approach |
|------|---------------------|
| Change container, same codec | -c copy
remux |
| Reduce file size | H.265/CRF 28 or VP9 |
| Maximum compatibility | H.264/AAC in MP4 |
| Professional editing | ProRes or DNxHD |
| Web streaming | H.264 + -movflags +faststart
|
| Lossless archival | FFV1 + FLAC in MKV |
| Audio podcast | MP3 VBR q:a 2 or AAC 192k |
| Thumbnails fast | -ss
before -i
, -vframes 1
|
| Analyze file | ffprobe -print_format json
|
| Fix rotation | transpose
filter |
| Precise cut | Re-encode with accurate -ss
after -i
|
| Fast cut (slight imprecision OK) | -ss
before -i
+ -c copy
|
---
## Common Error Diagnosis
| Error | Likely Cause | Fix |
|-------|-------------|-----|
| Encoder not found
| Codec not compiled into ffmpeg | Install full ffmpeg build |
| Invalid option -crf
| Using -crf
with copy or incompatible codec | Remove -crf
, use -b:v
|
| moov atom not found
| Corrupt/truncated input | Use -analyzeduration 100M -probesize 100M
|
| No audio/video stream
| Wrong -map
or stream missing | Check streams with ffprobe
, fix -map
|
| Output file is empty
| Missing output path or filter error | Check filtergraph syntax, verify paths |
| Trailing option(s) found
| Flag order wrong | Move input flags before -i
|
| Unable to find a suitable output format
| Missing output extension | Add correct extension to output file |
| Conversion failed!
| See preceding error lines | Run with -loglevel debug
for full trace |
---
## References
- references/ffprobe-analysis.md
— Complete ffprobe query patterns and JSON parsing
- references/codecs-containers.md
— Codec compatibility matrix and container guide
- references/ffmpeg-flags.md
— Complete flag reference with defaults and ranges
- assets/platform-presets.md
— Ready-to-use presets for 20+ platforms
- assets/quality-checklist.md
— Pre-release quality verification checklist
- assets/features.md` — Feature overview and capability descriptions
音频/视频处理技能
您是精通 ffmpeg 和 ffprobe 的音频/视频工程师。您能生成正确、高效、安全的 shell 命令,并附有清晰的解释。
本技能涵盖以下各节组织的各种音频/视频任务。若仅需了解本技能提供的功能(无需了解具体命令),请阅读同样按节组织的 features.md。features.md 还提到了本技能不同部分可使用的几个用例。
第 0 步 — 工具可用性检查(始终首先运行)
在生成任何命令之前,验证所需工具是否已安装。运行或指示代理运行:
bash
ffmpeg -version 2>&1 | head -1
ffprobe -version 2>&1 | head -1
Windows:在 PowerShell 中运行这些命令。head 不可用 — 使用 ffmpeg -version 并手动读取第一行,或通过管道传递给 Select-Object -First 1。
如果未安装 ffmpeg/ffprobe:
立即停止并提供特定平台的安装说明:
macOS
bash
选项 1:Homebrew(推荐)
brew install ffmpeg
注意:Homebrew 已移除 --with-* 选项标志。默认公式包含
最常见的编解码器。如需包含更多编解码器(libfdk-aac 等)的构建:
brew tap homebrew-ffmpeg/ffmpeg && brew install homebrew-ffmpeg/ffmpeg/ffmpeg
参见:https://formulae.brew.sh/formula/ffmpeg
验证
ffmpeg -version
Linux (Ubuntu/Debian)
bash
sudo apt update && sudo apt install -y ffmpeg
或获取最新的静态构建:
wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
tar xf ffmpeg-release-amd64-static.tar.xz
FFDIR=$(find . -maxdepth 1 -type d -name ffmpeg-*-static | head -n1)
sudo mv $FFDIR/ffmpeg $FFDIR/ffprobe /usr/local/bin/
Linux (RHEL/Fedora/CentOS)
bash
sudo dnf install -y ffmpeg ffmpeg-devel
或通过 RPM Fusion:
sudo dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install -y ffmpeg
Windows
powershell
选项 1:winget
winget install Gyan.FFmpeg
选项 2:Chocolatey
choco install ffmpeg
选项 3:Scoop
scoop install ffmpeg
选项 4:手动 — 从 https://www.gyan.dev/ffmpeg/builds/ 下载
解压并添加到 PATH
Docker(任何平台)
bash
macOS / Linux
docker run --rm -v $(pwd):/work -w /work jrottenberg/ffmpeg:latest \
-i input.mp4 output.mp4
Windows PowerShell
docker run --rm -v ${PWD}:/work -w /work jrottenberg/ffmpeg:latest
-i input.mp4 output.mp4
在确认 ffmpeg 已安装之前,请勿继续执行任何其他步骤。
第 1 步 — 媒体分析(处理前始终探测)
在构建命令之前,始终检查输入文件。加载 references/ffprobe-analysis.md 以获取完整的探测模式。
快速探测
bash
完整 JSON 输出 — 机器可读,用于脚本编写
ffprobe -v quiet -print
format json -showformat -show_streams input.mp4
人类可读摘要
ffprobe -v error -show
entries format=filename,duration,size,bitrate \
-show
entries stream=index,codecname,codec
type,width,height,rframe
rate,bitrate,sample_rate,channels \
-of default=noprint_wrappers=1 input.mp4
人类可读的完整元数据摘要
ffprobe -v quiet -print
format json -showformat -show_streams input.mp4 | python3 -m json.tool
任何操作前需提取的关键信息:
- - 视频:编解码器、分辨率(宽x高)、帧率、比特率、像素格式、色彩空间
- 音频:编解码器、采样率、声道数、比特率、布局(立体声/5.1等)
- 容器:格式、时长、总大小、流数量
- 字幕/附件:字幕流、嵌入字体
第 2 步 — 命令构建规则
加载 references/ffmpeg-flags.md 以获取完整的标志参考。
通用安全规则
- 1. 没有显式的 -y 标志绝不覆盖 — 默认使用 -n 跳过现有文件
- 多流操作始终指定 -map — 防止静默丢失流
- 无需重新编码时优先使用 -c copy(流复制) — 更快、无损
- 基于质量的编码使用 -crf,基于比特率的编码使用 -b:v — 切勿同时使用
- 验证输出:对输出运行 ffprobe 以确认预期的流
- 使用 -progress pipe:1 实现可脚本化的进度跟踪
- 在生产脚本中设置 -loglevel warning 以抑制信息垃圾
- Web MP4 始终使用 -movflags +faststart(将 moov atom 移到前端)
- 引用所有文件路径 — 空格和特殊字符会破坏命令
- 快速搜索使用 -ss 在 -i 之前(关键帧搜索),精确搜索在 -i 之后
命令模板
bash
ffmpeg \
[全局选项] \
[输入选项] -i 输入文件 \
[输出选项] \
输出文件
第 A 节 — 格式转换与转码
加载 references/codecs-containers.md 以获取编解码器兼容性矩阵。
A1. 视频转码
MP4 → 高质量 H.264(通用兼容性)
bash
ffmpeg -i input.mov \
-c:v libx264 -crf 23 -preset slow \
-c:a aac -b:a 192k \
-movflags +faststart \
output.mp4
crf 18-28:数值越低 = 质量越好/文件越大。preset:ultrafast→veryslow(速度 vs 压缩率)。
H.265/HEVC(更好的压缩率,现代设备)
bash
ffmpeg -i input.mp4 \
-c:v libx265 -crf 28 -preset slow \
-c:a aac -b:a 128k \
-tag:v hvc1 \
output_h265.mp4
Apple 设备兼容性需要 -tag:v hvc1。
AV1(最佳压缩率,最慢编码)
bash
ffmpeg -i input.mp4 \
-c:v libaom-av1 -crf 30 -b:v 0 \
-strict experimental \
-c:a libopus -b:a 128k \
output.webm
VP9 / WebM(Web 优化,免版税)
bash
ffmpeg -i input.mp4 \
-c:v libvpx-vp9 -crf 30 -b:v 0 \
-c:a libopus -b:a 128k \
output.webm
硬件加速编码(macOS VideoToolbox)
bash
ffmpeg -i input.mp4 \
-c:v h264_videotoolbox -b:v 5M \
-c:a aac -b:a 192k \
output_fast.mp4
硬件加速编码(NVIDIA NVENC)
bash
ffmpeg -i input.mp4 \
-c:v h264_nvenc -preset p6 -cq 23 \
-c:a aac -b:a 192k \
output_nvenc.mp4
硬件加速编码(Intel QSV)
bash
ffmpeg -i input.mp4 \
-c:v h264
qsv -globalquality 23 \