ffmpeg

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

FFmpeg for Video Production

用于视频制作的FFmpeg

FFmpeg is the essential tool for video/audio processing. This skill covers common operations for Remotion video projects.
FFmpeg是音视频处理的必备工具。本技能涵盖了Remotion视频项目中的常见操作。

Quick Reference

快速参考

GIF to MP4 (Remotion-compatible)

GIF转MP4(兼容Remotion)

bash
ffmpeg -i input.gif -movflags faststart -pix_fmt yuv420p \
  -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4
Why these flags:
  • -movflags faststart
    - Moves metadata to start for web streaming
  • -pix_fmt yuv420p
    - Ensures compatibility with most players
  • scale=trunc(...)
    - Forces even dimensions (required by most codecs)
bash
ffmpeg -i input.gif -movflags faststart -pix_fmt yuv420p \
  -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4
这些参数的作用:
  • -movflags faststart
    - 将元数据移至文件开头,适合网络流式播放
  • -pix_fmt yuv420p
    - 确保与大多数播放器兼容
  • scale=trunc(...)
    - 强制使用偶数分辨率(大多数编解码器要求)

Resize Video

调整视频尺寸

bash
undefined
bash
undefined

To 1920x1080 (maintain aspect ratio, add black bars)

调整为1920x1080(保持宽高比,添加黑边)

ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" output.mp4
ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" output.mp4

To 1920x1080 (crop to fill)

调整为1920x1080(裁剪填充)

ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080" output.mp4
ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080" output.mp4

Scale to width, auto height

按宽度缩放,高度自动适配

ffmpeg -i input.mp4 -vf "scale=1280:-2" output.mp4
undefined
ffmpeg -i input.mp4 -vf "scale=1280:-2" output.mp4
undefined

Compress Video

压缩视频

bash
undefined
bash
undefined

Good quality, smaller file (CRF 23 is default, lower = better quality)

画质良好,文件较小(CRF 23为默认值,值越低画质越好)

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4

Aggressive compression for web preview

激进压缩,适用于网页预览

ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset fast -c:a aac -b:a 96k output.mp4
ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset fast -c:a aac -b:a 96k output.mp4

Target file size (e.g., ~10MB for 60s video = ~1.3Mbps)

目标文件大小(例如:60秒视频约10MB = 约1.3Mbps)

ffmpeg -i input.mp4 -c:v libx264 -b:v 1300k -c:a aac -b:a 128k output.mp4
undefined
ffmpeg -i input.mp4 -c:v libx264 -b:v 1300k -c:a aac -b:a 128k output.mp4
undefined

Extract Audio

提取音频

bash
undefined
bash
undefined

Extract to MP3

提取为MP3

ffmpeg -i input.mp4 -vn -acodec libmp3lame -q:a 2 output.mp3
ffmpeg -i input.mp4 -vn -acodec libmp3lame -q:a 2 output.mp3

Extract to AAC

提取为AAC

ffmpeg -i input.mp4 -vn -acodec aac -b:a 192k output.m4a
ffmpeg -i input.mp4 -vn -acodec aac -b:a 192k output.m4a

Extract to WAV (uncompressed)

提取为WAV(无压缩)

ffmpeg -i input.mp4 -vn output.wav
undefined
ffmpeg -i input.mp4 -vn output.wav
undefined

Convert Audio Formats

转换音频格式

bash
undefined
bash
undefined

M4A to MP3 (for ElevenLabs voice samples)

M4A转MP3(适用于ElevenLabs语音样本)

ffmpeg -i input.m4a -codec:a libmp3lame -qscale:a 2 output.mp3
ffmpeg -i input.m4a -codec:a libmp3lame -qscale:a 2 output.mp3

WAV to MP3

WAV转MP3

ffmpeg -i input.wav -codec:a libmp3lame -b:a 192k output.mp3
ffmpeg -i input.wav -codec:a libmp3lame -b:a 192k output.mp3

Adjust volume

调整音量

ffmpeg -i input.mp3 -filter:a "volume=1.5" output.mp3
undefined
ffmpeg -i input.mp3 -filter:a "volume=1.5" output.mp3
undefined

Trim/Cut Video

修剪/剪切视频

bash
undefined
bash
undefined

Cut from timestamp to duration (recommended - reliable)

从指定时间点开始剪切指定时长(推荐 - 可靠)

ffmpeg -i input.mp4 -ss 00:00:30 -t 00:00:15 -c:v libx264 -c:a aac output.mp4
ffmpeg -i input.mp4 -ss 00:00:30 -t 00:00:15 -c:v libx264 -c:a aac output.mp4

Cut from timestamp to timestamp

从开始时间点剪切到结束时间点

ffmpeg -i input.mp4 -ss 00:00:30 -to 00:00:45 -c:v libx264 -c:a aac output.mp4
ffmpeg -i input.mp4 -ss 00:00:30 -to 00:00:45 -c:v libx264 -c:a aac output.mp4

Stream copy (faster but may lose frames at cut points)

流复制(更快但可能在剪切点丢失帧)

Only use when source has frequent keyframes

仅在源文件有频繁关键帧时使用

ffmpeg -i input.mp4 -ss 00:00:30 -t 00:00:15 -c copy output.mp4

**Note:** Re-encoding is recommended for trimming. Stream copy (`-c copy`) can silently drop video if the seek point doesn't align with a keyframe.
ffmpeg -i input.mp4 -ss 00:00:30 -t 00:00:15 -c copy output.mp4

**注意:** 修剪视频建议使用重新编码。流复制(`-c copy`)如果搜索点与关键帧不匹配,可能会无声地丢失视频帧。

Speed Up / Slow Down

加速/减速

bash
undefined
bash
undefined

2x speed (video and audio)

2倍速(视频和音频同步)

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4

0.5x speed (slow motion)

0.5倍速(慢动作)

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" output.mp4
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" output.mp4

Video only (no audio)

仅视频加速(无音频)

ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -an output.mp4
undefined
ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -an output.mp4
undefined

Concatenate Videos

拼接视频

bash
undefined
bash
undefined

Create file list

创建文件列表

echo "file 'clip1.mp4'" > list.txt echo "file 'clip2.mp4'" >> list.txt echo "file 'clip3.mp4'" >> list.txt
echo "file 'clip1.mp4'" > list.txt echo "file 'clip2.mp4'" >> list.txt echo "file 'clip3.mp4'" >> list.txt

Concatenate (same codec/resolution)

拼接视频(相同编解码器/分辨率)

ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4

Concatenate with re-encoding (different sources)

拼接视频并重新编码(不同源文件)

ffmpeg -f concat -safe 0 -i list.txt -c:v libx264 -c:a aac output.mp4
undefined
ffmpeg -f concat -safe 0 -i list.txt -c:v libx264 -c:a aac output.mp4
undefined

Add Fade In/Out

添加淡入/淡出效果

bash
undefined
bash
undefined

Fade in first 1 second, fade out last 1 second (30fps video)

前1秒淡入,最后1秒淡出(30fps视频)

ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=1,fade=t=out:st=9:d=1" -c:a copy output.mp4
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=1,fade=t=out:st=9:d=1" -c:a copy output.mp4

Audio fade

音频淡入淡出

ffmpeg -i input.mp4 -af "afade=t=in:st=0:d=1,afade=t=out:st=9:d=1" -c:v copy output.mp4
undefined
ffmpeg -i input.mp4 -af "afade=t=in:st=0:d=1,afade=t=out:st=9:d=1" -c:v copy output.mp4
undefined

Get Video Info

获取视频信息

bash
undefined
bash
undefined

Duration, resolution, codec info

时长、分辨率、编解码器信息

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4

Full info

完整信息

ffprobe -v quiet -print_format json -show_format -show_streams input.mp4
undefined
ffprobe -v quiet -print_format json -show_format -show_streams input.mp4
undefined

Remotion-Specific Patterns

Remotion特定模式

Video Speed Adjustment for Remotion

用于Remotion的视频速度调整

When to use FFmpeg vs Remotion
playbackRate
:
ScenarioUse FFmpegUse Remotion
Constant speed (1.5x, 2x)Either works✅ Simpler
Extreme speeds (>4x or <0.25x)✅ More reliableMay have issues
Variable speed (accelerate over time)✅ Pre-processComplex workaround needed
Need perfect audio sync✅ GuaranteedUsually fine
Demo needs to fit voiceover timing✅ Pre-calculateRuntime adjustment
Remotion limitation:
playbackRate
must be constant. Dynamic interpolation like
playbackRate={interpolate(frame, [0, 100], [1, 5])}
won't work correctly because Remotion evaluates frames independently.
bash
undefined
何时使用FFmpeg vs Remotion
playbackRate
场景使用FFmpeg使用Remotion
恒定速度(1.5x、2x)两者均可✅ 更简单
极端速度(>4x或<0.25x)✅ 更可靠可能出现问题
变速(随时间加速)✅ 预处理需要复杂的解决方案
需要完美的音频同步✅ 有保障通常没问题
演示视频需要匹配旁白时长✅ 预先计算运行时调整
Remotion限制:
playbackRate
必须为恒定值。动态插值如
playbackRate={interpolate(frame, [0, 100], [1, 5])}
无法正常工作,因为Remotion会独立计算每一帧。
bash
undefined

Speed up demo to fit a scene (e.g., 60s demo into 20s = 3x speed)

加速演示视频以适配场景(例如:60秒演示压缩到20秒 = 3倍速)

ffmpeg -i demo-raw.mp4
-filter_complex "[0:v]setpts=0.333*PTS[v];[0:a]atempo=3.0[a]"
-map "[v]" -map "[a]"
public/demos/demo-fast.mp4
ffmpeg -i demo-raw.mp4
-filter_complex "[0:v]setpts=0.333*PTS[v];[0:a]atempo=3.0[a]"
-map "[v]" -map "[a]"
public/demos/demo-fast.mp4

Slow motion for emphasis (0.5x speed)

慢动作强调效果(0.5倍速)

ffmpeg -i action.mp4
-filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]"
-map "[v]" -map "[a]"
public/demos/action-slow.mp4
ffmpeg -i action.mp4
-filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]"
-map "[v]" -map "[a]"
public/demos/action-slow.mp4

Speed up without audio (common for screen recordings)

仅加速视频(无音频,适用于屏幕录制)

ffmpeg -i demo.mp4 -filter:v "setpts=0.5*PTS" -an public/demos/demo-2x.mp4
ffmpeg -i demo.mp4 -filter:v "setpts=0.5*PTS" -an public/demos/demo-2x.mp4

Timelapse effect (10x speed, drop audio)

延时摄影效果(10倍速,移除音频)

ffmpeg -i long-demo.mp4 -filter:v "setpts=0.1*PTS" -an public/demos/timelapse.mp4

**Calculate speed factor:**
- To fit X seconds of video into Y seconds of scene: `speed = X / Y`
- setpts multiplier = `1 / speed` (e.g., 3x speed = setpts=0.333*PTS)
- atempo value = `speed` (e.g., 3x speed = atempo=3.0)

**Extreme speed (>2x audio):** Chain atempo filters (each limited to 0.5-2.0 range):
```bash
ffmpeg -i long-demo.mp4 -filter:v "setpts=0.1*PTS" -an public/demos/timelapse.mp4

**计算速度系数:**
- 要将X秒的视频适配到Y秒的场景:`speed = X / Y`
- setpts乘数 = `1 / speed`(例如:3倍速 = setpts=0.333*PTS)
- atempo值 = `speed`(例如:3倍速 = atempo=3.0)

**极端速度(音频>2x):** 链式使用atempo过滤器(每个过滤器限制在0.5-2.0范围内):
```bash

4x speed audio

4倍速音频

-filter_complex "[0:a]atempo=2.0,atempo=2.0[a]"
-filter_complex "[0:a]atempo=2.0,atempo=2.0[a]"

8x speed audio

8倍速音频

-filter_complex "[0:a]atempo=2.0,atempo=2.0,atempo=2.0[a]"
undefined
-filter_complex "[0:a]atempo=2.0,atempo=2.0,atempo=2.0[a]"
undefined

Prepare Demo Recording for Remotion

为Remotion准备演示录制视频

bash
undefined
bash
undefined

Standard 1080p, 30fps, Remotion-ready

标准1080p、30fps,兼容Remotion

ffmpeg -i raw-recording.mp4
-vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,fps=30"
-c:v libx264 -crf 18 -preset slow
-c:a aac -b:a 192k
-movflags faststart
public/demos/demo.mp4
undefined
ffmpeg -i raw-recording.mp4
-vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,fps=30"
-c:v libx264 -crf 18 -preset slow
-c:a aac -b:a 192k
-movflags faststart
public/demos/demo.mp4
undefined

Screen Recording to Remotion Asset

屏幕录制转Remotion素材

bash
undefined
bash
undefined

From iPhone/iPad recording (usually 60fps, variable resolution)

从iPhone/iPad录制视频转换(通常为60fps,可变分辨率)

ffmpeg -i iphone-recording.mov
-vf "scale=1920:-2,fps=30"
-c:v libx264 -crf 20
-an
public/demos/mobile-demo.mp4
undefined
ffmpeg -i iphone-recording.mov
-vf "scale=1920:-2,fps=30"
-c:v libx264 -crf 20
-an
public/demos/mobile-demo.mp4
undefined

Batch Convert GIFs

批量转换GIF

bash
for f in assets/*.gif; do
  ffmpeg -i "$f" -movflags faststart -pix_fmt yuv420p \
    -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \
    "public/demos/$(basename "$f" .gif).mp4"
done
bash
for f in assets/*.gif; do
  ffmpeg -i "$f" -movflags faststart -pix_fmt yuv420p \
    -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \
    "public/demos/$(basename "$f" .gif).mp4"
done

Common Issues

常见问题

"Height not divisible by 2"

"Height not divisible by 2"

Add scale filter:
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"
添加缩放过滤器:
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"

Video won't play in browser

视频无法在浏览器中播放

Use:
-movflags faststart -pix_fmt yuv420p -c:v libx264
使用参数:
-movflags faststart -pix_fmt yuv420p -c:v libx264

Audio out of sync after speed change

速度调整后音频不同步

Use filter_complex with atempo:
-filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]"
使用filter_complex和atempo:
-filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]"

File too large

文件过大

Increase CRF (23→28) or reduce resolution
提高CRF值(23→28)或降低分辨率

Quality Guidelines

质量指南

Use CaseCRFPresetNotes
Archive/Master18slowBest quality, large files
Production20-22mediumGood balance
Web/Preview23-25fastSmaller files
Draft/Quick28+veryfastFast encoding
使用场景CRFPreset说明
存档/母版18slow最佳画质,文件较大
生产环境20-22medium平衡画质与文件大小
网页/预览23-25fast文件更小
草稿/快速处理28+veryfast编码速度快

Platform-Specific Output Optimization

特定平台输出优化

After Remotion renders your video (typically to
out/video.mp4
), use FFmpeg to optimize for each distribution platform.
Remotion渲染视频后(通常输出为
out/video.mp4
),使用FFmpeg针对每个分发平台进行优化。

Workflow Integration

工作流集成

Remotion render (master)     FFmpeg optimization      Platform upload
       ↓                            ↓                       ↓
   out/video.mp4  ────────→  out/video-youtube.mp4  ───→  YouTube
                  ────────→  out/video-twitter.mp4  ───→  Twitter/X
                  ────────→  out/video-linkedin.mp4 ───→  LinkedIn
                  ────────→  out/video-web.mp4      ───→  Website embed
Remotion渲染(母版)     FFmpeg优化      平台上传
       ↓                            ↓                       ↓
   out/video.mp4  ────────→  out/video-youtube.mp4  ───→  YouTube
                  ────────→  out/video-twitter.mp4  ───→  Twitter/X
                  ────────→  out/video-linkedin.mp4 ───→  LinkedIn
                  ────────→  out/video-web.mp4      ───→  网站嵌入

YouTube (Recommended Settings)

YouTube(推荐设置)

YouTube re-encodes everything, so upload high quality:
bash
undefined
YouTube会重新编码所有视频,因此上传高质量版本:
bash
undefined

YouTube optimized (1080p)

优化YouTube(1080p)

ffmpeg -i out/video.mp4
-c:v libx264 -preset slow -crf 18
-profile:v high -level 4.0
-bf 2 -g 30
-c:a aac -b:a 192k -ar 48000
-movflags +faststart
out/video-youtube.mp4
ffmpeg -i out/video.mp4
-c:v libx264 -preset slow -crf 18
-profile:v high -level 4.0
-bf 2 -g 30
-c:a aac -b:a 192k -ar 48000
-movflags +faststart
out/video-youtube.mp4

YouTube Shorts (vertical 1080x1920)

YouTube Shorts(竖屏1080x1920)

ffmpeg -i out/video.mp4
-vf "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2"
-c:v libx264 -crf 18 -c:a aac -b:a 192k
out/video-shorts.mp4
undefined
ffmpeg -i out/video.mp4
-vf "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2"
-c:v libx264 -crf 18 -c:a aac -b:a 192k
out/video-shorts.mp4
undefined

Twitter/X

Twitter/X

Twitter has strict limits: max 140s, 512MB, 1920x1200:
bash
undefined
Twitter有严格限制:最大140秒,512MB,1920x1200:
bash
undefined

Twitter optimized (under 15MB target for fast upload)

优化Twitter(目标文件小于15MB,便于快速上传)

ffmpeg -i out/video.mp4
-c:v libx264 -preset medium -crf 24
-profile:v main -level 3.1
-vf "scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease"
-c:a aac -b:a 128k -ar 44100
-movflags +faststart
-fs 15M
out/video-twitter.mp4
ffmpeg -i out/video.mp4
-c:v libx264 -preset medium -crf 24
-profile:v main -level 3.1
-vf "scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease"
-c:a aac -b:a 128k -ar 44100
-movflags +faststart
-fs 15M
out/video-twitter.mp4

Check file size and duration

检查文件大小和时长

ffprobe -v error -show_entries format=duration,size -of csv=p=0 out/video-twitter.mp4
undefined
ffprobe -v error -show_entries format=duration,size -of csv=p=0 out/video-twitter.mp4
undefined

LinkedIn

LinkedIn

LinkedIn prefers MP4 with AAC audio, max 10 minutes:
bash
undefined
LinkedIn偏好带AAC音频的MP4,最大10分钟:
bash
undefined

LinkedIn optimized

优化LinkedIn

ffmpeg -i out/video.mp4
-c:v libx264 -preset medium -crf 22
-profile:v main
-vf "scale='min(1920,iw)':'min(1080,ih)':force_original_aspect_ratio=decrease"
-c:a aac -b:a 192k -ar 48000
-movflags +faststart
out/video-linkedin.mp4
undefined
ffmpeg -i out/video.mp4
-c:v libx264 -preset medium -crf 22
-profile:v main
-vf "scale='min(1920,iw)':'min(1080,ih)':force_original_aspect_ratio=decrease"
-c:a aac -b:a 192k -ar 48000
-movflags +faststart
out/video-linkedin.mp4
undefined

Website/Embed (Optimized for Fast Loading)

网站/嵌入(优化加载速度)

bash
undefined
bash
undefined

Web-optimized MP4 (small file, progressive loading)

网页优化MP4(文件小,支持渐进式加载)

ffmpeg -i out/video.mp4
-c:v libx264 -preset medium -crf 26
-profile:v baseline -level 3.0
-vf "scale=1280:720"
-c:a aac -b:a 128k
-movflags +faststart
out/video-web.mp4
ffmpeg -i out/video.mp4
-c:v libx264 -preset medium -crf 26
-profile:v baseline -level 3.0
-vf "scale=1280:720"
-c:a aac -b:a 128k
-movflags +faststart
out/video-web.mp4

WebM alternative (better compression, wider browser support)

WebM替代方案(压缩更好,浏览器支持广泛)

ffmpeg -i out/video.mp4
-c:v libvpx-vp9 -crf 30 -b:v 0
-vf "scale=1280:720"
-c:a libopus -b:a 128k
-deadline good
out/video-web.webm
undefined
ffmpeg -i out/video.mp4
-c:v libvpx-vp9 -crf 30 -b:v 0
-vf "scale=1280:720"
-c:a libopus -b:a 128k
-deadline good
out/video-web.webm
undefined

GIF (for Previews/Thumbnails)

GIF(用于预览/缩略图)

bash
undefined
bash
undefined

High-quality GIF (first 5 seconds)

高质量GIF(前5秒)

ffmpeg -i out/video.mp4 -t 5
-vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"
out/preview.gif
ffmpeg -i out/video.mp4 -t 5
-vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"
out/preview.gif

Smaller file GIF

小文件GIF

ffmpeg -i out/video.mp4 -t 3
-vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"
out/preview-small.gif
undefined
ffmpeg -i out/video.mp4 -t 3
-vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"
out/preview-small.gif
undefined

Platform Requirements Quick Reference

平台要求快速参考

PlatformMax ResolutionMax SizeMax DurationAudio
YouTube8K256GB12 hoursAAC 48kHz
Twitter/X1920x1200512MB140sAAC 44.1kHz
LinkedIn4096x23045GB10 minAAC 48kHz
Instagram Feed1080x13504GB60sAAC 48kHz
Instagram Reels1080x19204GB90sAAC 48kHz
TikTok1080x1920287MB10 minAAC
平台最大分辨率最大文件大小最大时长音频要求
YouTube8K256GB12小时AAC 48kHz
Twitter/X1920x1200512MB140秒AAC 44.1kHz
LinkedIn4096x23045GB10分钟AAC 48kHz
Instagram Feed1080x13504GB60秒AAC 48kHz
Instagram Reels1080x19204GB90秒AAC 48kHz
TikTok1080x1920287MB10分钟AAC

Batch Export for All Platforms

批量导出至所有平台

bash
#!/bin/bash
bash
#!/bin/bash

save as: export-all-platforms.sh

保存为: export-all-platforms.sh

INPUT="out/video.mp4"
INPUT="out/video.mp4"

YouTube (high quality)

YouTube(高质量)

ffmpeg -i "$INPUT" -c:v libx264 -preset slow -crf 18
-c:a aac -b:a 192k -movflags +faststart
out/video-youtube.mp4
ffmpeg -i "$INPUT" -c:v libx264 -preset slow -crf 18
-c:a aac -b:a 192k -movflags +faststart
out/video-youtube.mp4

Twitter (compressed)

Twitter(压缩版)

ffmpeg -i "$INPUT" -c:v libx264 -crf 24
-vf "scale='min(1280,iw)':'-2'"
-c:a aac -b:a 128k -movflags +faststart
out/video-twitter.mp4
ffmpeg -i "$INPUT" -c:v libx264 -crf 24
-vf "scale='min(1280,iw)':'-2'"
-c:a aac -b:a 128k -movflags +faststart
out/video-twitter.mp4

LinkedIn

LinkedIn

ffmpeg -i "$INPUT" -c:v libx264 -crf 22
-c:a aac -b:a 192k -movflags +faststart
out/video-linkedin.mp4
ffmpeg -i "$INPUT" -c:v libx264 -crf 22
-c:a aac -b:a 192k -movflags +faststart
out/video-linkedin.mp4

Web embed (small)

网页嵌入(小文件)

ffmpeg -i "$INPUT" -c:v libx264 -crf 26
-vf "scale=1280:720"
-c:a aac -b:a 128k -movflags +faststart
out/video-web.mp4
echo "Exported:" ls -lh out/video-*.mp4
undefined
ffmpeg -i "$INPUT" -c:v libx264 -crf 26
-vf "scale=1280:720"
-c:a aac -b:a 128k -movflags +faststart
out/video-web.mp4
echo "导出完成:" ls -lh out/video-*.mp4
undefined

Error Handling

错误处理

Common errors and fixes when processing video:
bash
undefined
处理视频时的常见错误及修复方法:
bash
undefined

Check if FFmpeg succeeded

检查FFmpeg是否执行成功

ffmpeg -i input.mp4 -c:v libx264 output.mp4 && echo "Success" || echo "Failed: check input file"
ffmpeg -i input.mp4 -c:v libx264 output.mp4 && echo "成功" || echo "失败: 检查输入文件"

Validate output file is playable

验证输出文件是否可播放

ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of csv=p=0 output.mp4
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of csv=p=0 output.mp4

Get detailed error info

获取详细错误信息

ffmpeg -v error -i input.mp4 -f null - 2>&1 | head -20
undefined
ffmpeg -v error -i input.mp4 -f null - 2>&1 | head -20
undefined

Handling Common Failures

处理常见故障

ErrorCauseFix
"No such file"Input path wrongCheck path, use quotes for spaces
"Invalid data"Corrupted inputRe-download or re-record source
"height not divisible by 2"Odd dimensionsAdd scale filter with trunc
"encoder not found"Missing codecInstall FFmpeg with full codecs
Output 0 bytesSilent failureCheck full ffmpeg output for errors

错误原因修复方法
"No such file"输入路径错误检查路径,带空格的路径使用引号
"Invalid data"输入文件损坏重新下载或重新录制源文件
"height not divisible by 2"分辨率为奇数添加带trunc的缩放过滤器
"encoder not found"缺少编解码器安装带完整编解码器的FFmpeg版本
输出文件为0字节静默失败查看FFmpeg完整输出信息排查错误

Feedback & Contributions

反馈与贡献

If this skill is missing information or could be improved:
  • Missing a command? Describe what you needed
  • Found an error? Let me know what's wrong
  • Want to contribute? I can help you:
    1. Update this skill with improvements
    2. Create a PR to github.com/digitalsamba/claude-code-video-toolkit
Just say "improve this skill" and I'll guide you through updating
.claude/skills/ffmpeg/SKILL.md
.
如果本技能缺少某些信息或可以改进:
  • 缺少某个命令? 描述您的需求
  • 发现错误? 告知问题所在
  • 想要贡献? 我可以帮助您:
    1. 更新本技能的内容
    2. 向github.com/digitalsamba/claude-code-video-toolkit提交PR
只需说“改进本技能”,我将引导您更新
.claude/skills/ffmpeg/SKILL.md