Communitygithub.com

Army161/OpenMontage

使用 FFmpeg 进行视频和音频处理,适用于格式转换、调整大小、压缩、音频提取以及为 Remotion 准备素材。

OpenMontage 是什么?

该技能为 AI 开发者和内容创作者提供了全面的 FFmpeg 操作指南,专注于 Remotion 视频项目的工作流程。它涵盖了从基础视频处理(如 GIF 转 MP4、视频缩放、压缩、音频提取)到高级操作(如变速、拼接、淡入淡出)的所有常见任务。技能特别强调与 Remotion 的无缝集成,提供了针对 Remotion 播放速度限制的 FFmpeg 预处理方案,以及用于优化不同平台(YouTube、Twitter、LinkedIn、网站等)输出的最佳实践。此外,还包含了批量处理、错误处理和质量控制的详细指南,确保用户能够高效生成高质量的视频资产。支持所有平台(包括命令行和 AI 编码助手)。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Army161/OpenMontage/tree/HEAD/.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)

极端速度(>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

常见问题

"高度不能被 2 整除"

添加缩放滤镜:-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"

视频无法在浏览器播放

使用:-movflags faststart -pix_fmt yuv420p -c:v libx264

变速后音频不同步

使用 filter_complex 配合 atempo:-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

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

# 网页优化 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/X1920x1200512MB140sAAC 44.1kHz
LinkedIn4096x23045GB10 分钟AAC 48kHz
Instagram 动态1080x13504GB60sAAC 48kHz
Instagram Reels1080x19204GB90sAAC 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

# 网页嵌入(小)
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

只需说“改进此技能”,我会指导您更新 .claude/skills/ffmpeg/SKILL.md。

Individual skills in this repo

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

Army161/OpenMontage

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). Supports two gateways: HeyGen API and fal.ai API.

Army161/OpenMontage

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.

Army161/OpenMontage

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

Army161/OpenMontage

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

Army161/OpenMontage

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".

Army161/OpenMontage

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.

Army161/OpenMontage

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

Army161/OpenMontage

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.

Army161/OpenMontage

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`).

Army161/OpenMontage

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.

Army161/OpenMontage

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`.

Army161/OpenMontage

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.

Army161/OpenMontage

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).

Army161/OpenMontage

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.

Army161/OpenMontage

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.

Army161/OpenMontage

Best practices for Remotion - Video creation in React

Army161/OpenMontage

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.

Army161/OpenMontage

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.

Army161/OpenMontage

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

Army161/OpenMontage

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

相关技能