ffmpeg by digitalsamba/claude-code-video-toolkit
npx skills add https://github.com/digitalsamba/claude-code-video-toolkit --skill ffmpegFFmpeg 是视频/音频处理的核心工具。本技能涵盖 Remotion 视频项目的常见操作。
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(...) - 强制使用偶数尺寸(大多数编解码器要求)# 调整为 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
# 调整为 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=1280:-2" output.mp4
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 良好质量,较小文件(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 28 -preset fast -c:a aac -b:a 96k output.mp4
# 目标文件大小(例如,60秒视频约10MB = 约1.3Mbps)
ffmpeg -i input.mp4 -c:v libx264 -b:v 1300k -c:a aac -b:a 128k output.mp4
# 提取为 MP3
ffmpeg -i input.mp4 -vn -acodec libmp3lame -q:a 2 output.mp3
# 提取为 AAC
ffmpeg -i input.mp4 -vn -acodec aac -b:a 192k output.m4a
# 提取为 WAV(未压缩)
ffmpeg -i input.mp4 -vn output.wav
# M4A 转 MP3(适用于 ElevenLabs 语音样本)
ffmpeg -i input.m4a -codec:a libmp3lame -qscale:a 2 output.mp3
# WAV 转 MP3
ffmpeg -i input.wav -codec:a libmp3lame -b:a 192k output.mp3
# 调整音量
ffmpeg -i input.mp3 -filter:a "volume=1.5" output.mp3
# 从时间戳开始剪切指定时长(推荐 - 可靠)
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 -to 00:00:45 -c:v libx264 -c:a aac output.mp4
# 流复制(更快,但可能在剪切点丢失帧)
# 仅在源文件有频繁关键帧时使用
ffmpeg -i input.mp4 -ss 00:00:30 -t 00:00:15 -c copy output.mp4
注意: 建议重新编码进行裁剪。流复制(-c copy)在搜索点未对齐关键帧时可能会静默丢弃视频。
# 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
# 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:v "setpts=0.5*PTS" -an output.mp4
# 创建文件列表
echo "file 'clip1.mp4'" > list.txt
echo "file 'clip2.mp4'" >> list.txt
echo "file 'clip3.mp4'" >> list.txt
# 合并(相同编解码器/分辨率)
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
# 重新编码合并(不同来源)
ffmpeg -f concat -safe 0 -i list.txt -c:v libx264 -c:a aac output.mp4
# 前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 -af "afade=t=in:st=0:d=1,afade=t=out:st=9:d=1" -c:v copy output.mp4
# 时长、分辨率、编解码器信息
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
# 完整信息
ffprobe -v quiet -print_format json -show_format -show_streams input.mp4
何时使用 FFmpeg 与 RemotionplaybackRate:
| 场景 | 使用 FFmpeg | 使用 Remotion |
|---|---|---|
| 恒定速度(1.5倍、2倍) | 两者皆可 | ✅ 更简单 |
| 极端速度(>4倍 或 <0.25倍) | ✅ 更可靠 | 可能有问题 |
| 可变速度(随时间加速) | ✅ 预处理 | 需要复杂变通方案 |
| 需要完美音频同步 | ✅ 有保证 | 通常没问题 |
| 演示需要匹配旁白时间 | ✅ 预先计算 | 运行时调整 |
Remotion 限制: playbackRate 必须是常量。像 playbackRate={interpolate(frame, [0, 100], [1, 5])} 这样的动态插值无法正确工作,因为 Remotion 独立评估每一帧。
# 加速演示以适应场景(例如,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
# 强调慢动作(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 demo.mp4 -filter:v "setpts=0.5*PTS" -an public/demos/demo-2x.mp4
# 延时摄影效果(10倍速,丢弃音频)
ffmpeg -i long-demo.mp4 -filter:v "setpts=0.1*PTS" -an public/demos/timelapse.mp4
计算速度因子:
speed = X / Y1 / speed(例如,3倍速 = setpts=0.333*PTS)speed(例如,3倍速 = atempo=3.0)极端速度(>2倍音频): 链接 atempo 过滤器(每个限制在 0.5-2.0 范围内):
# 4倍速音频
-filter_complex "[0:a]atempo=2.0,atempo=2.0[a]"
# 8倍速音频
-filter_complex "[0:a]atempo=2.0,atempo=2.0,atempo=2.0[a]"
# 标准 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
# 从 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
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
添加缩放过滤器:-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"
使用:-movflags faststart -pix_fmt yuv420p -c:v libx264
使用带 atempo 的 filter_complex:-filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]"
增加 CRF(23→28)或降低分辨率
| 使用场景 | CRF | Preset | 说明 |
|---|---|---|---|
| 存档/母版 | 18 | slow | 最佳质量,文件较大 |
| 生产 | 20-22 | medium | 良好平衡 |
| 网页/预览 | 23-25 | fast | 较小文件 |
| 草稿/快速 | 28+ | veryfast | 快速编码 |
在 Remotion 渲染视频后(通常到 out/video.mp4),使用 FFmpeg 为每个分发平台进行优化。
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 会重新编码所有内容,因此上传高质量文件:
# 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
# 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
Twitter 有严格限制:最长 140 秒,512MB,1920x1200:
# 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
# 检查文件大小和时长
ffprobe -v error -show_entries format=duration,size -of csv=p=0 out/video-twitter.mp4
LinkedIn 偏好 MP4 格式和 AAC 音频,最长 10 分钟:
# 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
# 网页优化 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 替代方案(更好压缩,更广泛浏览器支持)
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
# 高质量 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
# 较小文件 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
| 平台 | 最大分辨率 | 最大大小 | 最大时长 | 音频 |
|---|---|---|---|---|
| YouTube | 8K | 256GB | 12 小时 | AAC 48kHz |
| Twitter/X | 1920x1200 | 512MB | 140秒 | AAC 44.1kHz |
| 4096x2304 | 5GB | 10 分钟 | AAC 48kHz | |
| Instagram Feed | 1080x1350 | 4GB | 60秒 | AAC 48kHz |
| Instagram Reels | 1080x1920 | 4GB | 90秒 | AAC 48kHz |
| TikTok | 1080x1920 | 287MB | 10 分钟 | AAC |
#!/bin/bash
# 保存为:export-all-platforms.sh
INPUT="out/video.mp4"
# YouTube(高质量)
ffmpeg -i "$INPUT" -c:v libx264 -preset slow -crf 18 \
-c:a aac -b:a 192k -movflags +faststart \
out/video-youtube.mp4
# 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
# 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 26 \
-vf "scale=1280:720" \
-c:a aac -b:a 128k -movflags +faststart \
out/video-web.mp4
echo "已导出:"
ls -lh out/video-*.mp4
处理视频时的常见错误和修复方法:
# 检查 FFmpeg 是否成功
ffmpeg -i input.mp4 -c:v libx264 output.mp4 && echo "成功" || echo "失败:检查输入文件"
# 验证输出文件可播放
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of csv=p=0 output.mp4
# 获取详细错误信息
ffmpeg -v error -i input.mp4 -f null - 2>&1 | head -20
| 错误 | 原因 | 修复方法 |
|---|---|---|
| "没有此文件" | 输入路径错误 | 检查路径,路径有空格时使用引号 |
| "无效数据" | 输入文件损坏 | 重新下载或重新录制源文件 |
| "高度不能被 2 整除" | 奇数尺寸 | 添加带 trunc 的缩放过滤器 |
| "找不到编码器" | 缺少编解码器 | 安装完整编解码器的 FFmpeg |
| 输出 0 字节 | 静默失败 | 检查完整 ffmpeg 输出以查找错误 |
如果本技能缺少信息或可以改进:
只需说"改进此技能",我将指导您更新 .claude/skills/ffmpeg/SKILL.md。
每周安装
1.6K
仓库
GitHub 星标
140
首次出现
Jan 23, 2026
安全审计
安装于
opencode1.5K
gemini-cli1.4K
codex1.4K
github-copilot1.3K
cursor1.3K
kimi-cli1.2K
FFmpeg is the essential tool for video/audio processing. This skill covers common operations for Remotion video projects.
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 playersscale=trunc(...) - Forces even dimensions (required by most codecs)# To 1920x1080 (maintain aspect ratio, add black bars)
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)
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
# Good quality, smaller file (CRF 23 is default, lower = better quality)
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
# Target file size (e.g., ~10MB for 60s video = ~1.3Mbps)
ffmpeg -i input.mp4 -c:v libx264 -b:v 1300k -c:a aac -b:a 128k output.mp4
# Extract to MP3
ffmpeg -i input.mp4 -vn -acodec libmp3lame -q:a 2 output.mp3
# Extract to AAC
ffmpeg -i input.mp4 -vn -acodec aac -b:a 192k output.m4a
# Extract to WAV (uncompressed)
ffmpeg -i input.mp4 -vn output.wav
# M4A to MP3 (for ElevenLabs voice samples)
ffmpeg -i input.m4a -codec:a libmp3lame -qscale:a 2 output.mp3
# WAV to 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
# 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
# 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
# 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.
# 2x speed (video and audio)
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)
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
# Create file list
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
# Concatenate with re-encoding (different sources)
ffmpeg -f concat -safe 0 -i list.txt -c:v libx264 -c:a aac output.mp4
# Fade in first 1 second, fade out last 1 second (30fps video)
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
# Duration, resolution, codec info
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
When to use FFmpeg vs RemotionplaybackRate:
| Scenario | Use FFmpeg | Use Remotion |
|---|---|---|
| Constant speed (1.5x, 2x) | Either works | ✅ Simpler |
| Extreme speeds (>4x or <0.25x) | ✅ More reliable | May have issues |
| Variable speed (accelerate over time) | ✅ Pre-process | Complex workaround needed |
| Need perfect audio sync | ✅ Guaranteed | Usually fine |
| Demo needs to fit voiceover timing | ✅ Pre-calculate | Runtime 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.
# Speed up demo to fit a scene (e.g., 60s demo into 20s = 3x speed)
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)
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
# Timelapse effect (10x speed, drop audio)
ffmpeg -i long-demo.mp4 -filter:v "setpts=0.1*PTS" -an public/demos/timelapse.mp4
Calculate speed factor:
speed = X / Y1 / speed (e.g., 3x speed = setpts=0.333*PTS)speed (e.g., 3x speed = atempo=3.0)Extreme speed ( >2x audio): Chain atempo filters (each limited to 0.5-2.0 range):
# 4x speed audio
-filter_complex "[0:a]atempo=2.0,atempo=2.0[a]"
# 8x speed audio
-filter_complex "[0:a]atempo=2.0,atempo=2.0,atempo=2.0[a]"
# Standard 1080p, 30fps, Remotion-ready
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
# From iPhone/iPad recording (usually 60fps, variable resolution)
ffmpeg -i iphone-recording.mov \
-vf "scale=1920:-2,fps=30" \
-c:v libx264 -crf 20 \
-an \
public/demos/mobile-demo.mp4
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
Add scale filter: -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"
Use: -movflags faststart -pix_fmt yuv420p -c:v libx264
Use filter_complex with atempo: -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]"
Increase CRF (23→28) or reduce resolution
| Use Case | CRF | Preset | Notes |
|---|---|---|---|
| Archive/Master | 18 | slow | Best quality, large files |
| Production | 20-22 | medium | Good balance |
| Web/Preview | 23-25 | fast | Smaller files |
| Draft/Quick | 28+ | veryfast | Fast encoding |
After Remotion renders your video (typically to out/video.mp4), use FFmpeg to optimize for each distribution platform.
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
YouTube re-encodes everything, so upload high quality:
# YouTube optimized (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
# YouTube Shorts (vertical 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
Twitter has strict limits: max 140s, 512MB, 1920x1200:
# Twitter optimized (under 15MB target for fast upload)
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
LinkedIn prefers MP4 with AAC audio, max 10 minutes:
# LinkedIn optimized
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
# Web-optimized MP4 (small file, progressive loading)
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)
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
# High-quality GIF (first 5 seconds)
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
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
| Platform | Max Resolution | Max Size | Max Duration | Audio |
|---|---|---|---|---|
| YouTube | 8K | 256GB | 12 hours | AAC 48kHz |
| Twitter/X | 1920x1200 | 512MB | 140s | AAC 44.1kHz |
| 4096x2304 | 5GB | 10 min | AAC 48kHz | |
| Instagram Feed | 1080x1350 | 4GB | 60s | AAC 48kHz |
| Instagram Reels | 1080x1920 | 4GB | 90s | AAC 48kHz |
| TikTok | 1080x1920 | 287MB |
#!/bin/bash
# save as: export-all-platforms.sh
INPUT="out/video.mp4"
# YouTube (high quality)
ffmpeg -i "$INPUT" -c:v libx264 -preset slow -crf 18 \
-c:a aac -b:a 192k -movflags +faststart \
out/video-youtube.mp4
# Twitter (compressed)
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
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
Common errors and fixes when processing video:
# Check if FFmpeg succeeded
ffmpeg -i input.mp4 -c:v libx264 output.mp4 && echo "Success" || echo "Failed: check input file"
# Validate output file is playable
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
| Error | Cause | Fix |
|---|---|---|
| "No such file" | Input path wrong | Check path, use quotes for spaces |
| "Invalid data" | Corrupted input | Re-download or re-record source |
| "height not divisible by 2" | Odd dimensions | Add scale filter with trunc |
| "encoder not found" | Missing codec | Install FFmpeg with full codecs |
| Output 0 bytes | Silent failure | Check full ffmpeg output for errors |
If this skill is missing information or could be improved:
Just say "improve this skill" and I'll guide you through updating .claude/skills/ffmpeg/SKILL.md.
Weekly Installs
1.6K
Repository
GitHub Stars
140
First Seen
Jan 23, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode1.5K
gemini-cli1.4K
codex1.4K
github-copilot1.3K
cursor1.3K
kimi-cli1.2K
99,500 周安装
| 10 min |
| AAC |