ffmpeg-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFFmpeg CLI Reference
FFmpeg CLI 参考手册
Contents
目录
Dependencies
依赖项
Verify ffmpeg is installed:
sh
ffmpeg -versionInstall if missing:
sh
undefined验证FFmpeg是否已安装:
sh
ffmpeg -version如果未安装,执行以下命令安装:
sh
undefinedmacOS
macOS
brew install ffmpeg
brew install ffmpeg
Ubuntu/Debian
Ubuntu/Debian
sudo apt install ffmpeg
sudo apt install ffmpeg
Windows (scoop)
Windows (scoop)
scoop install ffmpeg
undefinedscoop install ffmpeg
undefinedGlossary of flags and filters
参数与滤镜术语表
| Flag/Filter | Purpose |
|---|---|
| Video filter |
| Audio filter |
| Complex filter graph for multi-stream filtering |
| All streams from first input (0-based) |
| Video stream from first input |
| Audio stream from second input |
| First input, first video stream |
| First input, second audio stream |
| Named stream, used with |
| Select stream for output |
| Auto-overwrite output files without confirmation |
Converting formats
格式转换
Remux MP4 to MKV (no re-encoding):
sh
ffmpeg -i input.mp4 -c copy output.mkvMKV and MP4 are both containers for H264/H265 video and AAC/MP3 audio. Video quality is determined by the codec, not the container. MKV supports multiple video streams; MP4 has wider device support.
Remux MP4 to MOV:
sh
ffmpeg -i input.mp4 -c copy output.movEncode MP4 to AVI (re-encodes):
sh
ffmpeg -i input.mp4 output.avi将MP4格式重封装为MKV(无需重新编码):
sh
ffmpeg -i input.mp4 -c copy output.mkvMKV和MP4均为H264/H265视频及AAC/MP3音频的容器格式。视频质量由编码格式决定,而非容器格式。MKV支持多视频流;MP4则拥有更广泛的设备兼容性。
将MP4格式重封装为MOV:
sh
ffmpeg -i input.mp4 -c copy output.mov将MP4编码为AVI(需重新编码):
sh
ffmpeg -i input.mp4 output.aviResizing and padding
缩放与填充
Upscale to 1080x1920, preserve aspect ratio, black padding:
sh
ffmpeg -i input.mp4 -vf "scale=w=1080:h=1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1" output.mp4scale options:
- - auto-decrease output dimensions to fit aspect ratio
force_original_aspect_ratio=decrease - - auto-increase dimensions
force_original_aspect_ratio=increase - - let ffmpeg pick correct height for aspect ratio
scale=w=1080:h=-1 - - force dimensions divisible by 2
scale=w=1080:h=-2
pad options:
- - x:y is top-left corner position
pad=width:height:x:y:color - centres the video; negative values also centre
(ow-iw)/2:(oh-ih)/2 - pad reference
setsar=1:1 ensures 1:1 pixel aspect ratio. Prevents ffmpeg from compensating for ratio changes. setsar reference
Two scaled outputs from one input (horizontal + vertical with logo overlay):
sh
ffmpeg -i input.mp4 -i logo.png \
-filter_complex "[0:v]split=2[s0][s1]; \
[s0]scale=w=1920:h=1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1[out1]; \
[s1]scale=w=720:h=1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1[s2]; \
[s2][1]overlay=(main_w-overlay_w)/2:(main_w-overlay_w)/5[out2]" \
-map [out1] -map 0:a output_youtube.mp4 \
-map [out2] -map 0:a output_shorts.mp4将视频 upscale 至1080x1920,保持宽高比,添加黑边填充:
sh
ffmpeg -i input.mp4 -vf "scale=w=1080:h=1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1" output.mp4scale参数选项:
- - 自动缩小输出尺寸以适配原宽高比
force_original_aspect_ratio=decrease - - 自动放大输出尺寸
force_original_aspect_ratio=increase - - 由FFmpeg自动计算符合宽高比的高度
scale=w=1080:h=-1 - - 强制尺寸为2的倍数
scale=w=1080:h=-2
pad参数选项:
- - x:y为填充区域的左上角坐标
pad=width:height:x:y:color - - 将视频居中;负值同样可实现居中效果
(ow-iw)/2:(oh-ih)/2 - pad参考文档
setsar=1:1用于确保1:1的像素宽高比,避免FFmpeg自动补偿宽高比变化。setsar参考文档
从单个输入生成两个缩放后的输出(横版+竖版,且添加logo水印):
sh
ffmpeg -i input.mp4 -i logo.png \
-filter_complex "[0:v]split=2[s0][s1]; \
[s0]scale=w=1920:h=1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1[out1]; \
[s1]scale=w=720:h=1280:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1:1[s2]; \
[s2][1]overlay=(main_w-overlay_w)/2:(main_w-overlay_w)/5[out2]" \
-map [out1] -map 0:a output_youtube.mp4 \
-map [out2] -map 0:a output_shorts.mp4Trim by time
按时间剪辑
sh
ffmpeg -i input.mp4 -ss 00:00:10 -to 00:00:25 output.mp4For faster but less accurate trimming, see the Input/output seeking section in . For the trade-offs when trimming, see .
references/encoding-and-settings.md-c copyreferences/core-concepts.mdsh
ffmpeg -i input.mp4 -ss 00:00:10 -to 00:00:25 output.mp4如需更快但精度稍低的剪辑方式,请查看中的输入/输出seek章节。关于剪辑时使用的利弊,请查看。
references/encoding-and-settings.md-c copyreferences/core-concepts.mdVerification and inspection
验证与检查
List supported formats:
sh
ffmpeg -formatsList supported codecs:
sh
ffmpeg -codecs列出支持的格式:
sh
ffmpeg -formats列出支持的编码格式:
sh
ffmpeg -codecsffprobe
ffprobe
ffprobe provides structured metadata about media files.
Show detailed stream information:
sh
ffprobe -show_streams -i input.mp4Verify moov atom position (faststart):
sh
ffprobe -v trace -i input.mp4Look for near the beginning of output to confirm faststart is applied.
type:'moov'ffprobe用于提取媒体文件的结构化元数据。
显示详细的流信息:
sh
ffprobe -show_streams -i input.mp4验证moov原子的位置(faststart):
sh
ffprobe -v trace -i input.mp4在输出内容开头附近查找即可确认已应用faststart。
type:'moov'Reference files
参考文件
Load these on demand with the Read tool when the task requires deeper coverage.
| File | Topics |
|---|---|
| |
| Replace audio, extract audio, mix audio, combine MP3 tracks, crossfade, change audio format, merge and normalise |
| Playback speed, FPS change, jump cuts, video cropping for social, drawtext overlay, subtitles (burn/embed/extract), combine media (overlay, logo, background, concat intro/main/outro, vstack) |
| Image to video, slideshow with fade, Ken Burns (zoompan), GIFs, video compilation with fades, thumbnails (single/multiple/scene), image thumbnails, storyboards (scene tile/keyframe/Nth frame) |
| Optimised daily command, H264 (libx264) deep-dive, H265 (libx265) Apple compat, VP9 (libvpx-vp9) constant quality, 1-pass vs 2-pass, |
当任务需要更深入的内容时,可使用读取工具按需加载以下文件。
| 文件 | 主题 |
|---|---|
| |
| 替换音频、提取音频、混音、合并MP3轨道、交叉淡入淡出、转换音频格式、合并与归一化 |
| 播放速度调整、帧率修改、跳剪、社交平台视频裁剪、drawtext水印、字幕(硬刻录/嵌入/提取)、媒体合成(水印、logo、背景、拼接片头/正片/片尾、垂直拼接) |
| 图片转视频、带淡入淡出的幻灯片、Ken Burns效果(zoompan)、GIF生成、带淡入淡出的视频合集、缩略图(单张/多张/场景)、图片缩略图、故事板(场景分镜/关键帧/第N帧) |
| 日常优化命令、H264(libx264)深入解析、H265(libx265)苹果兼容性、VP9(libvpx-vp9)恒定质量、1-pass vs 2-pass编码、 |