video-edit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Video Edit

视频编辑

Edit videos locally by running ffmpeg/ffprobe directly. No wrapper scripts needed.
直接运行ffmpeg/ffprobe在本地编辑视频,无需包装脚本。

Prerequisites

前置条件

Install ffmpeg (includes ffprobe):
bash
undefined
安装ffmpeg(包含ffprobe):
bash
undefined

macOS

macOS

brew install ffmpeg
brew install ffmpeg

Ubuntu/Debian

Ubuntu/Debian

sudo apt update && sudo apt install -y ffmpeg
sudo apt update && sudo apt install -y ffmpeg

Verify

验证

ffmpeg -version && ffprobe -version
undefined
ffmpeg -version && ffprobe -version
undefined

Quick Reference

快速参考

Get video info

获取视频信息

bash
ffprobe -v quiet -print_format json -show_format -show_streams video.mp4
bash
ffprobe -v quiet -print_format json -show_format -show_streams video.mp4

Trim

修剪视频

bash
ffmpeg -y -ss 00:00:30 -to 00:01:45 -i video.mp4 -c copy trimmed.mp4
bash
ffmpeg -y -ss 00:00:30 -to 00:01:45 -i video.mp4 -c copy trimmed.mp4

Concatenate clips

拼接视频剪辑

bash
undefined
bash
undefined

1. Create a file list

1. 创建文件列表

printf "file '%s'\n" clip1.mp4 clip2.mp4 clip3.mp4 > list.txt
printf "file '%s'\n" clip1.mp4 clip2.mp4 clip3.mp4 > list.txt

2. Concat with stream copy

2. 流复制模式拼接

ffmpeg -y -f concat -safe 0 -i list.txt -c copy joined.mp4
undefined
ffmpeg -y -f concat -safe 0 -i list.txt -c copy joined.mp4
undefined

Resize for platform

为平台调整视频尺寸

bash
ffmpeg -y -i video.mp4 \
  -vf "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black" \
  -c:a copy tiktok.mp4
bash
ffmpeg -y -i video.mp4 \
  -vf "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black" \
  -c:a copy tiktok.mp4

Change speed

调整视频速度

bash
undefined
bash
undefined

2x faster

2倍速

ffmpeg -y -i video.mp4 -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" fast.mp4
ffmpeg -y -i video.mp4 -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" fast.mp4

0.5x (slow motion)

0.5倍速(慢动作)

ffmpeg -y -i video.mp4 -filter:v "setpts=2.0*PTS" -filter:a "atempo=0.5" slow.mp4
undefined
ffmpeg -y -i video.mp4 -filter:v "setpts=2.0*PTS" -filter:a "atempo=0.5" slow.mp4
undefined

Extract audio

提取音频

bash
ffmpeg -y -i video.mp4 -vn -acodec libmp3lame audio.mp3
bash
ffmpeg -y -i video.mp4 -vn -acodec libmp3lame audio.mp3

Replace audio

替换音频

bash
ffmpeg -y -i video.mp4 -i audio.mp3 -c:v copy -map 0:v:0 -map 1:a:0 -shortest output.mp4
bash
ffmpeg -y -i video.mp4 -i audio.mp3 -c:v copy -map 0:v:0 -map 1:a:0 -shortest output.mp4

Compress

压缩视频

bash
ffmpeg -y -i video.mp4 -crf 23 -preset medium -c:a copy compressed.mp4
bash
ffmpeg -y -i video.mp4 -crf 23 -preset medium -c:a copy compressed.mp4

Convert format

转换视频格式

bash
ffmpeg -y -i video.mov output.mp4
bash
ffmpeg -y -i video.mov output.mp4

Add image overlay

添加图片叠加层

bash
undefined
bash
undefined

Logo in top-right corner

右上角添加logo

ffmpeg -y -i video.mp4 -i logo.png
-filter_complex "overlay=W-w-10:10" -c:a copy watermarked.mp4
undefined
ffmpeg -y -i video.mp4 -i logo.png
-filter_complex "overlay=W-w-10:10" -c:a copy watermarked.mp4
undefined

Platform Presets

平台预设参数

PlatformResolutionScale + pad filter
TikTok1080 x 1920
scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black
YouTube1920 x 1080
scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black
Instagram1080 x 1350
scale=1080:1350:force_original_aspect_ratio=decrease,pad=1080:1350:(ow-iw)/2:(oh-ih)/2:black
Square1080 x 1080
scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:(ow-iw)/2:(oh-ih)/2:black
Twitter/X1920 x 1080
scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black
Use the filter with:
ffmpeg -y -i input.mp4 -vf "<filter>" -c:a copy output.mp4
平台分辨率缩放+填充滤镜
TikTok1080 x 1920
scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black
YouTube1920 x 1080
scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black
Instagram1080 x 1350
scale=1080:1350:force_original_aspect_ratio=decrease,pad=1080:1350:(ow-iw)/2:(oh-ih)/2:black
正方形格式1080 x 1080
scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:(ow-iw)/2:(oh-ih)/2:black
Twitter/X1920 x 1080
scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black
使用滤镜的命令格式:
ffmpeg -y -i input.mp4 -vf "<filter>" -c:a copy output.mp4

Tips

小贴士

  • Always use
    -y
    to overwrite output without prompting.
  • Use
    -c copy
    when you only need to cut/join (no re-encoding, very fast).
  • Lower CRF = better quality, larger file. Range 18-28 is typical; 23 is the default.
  • For detailed recipes and flag explanations, see
    references/operations.md
    .
  • 始终使用
    -y
    参数,无需确认即可覆盖输出文件。
  • 当仅需剪切/拼接视频时,使用
    -c copy
    参数(无需重新编码,速度极快)。
  • CRF值越低,视频质量越高,文件体积越大。常用范围是18-28,默认值为23。
  • 如需详细的操作指南和参数说明,请查看
    references/operations.md