Communitygithub.com

9018/mychat

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

mychat 是什么?

该技能提供了一个全面的 FFmpeg 参考指南,专为视频制作和 Remotion 项目优化。它涵盖了从基础转换(如 GIF 到 MP4)到高级工作流(如针对 YouTube、Twitter、LinkedIn 和 Web 的平台特定输出优化)的所有内容。技能中包含的命令经过精心挑选,以确保与 Remotion 兼容(例如,使用 `-movflags faststart` 和 `yuv420p` 像素格式),并包括常见的故障排除技巧。对于开发者来说,它解决了在 Remotion 中处理视频速度的关键限制,提供了何时使用 FFmpeg 预处理与 Remotion 的 `playbackRate` 属性的明确指导,特别是对于恒定速度、极端速度变化或需要完美音频同步的场景。它还包含用于提取视频信息、批量转换以及为不同平台(包括 Twitter/X 的严格文件大小限制和 YouTube 的推荐编码设置)导出最终渲染视频的实用脚本。该技能以 SKILL.md 格式呈现,可以在任何支持 Claude Code 技能的环境中直接使用。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/9018/mychat/tree/HEAD/OpenMontage/.agents/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 - 将元数据移到文件开头,便于网络流式传输
  • -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

# 激进压缩,用于网络预览
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)

极端速度(>2x 音频): 链式使用 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"(高度不能被 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良好平衡
网页/预览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 偏好使用 AAC 音频的 MP4,最长 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 "已导出:"
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

处理常见故障

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

反馈与贡献

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

  • 缺少某个命令? 描述一下你需要什么
  • 发现错误? 告诉我哪里有问题
  • 想要贡献? 我可以帮助你:
    1. 更新此技能,进行改进
    2. 向 github.com/digitalsamba/claude-code-video-toolkit 发起 PR

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

Individual skills in this repo

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

9018/mychat

Generate AI videos from text prompts using multiple provider gateways. Use when: (1) Generating videos from text descriptions, (2) Creating AI-generated video clips for content production, (3) Image-to-video generation with a reference image, (4) Choosing between video generation providers (VEO, Kling, Sora, Runway, Seedance, MiniMax, Gemini Omni). Supports gateways: HeyGen API, fal.ai API, Kling official direct API, and the Gemini API (Gemini Omni Flash).

9018/mychat

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.

9018/mychat

Use p5.js/canvas for local procedural character effects: particles, weather, squash/stretch, walk cycles, and environmental motion.

9018/mychat

Review local character animation with schema checks, Playwright browser previews, frame sampling, and FFmpeg/ffprobe final output checks.

9018/mychat

Create videos from a text prompt using HeyGen's Video Agent. Use when: (1) Creating a video from a description or idea, (2) Generating explainer, demo, or marketing videos from a prompt, (3) Making a video without specifying exact avatars, voices, or scenes, (4) Quick video prototyping or drafts, (5) One-shot prompt-to-video generation, (6) User says "make me a video" or "create a video about X".

9018/mychat

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.

9018/mychat

Use when implementing Disney's 12 animation principles with Framer Motion in React applications

9018/mychat

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). HyperFrames-native: single paused timeline, seek-safe, deterministic.

9018/mychat

HyperFrames CLI dev loop. Use when running npx hyperframes init, add, catalog, capture, lint, validate, inspect, layout, snapshot, preview, play, render, publish, lambda, doctor, browser, info, upgrade, skills, compositions, docs, benchmark, telemetry, transcribe, tts, or remove-background, or when troubleshooting the HyperFrames build/render environment. Entry point for AWS Lambda cloud rendering (`hyperframes lambda deploy / render / progress / destroy / policies`).

9018/mychat

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.

9018/mychat

Non-animation creative direction for HyperFrames videos. Use for design spec (frame.md / design.md) handling, palettes, typography, narration, beat planning, audio-reactive visuals, composition patterns, and brand / style decisions. For atomic motion patterns and scene blueprints, use `hyperframes-animation`.

9018/mychat

Audio and media assets for HyperFrames compositions, produced by one shared audio engine (`scripts/audio.mjs`) — multi-provider TTS (HeyGen / ElevenLabs / Kokoro local), background music + sound effects (HeyGen audio-library retrieval by default, with local Lyria / MusicGen BGM generation and a bundled SFX library as the no-credential fallback), Whisper transcription, background removal, and caption authoring. Use for voiceover / TTS, BGM, SFX / sound effects, transcription, captions / subtitles / lyrics / karaoke / per-word styling, voice + provider selection, and music-mood prompting.

9018/mychat

Install and wire registry blocks and components into HyperFrames compositions. Use when running hyperframes add, installing a block or component, wiring an installed item into index.html, or working with hyperframes.json. Covers the add command, install locations, block sub-composition wiring, component snippet merging, registry discovery, and authoring a new block or component to contribute upstream (idea → scaffold → validate → PR).

9018/mychat

Use when the user wants a short, design-led motion graphic where motion is the message: kinetic typography, stat or number count-up, chart/data-viz hit, logo sting, brand lockup, lower-third, callout, social overlay, animated headline/tweet/news item, motion poster, or quick captured-page highlight. Usually under 10s and up to ~30s, with no narration arc, voice-over, or live-action subject. Can render to MP4 or transparent overlay. Not for longer, multi-scene, narrated, or brand-reel pieces (use general-video), narrated website videos (website-to-video), topic explainers (faceless-explainer), product promos (product-launch-video), PR videos (pr-to-video), or captions on existing footage (embedded-captions). When unsure whether it's a quick motion-first piece or a longer / narrated treatment, see /hyperframes.

9018/mychat

Use when the user has a music track (an audio file, or a video to pull audio from) and wants a beat-synced HyperFrames video, calm to hard-hitting. The music drives everything: one analyzer reads it once, the orchestrator lays out the frames and fills a per-frame plan, and one sub-agent builds each frame. Typography and templates are the floor — a complete video needs zero assets — but any images or videos the user supplies are cut into the frames on the same beat grid (beat-cut / ken-burns). The genre (lyric video, slideshow, kinetic promo) falls out of the per-frame choices; the pipeline never branches on it.

9018/mychat

Toolkit-specific Remotion patterns — custom transitions, shared components, and project conventions. For core Remotion framework knowledge (hooks, animations, rendering, etc.), see the `remotion-official` skill.

9018/mychat

Port an existing Remotion (React) composition to HyperFrames HTML. Use ONLY when the user explicitly asks to port/convert/migrate/translate a Remotion source. Do NOT use: (a) authoring a new HyperFrames composition; (b) Remotion mentioned in passing; (c) Remotion code shared as reference only; (d) "same video as my Remotion one" without explicit migrate request — treat as fresh build. Doubt → `/general-video`. One-way, Remotion-only: no reverse export (HyperFrames→Remotion or any framework), no non-Remotion source (After Effects, Framer Motion, plain React/CSS) → out of scope, re-create via `/general-video`. Flags unsupported patterns (useState, useEffect, async calculateMetadata, third-party React libs, `@remotion/lambda`) and recommends runtime interop over lossy translation. Unsure whether to port vs. build fresh, or only a passing Remotion mention? → /hyperframes.

9018/mychat

Animate SVG character rigs with GSAP, CSS transforms, Remotion frame control, and HyperFrames-compatible browser previews.

9018/mychat

Three.js animation - keyframe animation, skeletal animation, morph targets, animation mixing. Use when animating objects, playing GLTF animations, creating procedural motion, or blending animations.

9018/mychat

Download video and audio from YouTube and 1000+ sites using yt-dlp. No API keys needed. Use when: (1) Downloading a video from YouTube or other sites, (2) Extracting audio from a video URL, (3) Downloading subtitles/captions from a video, (4) Getting video metadata without downloading.

相关技能