Communitygithub.com

Zuhair-01/claude-skills-and-systems

使用 FFmpeg 进行视频和音频处理。适用于格式转换、缩放、压缩、音频提取以及为 Remotion 准备素材。触发场景包括将 GIF 转换为 MP4、调整视频大小、提取音频、压缩文件或任何媒体转换任务。

claude-skills-and-systems 是什么?

该技能为 AI 代理(如 Claude Code、Cursor 等)提供了一套完整的 FFmpeg 视频与音频处理方案,专门针对 Remotion 视频项目优化。它覆盖了从基本格式转换(GIF 转 MP4、音频提取)、视频缩放、压缩到高级操作(变速、拼接、淡入淡出)的常用命令,并深入讲解了每个命令中关键参数(如 `-movflags faststart`、`-pix_fmt yuv420p`、CRF 值)的作用,以确保输出兼容性与质量。技能还特别包含了 Remotion 相关的模式,例如如何根据场景时长计算变速因子,并指导在 `playbackRate` 无法满足需求时改用 FFmpeg 预处理。此外,它提供了针对 YouTube、Twitter/X、LinkedIn 和网页嵌入等不同平台的视频优化设置、质量指南以及常见错误的修复方法,使代理能自动完成从源素材到多渠道分发的完整视频处理流水线。此技能支持所有安装了 FFmpeg 的开发环境,并提供了清晰的 bash 命令和批量导出脚本,便于集成到 CI/CD 工作流中。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Zuhair-01/claude-skills-and-systems/tree/HEAD/skills/ffmpeg

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

FFmpeg 视频制作指南

FFmpeg 是处理视频/音频的核心工具。本技能涵盖了 Remotion 视频项目中的常见操作。

快速参考

GIF 转 MP4(兼容 Remotion)

ffmpeg -i input.gif -movflags faststart -pix_fmt yuv420p \
  -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4

参数说明:

  • -movflags faststart - 将元数据移到文件开头,优化 Web 流式播放
  • -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

压缩视频

# 高质量,较小文件(CRF 23 为默认,数值越低画质越好)
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4

# 强力压缩,用于 Web 预览
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

Remotion 专用模式

为 Remotion 调整视频速度

何时使用 FFmpeg 与 Remotion 的 playbackRate:

场景使用 FFmpeg使用 Remotion
恒定速度(1.5x,2x)两者均可✅ 更简单
极端速度(>4x 或 <0.25x)✅ 更可靠可能有问题
变速(随时间加速)✅ 预处理需复杂变通方案
需要完美音频同步✅ 有保障通常没问题
演示需匹配配音时间✅ 预先计算运行时调整

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

计算速度因子:

  • 将 X 秒视频放入 Y 秒场景需要的速度:speed = X / Y
  • setpts 倍数 = 1 / speed(例如:3 倍速 = setpts=0.333*PTS)
  • atempo 值 = 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]"

为 Remotion 准备演示录制

# 标准 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

将屏幕录制转换为 Remotion 资源

# 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

批量转换 GIF

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

常见问题

"Height not divisible by 2"

添加缩放滤镜:-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预设说明
归档/母版18slow最佳质量,文件较大
成品输出20-22medium良好平衡
Web/预览23-25fast较小文件
草稿/快速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 会重新编码所有内容,因此上传高质量视频:

# 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/X

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

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

网站/嵌入(针对快速加载优化)

# 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 替代(更好压缩,更广泛的浏览器支持)
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(用于预览/缩略图)

# 高质量 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

平台要求快速参考

平台最大分辨率最大大小最大时长音频
YouTube8K256GB12 小时AAC 48kHz
Twitter/X1920x1200512MB140 秒AAC 44.1kHz
LinkedIn4096x23045GB10 分钟AAC 48kHz
Instagram Feed1080x13504GB60 秒AAC 48kHz
Instagram Reels1080x19204GB90 秒AAC 48kHz
TikTok1080x1920287MB10 分钟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

# Web 嵌入(较小)
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

错误处理

处理视频时的常见错误与修复:

# 检查 FFmpeg 是否成功
ffmpeg -i input.mp4 -c:v libx264 output.mp4 && echo "Success" || echo "Failed: check input file"

# 验证输出文件是否可播放
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

处理常见失败

错误原因修复
"No such file"输入路径错误检查路径,带空格时使用引号
"Invalid data"输入文件损坏重新下载或重新录制源文件
"height not divisible by 2"尺寸为奇数使用 trunc 添加 scale 滤镜
"encoder not found"缺少编解码器安装包含完整编解码器的 FFmpeg
Output 0 bytes静默失败检查完整 ffmpeg 输出以获取错误信息

反馈与贡献

如果此技能缺少信息或可以改进:

  • 缺少某个命令? 描述您需要的内容
  • 发现错误? 请告诉我哪里有问题
  • 想要贡献? 我可以帮助您:
    1. 使用改进内容更新此技能
    2. 创建一个 PR 到 github.com/digitalsamba/claude-code-video-toolkit

只需说 "improve this skill",我将指导您更新 .claude/skills/ffmpeg/SKILL.md。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

Zuhair-01/claude-skills-and-systems

Create AI avatar videos with precise control over avatars, voices, scripts, scenes, and backgrounds using HeyGen's v2 API. Use when: (1) Choosing a specific avatar and voice for a video, (2) Writing exact scripts for an avatar to speak, (3) Building multi-scene videos with different backgrounds per scene, (4) Creating transparent WebM videos for compositing, (5) Using talking photos as video presenters, (6) Integrating HeyGen avatars with Remotion, (7) Batch video generation with exact specs, (8) Brand-consistent production videos with precise control.

Zuhair-01/claude-skills-and-systems

Generate Mandarin and multilingual narration with Volcengine Doubao Speech 2.0. Use when creating Chinese voiceovers, when the user prefers Doubao/Volcengine/火山引擎/豆包 TTS, or when narration needs character-level timestamp metadata for subtitles.

Zuhair-01/claude-skills-and-systems

Edit existing videos using AI — remix style, upscale, remove background, and add audio via fal.ai's hosted video models.

Zuhair-01/claude-skills-and-systems

Author or edit a custom HyperFrames composition when no specialized workflow fits, or when BRIEF.md sets flow: companion. Use for longer or multi-scene pieces, brand and sizzle reels, montages, static loops, static title cards, footage remixes, and freeform builds. Use motion-graphics instead for a short unnarrated motion-first unit, including an animated title. Route fresh creation through hyperframes before using this skill.

Zuhair-01/claude-skills-and-systems

Read-only queue dashboard for workspace-aware ship. (gstack)

Zuhair-01/claude-skills-and-systems

Generate HeyGen presenter videos via the v3 Video Agent pipeline — handles Frame Check (aspect ratio correction), prompt engineering, avatar resolution, and voice selection. Required for any HeyGen video generation. Replaces deprecated endpoints with v3. Use when: (1) generating any HeyGen video (via API or otherwise), (2) sending a personalized video message (outreach, update, announcement, pitch, knowledge), (3) creating a HeyGen presenter-led explainer, tutorial, or product demo with a human face, (4) "make a video of me saying...", "send a video to my leads", "record an update for my team", "create a video pitch", "make a loom-style message", "I want to appear in this video", "generate a HeyGen video", "make a talking head video". Accepts avatar_id from heygen-avatar for identity-first HeyGen videos, or uses a stock presenter. Returns video share URL + HeyGen session URL for iteration. Chain signal: when the user wants to create/design an avatar AND make a video in the same request, run heygen-avatar f...

Zuhair-01/claude-skills-and-systems

All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.

Zuhair-01/claude-skills-and-systems

The HyperFrames composition contract — build one renderable project. Use for composition structure, the `data-*` timing attributes, `class="clip"`, tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.

Zuhair-01/claude-skills-and-systems

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

相关技能