video-editor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Video Editor - FFmpeg & Encoding Expert

视频编辑专家 - FFmpeg与编码指南

Expert guidance for video editing, encoding, and processing with ffmpeg. This skill covers container formats, codecs, encoding best practices, and quality optimization for video production workflows.
FFmpeg视频编辑、编码与处理专业指南。本指南涵盖容器格式、编解码器、编码最佳实践,以及视频制作工作流中的质量优化方案。

When to Use This Skill

适用场景

Use this skill when:
  • Encoding or transcoding video files
  • Converting between container formats (MKV, MP4, etc.)
  • Optimizing encoding settings for quality or file size
  • Troubleshooting video quality issues
  • Working with color spaces and color matrices
  • Hardsubbing or softsubbing videos
  • Preparing videos for specific platforms or devices
  • Understanding why a video looks wrong after processing
当你需要以下操作时,可使用本指南:
  • 视频文件编码或转码
  • 在不同容器格式(MKV、MP4等)之间转换
  • 优化编码设置以平衡质量与文件大小
  • 排查视频质量问题
  • 处理色彩空间与色彩矩阵
  • 硬字幕嵌入或软字幕处理
  • 为特定平台或设备准备视频
  • 分析视频处理后画质异常的原因

Core Concepts

核心概念

Container vs. Codec

容器格式 vs 编解码器

This distinction is critical. File extensions like
.mkv
or
.mp4
are container formats that package already-compressed streams. The actual compression happens through codecs like H.264, H.265, VP9, or AV1.
ConceptWhat It IsExamples
ContainerWrapper that holds video/audio/subtitle streamsMKV, MP4, AVI, MOV, WebM
CodecAlgorithm that compresses/decompresses videoH.264, H.265/HEVC, VP9, AV1
EncoderSoftware that implements a codecx264, x265, libvpx, NVENC
这一区分至关重要
.mkv
.mp4
这类文件扩展名是容器格式,用于封装已压缩的音视频流。实际的压缩由H.264、H.265、VP9或AV1等**编解码器(codec)**完成。
概念定义示例
容器格式封装视频/音频/字幕流的容器MKV, MP4, AVI, MOV, WebM
编解码器用于压缩/解压缩视频的算法H.264, H.265/HEVC, VP9, AV1
编码器实现编解码器的软件x264, x265, libvpx, NVENC

Remuxing vs. Reencoding

封包格式转换(Remuxing) vs 重新编码(Reencoding)

OperationWhat It DoesQuality ImpactSpeed
RemuxingMoves streams between containers without re-compressionNone (lossless)Very fast
ReencodingDecodes and re-encodes video with new settingsAlways loses qualitySlow
Rule of thumb: If you only need to change the container format, remux. Only reencode when absolutely necessary.
操作定义画质影响速度
封包格式转换在不重新压缩的前提下,将音视频流转移到其他容器中无(无损)极快
重新编码解码视频并使用新设置重新编码必然损失画质缓慢
经验法则:若仅需更改容器格式,使用封包格式转换。仅在绝对必要时才进行重新编码。

Quality Principles

质量原则

What "Quality" Actually Means

「画质」的真正含义

Video quality measures how closely the output resembles the source. Every processing step moves the video further from the original. There is no way to add quality - only preserve or lose it.
视频画质衡量的是输出与源文件的相似程度。每一步处理都会让视频偏离源文件。不存在提升画质的方法,只能尽可能保留或避免损失画质。

Common Misconceptions

常见误区

MythReality
Higher resolution = better qualityResolution is just dimensions; a 720p video can look better than a 4K one
Higher bitrate = better qualityEncoder efficiency matters more; same quality at different sizes is possible
H.265 is always 50% smallerDepends on encoder settings; poorly-configured H.265 can be worse than H.264
Hardware encoding is fine for qualityHardware encoders (NVENC, QuickSync) sacrifice quality for speed
AI upscaling improves qualityUpscaling adds artificial detail that wasn't in the source
误区真相
分辨率越高=画质越好分辨率仅指尺寸;720p视频的画质可能优于4K视频
码率越高=画质越好编码器效率更重要;相同画质下可实现不同文件大小
H.265总能比H.264小50%取决于编码器设置;配置不当的H.265画质可能不如H.264
硬件编码画质足够好硬件编码器(NVENC、QuickSync)为了速度牺牲画质
AI upscale能提升画质超分辨率会添加源文件中不存在的人工细节

The Encoding Quality Hierarchy

编码画质优先级

From most to least important:
  1. Encoder settings (CRF, preset, tuning)
  2. Encoder choice (x264/x265 vs. hardware encoders)
  3. Codec (H.265 vs. H.264 vs. VP9)
从最重要到最不重要:
  1. 编码器设置(CRF、preset、tuning)
  2. 编码器选择(x264/x265 vs 硬件编码器)
  3. 编解码器(H.265 vs H.264 vs VP9)

Quick Reference: FFmpeg Commands

快速参考:FFmpeg命令

Remux (Change Container, No Quality Loss)

封包格式转换(更改容器,无画质损失)

bash
undefined
bash
undefined

MKV to MP4 (preserves all streams)

MKV转MP4(保留所有流)

ffmpeg -i input.mkv -c copy output.mp4
ffmpeg -i input.mkv -c copy output.mp4

MP4 to MKV

MP4转MKV

ffmpeg -i input.mp4 -c copy output.mkv
undefined
ffmpeg -i input.mp4 -c copy output.mkv
undefined

Basic Encoding

基础编码

bash
undefined
bash
undefined

Encode with x264, copy audio

使用x264编码,复制音频

ffmpeg -i input.mkv -c:a copy -c:v libx264 -preset slower -crf 20 output.mkv
ffmpeg -i input.mkv -c:a copy -c:v libx264 -preset slower -crf 20 output.mkv

Encode with x265

使用x265编码

ffmpeg -i input.mkv -c:a copy -c:v libx265 -preset slower -crf 22 output.mkv
undefined
ffmpeg -i input.mkv -c:a copy -c:v libx265 -preset slower -crf 22 output.mkv
undefined

Quality-Focused Encoding

画质优先的编码

bash
undefined
bash
undefined

High-quality x264 for animation

动画内容专用高质量x264编码

ffmpeg -i input.mkv -c:a copy -c:v libx264 -preset slower -crf 18
-x264-params bframes=8 output.mkv
ffmpeg -i input.mkv -c:a copy -c:v libx264 -preset slower -crf 18
-x264-params bframes=8 output.mkv

High-quality x265

高质量x265编码

ffmpeg -i input.mkv -c:a copy -c:v libx265 -preset slower -crf 20
-x265-params bframes=8 output.mkv
undefined
ffmpeg -i input.mkv -c:a copy -c:v libx265 -preset slower -crf 20
-x265-params bframes=8 output.mkv
undefined

Encoding Settings Deep Dive

编码设置深度解析

CRF (Constant Rate Factor)

CRF(恒定速率因子)

CRF controls quality vs. file size tradeoff. Lower = higher quality, larger file.
CRF RangeQuality LevelTypical Use
0LosslessArchival, intermediate
15-18Visually losslessHigh-quality archival
19-23High qualityGeneral use, streaming
24-28Medium qualityWeb, mobile
29+Low qualityPreviews, thumbnails
Note: CRF values aren't directly comparable between encoders. x265 CRF 22 ≈ x264 CRF 20.
CRF控制画质与文件大小的平衡。值越小=画质越高,文件越大
CRF范围画质等级典型用途
0无损归档、中间文件
15-18视觉无损高质量归档
19-23高质量通用用途、流媒体
24-28中等质量网页、移动设备
29+低质量预览、缩略图
注意:不同编码器的CRF值无法直接对比。x265的CRF22 ≈ x264的CRF20。

Preset

Preset(预设)

Presets control encoding speed vs. compression efficiency.
PresetSpeedFile SizeUse When
ultrafastFastestLargestLive streaming
fastFastLargeQuick transcodes
mediumModerateModerateDefault
slowSlowSmallerQuality-focused
slowerVery slowEven smallerRecommended for quality
veryslowExtremely slowSmallestMaximum compression
Recommendation: Use
slower
for quality-focused encoding. The difference between
slower
and
veryslow
is minimal for significant time cost.
预设控制编码速度与压缩效率的平衡。
预设速度文件大小适用场景
ultrafast最快最大直播流
fast快速转码
medium中等中等默认设置
slow较小画质优先场景
slower很慢更小推荐用于画质优先编码
veryslow极慢最小最大压缩率
推荐:画质优先编码使用
slower
预设。
slower
veryslow
的压缩率差异极小,但耗时大幅增加。

Tune Options

Tune(调优选项)

TuneBest For
filmLive-action with film grain
animationCartoons, anime, flat areas
grainPreserve film grain
stillimageSlideshow, static content
fastdecodePlayback on weak devices
bash
undefined
调优最佳适用场景
film带胶片颗粒的真人视频
animation卡通、动画、平涂内容
grain保留胶片颗粒
stillimage幻灯片、静态内容
fastdecode弱设备播放
bash
undefined

Animation tuning

动画内容调优

ffmpeg -i input.mkv -c:v libx264 -preset slower -crf 20 -tune animation output.mkv
undefined
ffmpeg -i input.mkv -c:v libx264 -preset slower -crf 20 -tune animation output.mkv
undefined

Container-Specific Considerations

容器格式特定注意事项

MKV (Matroska)

MKV(Matroska)

Pros:
  • Supports virtually any codec
  • Multiple audio/subtitle tracks
  • Chapter markers
  • Variable frame rate support
Cons:
  • Less compatible with some devices/software
  • Some streaming services don't accept it
优点
  • 支持几乎所有编解码器
  • 多音轨/字幕轨
  • 章节标记
  • 可变帧率支持
缺点
  • 部分设备/软件兼容性较差
  • 部分流媒体服务不支持

MP4

MP4

Pros:
  • Universal compatibility
  • Web-friendly
  • Hardware decoder support everywhere
Cons:
  • Limited subtitle format support
  • Stricter codec requirements
  • Constant frame rate expected
优点
  • 通用兼容性
  • 网页友好
  • 全平台硬件解码支持
缺点
  • 字幕格式支持有限
  • 编解码器要求更严格
  • 通常要求恒定帧率

Converting MKV to MP4 for Editing Software

MKV转MP4适配编辑软件

Some editing software requires constant frame rate MP4. Use this two-pass approach:
bash
undefined
部分编辑软件要求恒定帧率的MP4。使用以下两步法:
bash
undefined

Step 1: Initial remux with timescale adjustment

步骤1:调整时间轴的初始封包转换

ffmpeg -i input.mkv -c copy -video_track_timescale 24000 intermediate.mp4
ffmpeg -i input.mkv -c copy -video_track_timescale 24000 intermediate.mp4

Step 2: Fix timestamps

步骤2:修复时间戳

ffmpeg -i intermediate.mp4 -c copy
-bsf:v "setts=dts=1001round(DTS/1001):pts=1001round(PTS/1001)" output.mp4
undefined
ffmpeg -i intermediate.mp4 -c copy
-bsf:v "setts=dts=1001round(DTS/1001):pts=1001round(PTS/1001)" output.mp4
undefined

Color Space & Color Management

色彩空间与色彩管理

Understanding Color Metadata

理解色彩元数据

Videos store colors in YCbCr format with metadata specifying:
  • Color matrix: How to convert YCbCr to RGB (BT.709, BT.601)
  • Color range: Limited (16-235) vs. Full (0-255)
  • Chroma location: Where color samples are positioned
视频以YCbCr格式存储,元数据包含:
  • 色彩矩阵:YCbCr转RGB的规则(BT.709、BT.601)
  • 色彩范围:有限范围(16-235) vs 全范围(0-255)
  • 色度位置:色彩样本的定位

Common Issues

常见问题

SymptomLikely Cause
Washed out colorsWrong color range (Limited treated as Full)
Crushed blacks/blown whitesWrong color range (Full treated as Limited)
Greenish/pinkish tintWrong color matrix
Colors look "off" after encodeMismatched color metadata
症状可能原因
色彩泛白色彩范围不匹配(有限范围被识别为全范围)
黑色过暗/白色过曝色彩范围不匹配(全范围被识别为有限范围)
偏绿/偏粉色彩矩阵错误
编码后色彩异常色彩元数据不匹配

Preserving Color Information

保留色彩信息

bash
undefined
bash
undefined

Explicitly preserve color metadata

显式保留色彩元数据

ffmpeg -i input.mkv -c:v libx264 -preset slower -crf 20
-colorspace bt709 -color_primaries bt709 -color_trc bt709 output.mkv
undefined
ffmpeg -i input.mkv -c:v libx264 -preset slower -crf 20
-colorspace bt709 -color_primaries bt709 -color_trc bt709 output.mkv
undefined

Hardsubbing (Burning In Subtitles)

硬字幕嵌入

Using FFmpeg

使用FFmpeg

bash
undefined
bash
undefined

Hardsub from external subtitle file

从外部字幕文件嵌入硬字幕

ffmpeg -i input.mkv -vf "subtitles=subs.ass" -c:v libx264 -preset slower -crf 20 output.mkv
ffmpeg -i input.mkv -vf "subtitles=subs.ass" -c:v libx264 -preset slower -crf 20 output.mkv

Hardsub from embedded subtitle track

从内嵌字幕轨嵌入硬字幕

ffmpeg -i input.mkv -vf "subtitles=input.mkv:si=0" -c:v libx264 -preset slower -crf 20 output.mkv
undefined
ffmpeg -i input.mkv -vf "subtitles=input.mkv:si=0" -c:v libx264 -preset slower -crf 20 output.mkv
undefined

Using mpv (Better for Complex Subtitles)

使用mpv(复杂字幕更优)

mpv handles complex ASS subtitles (styling, positioning) more accurately:
bash
mpv --no-config input.mkv -o output.mkv \
  --audio=no \
  --ovc=libx264 \
  --ovcopts=preset=slower,crf=20,bframes=8
mpv对复杂ASS字幕(样式、定位)的处理更准确:
bash
mpv --no-config input.mkv -o output.mkv \
  --audio=no \
  --ovc=libx264 \
  --ovcopts=preset=slower,crf=20,bframes=8

What to Avoid

避坑指南

Tools

工具类

ToolProblem
HandbrakeUnpredictable settings, hides important options
Online convertersQuality loss, privacy concerns
"AI upscalers"Add fake detail, move further from source
Windows built-in toolsPoor quality, limited options
工具问题
Handbrake设置不可控,隐藏关键选项
在线转换器画质损失,隐私风险
"AI超分辨率工具"添加虚假细节,偏离源文件
Windows内置工具画质差,选项有限

Practices

操作类

PracticeWhy It's Bad
Unnecessary sharpeningAdds artifacts, moves from source
Upscaling to higher resolutionDoesn't add real detail
Multiple reencodesQuality loss compounds
Using NVENC for qualityHardware encoders prioritize speed over quality
Frame rate interpolationAdds fake frames with artifacts
操作危害
不必要的锐化添加伪影,偏离源文件
超分辨率到更高分辨率无法添加真实细节
多次重新编码画质损失累积
使用NVENC追求画质硬件编码器优先速度而非画质
帧率插值添加带伪影的虚假帧

Recommended Tools

推荐工具

Essential

必备工具

ToolPurpose
ffmpegSwiss army knife for video processing
MediaInfoInspect video properties and metadata
mpvSuperior media player, encoding support
MKVToolNixGUI for MKV muxing operations
工具用途
ffmpeg视频处理瑞士军刀
MediaInfo查看视频属性与元数据
mpv高级媒体播放器,支持编码
MKVToolNixMKV封包操作GUI工具

Specialized

专业工具

ToolPurpose
AegisubSubtitle editing
HandBrakeSimple transcoding (use with caution)
yt-dlpDownload online videos
工具用途
Aegisub字幕编辑
HandBrake简单转码(谨慎使用)
yt-dlp在线视频下载

Troubleshooting

故障排查

Video Won't Play

视频无法播放

  1. Check codec support on target device
  2. Try remuxing to different container
  3. Verify file isn't corrupted:
    ffmpeg -v error -i file.mkv -f null -
  1. 检查目标设备的编解码器支持
  2. 尝试转码到其他容器格式
  3. 验证文件是否损坏:
    ffmpeg -v error -i file.mkv -f null -

Colors Look Wrong After Encoding

编码后色彩异常

  1. Compare color metadata:
    mediainfo input.mkv
    vs.
    mediainfo output.mkv
  2. Check color range (Limited vs. Full)
  3. Check color matrix (BT.709 vs. BT.601)
  4. Explicitly set color parameters in ffmpeg command
  1. 对比色彩元数据:
    mediainfo input.mkv
    vs
    mediainfo output.mkv
  2. 检查色彩范围(有限vs全范围)
  3. 检查色彩矩阵(BT.709 vs BT.601)
  4. 在FFmpeg命令中显式设置色彩参数

File Size Too Large

文件过大

  1. Increase CRF (e.g., 20 → 23)
  2. Use slower preset for better compression
  3. Consider x265 for better efficiency
  4. Check if you're unnecessarily encoding (remux instead)
  1. 提高CRF值(如20→23)
  2. 使用更慢的预设以提升压缩率
  3. 考虑使用x265以获得更高效率
  4. 检查是否存在不必要的编码(改用封包转换)

Encoding Takes Forever

编码耗时过长

  1. Use faster preset (but accept larger file)
  2. Check if hardware encoding is acceptable for your use case
  3. Ensure source isn't being decoded unnecessarily
  1. 使用更快的预设(接受更大文件)
  2. 确认硬件编码是否符合你的需求
  3. 确保源文件未被不必要地解码

Audio/Video Out of Sync

音视频不同步

  1. Check source file for sync issues first
  2. Use
    -async 1
    for audio sync correction
  3. Try remuxing instead of reencoding
  1. 先检查源文件是否存在同步问题
  2. 使用
    -async 1
    修正音频同步
  3. 尝试封包转换而非重新编码

Examples

示例

Archive a Blu-ray Rip

蓝光备份归档

bash
ffmpeg -i input.mkv -c:a copy -c:v libx265 -preset slower -crf 18 \
  -x265-params bframes=8 output.mkv
bash
ffmpeg -i input.mkv -c:a copy -c:v libx265 -preset slower -crf 18 \
  -x265-params bframes=8 output.mkv

Prepare for YouTube Upload

为YouTube上传准备视频

bash
ffmpeg -i input.mkv -c:a aac -b:a 384k -c:v libx264 -preset slower -crf 18 \
  -profile:v high -level 4.2 -pix_fmt yuv420p output.mp4
bash
ffmpeg -i input.mkv -c:a aac -b:a 384k -c:v libx264 -preset slower -crf 18 \
  -profile:v high -level 4.2 -pix_fmt yuv420p output.mp4

Quick Preview/Proxy

快速预览/代理文件

bash
ffmpeg -i input.mkv -c:a aac -b:a 128k -c:v libx264 -preset fast -crf 28 \
  -vf scale=640:-2 output.mp4
bash
ffmpeg -i input.mkv -c:a aac -b:a 128k -c:v libx264 -preset fast -crf 28 \
  -vf scale=640:-2 output.mp4

Extract Audio Only

仅提取音频

bash
undefined
bash
undefined

Copy audio stream (no re-encoding)

复制音频流(无重新编码)

ffmpeg -i input.mkv -vn -c:a copy output.mka
ffmpeg -i input.mkv -vn -c:a copy output.mka

Convert to MP3

转换为MP3

ffmpeg -i input.mkv -vn -c:a libmp3lame -b:a 320k output.mp3
undefined
ffmpeg -i input.mkv -vn -c:a libmp3lame -b:a 320k output.mp3
undefined

Trim Without Re-encoding

无损修剪

bash
undefined
bash
undefined

Trim from 1:00 to 2:30

从1:00修剪到2:30

ffmpeg -i input.mkv -ss 00:01:00 -to 00:02:30 -c copy output.mkv
undefined
ffmpeg -i input.mkv -ss 00:01:00 -to 00:02:30 -c copy output.mkv
undefined

Resources

资源