Communitygithub.com

FFmpeg 视频制作技能

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

FFmpeg 视频制作技能 是什么?

这是一个专为 AI 代理(如 Claude Code)设计的 FFmpeg 技能,专注于 Remotion 视频项目中的视频/音频处理任务。技能涵盖从基础操作(GIF 转 MP4、视频缩放、压缩、音频提取)到高级 Remotion 集成(视频变速、演示录制准备)的全面功能,还包含针对 YouTube、Twitter、LinkedIn 等平台的输出优化方案。核心优势在于提供了可立即复用的命令行代码片段,并详细解释了每个参数的作用,降低了 FFmpeg 的使用门槛。该技能还包含了常见错误清单和批量导出脚本,能显著提升视频制作工作流的效率。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Biznomad/agent-skills/tree/HEAD/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 秒场景:速度 = X / Y
  • setpts 乘数 = 1 / 速度(例如 3 倍速 = setpts=0.333*PTS)
  • atempo 值 = 速度(例如 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

速度调整后音频不同步

使用 filter_complex 配合 atempo:-filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]"

文件太大

提高 CRF 值(23→28)或降低分辨率

质量指南

用途CRFPreset说明
存档/母版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

只需说“改进此技能”,我将引导你更新 .claude/skills/ffmpeg/SKILL.md。

Individual skills in this repo

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

Biznomad/agent-skills

Landing page quality assessment for paid advertising campaigns. Evaluates message match, page speed, mobile experience, trust signals, form optimization, and conversion rate potential. Use when user says "landing page", "post-click experience", "landing page audit", "conversion rate", or "landing page optimization".

Biznomad/agent-skills

TikTok Ads deep analysis covering creative quality, tracking, bidding, campaign structure, and TikTok Shop. Evaluates 25 checks with emphasis on creative-first strategy, safe zone compliance, and Smart+ campaigns. Use when user says "TikTok Ads", "TikTok marketing", "TikTok Shop", "Spark Ads", "Smart+", or "TikTok campaign".

Biznomad/agent-skills

YouTube Ads specific analysis covering campaign types, creative quality, audience targeting, and measurement. Evaluates video ad performance across skippable, non-skippable, bumper, Shorts, and Demand Gen formats. Use when user says "YouTube Ads", "video ads", "pre-roll", "bumper ads", "YouTube campaign", or "Shorts ads".

Biznomad/agent-skills

Help users get promoted at work. Use when someone is preparing for a promotion conversation, building their case for advancement, trying to understand what's blocking their promotion, or figuring out how to get to the next level in their career.

Biznomad/agent-skills

CSS animation adapter patterns for HyperFrames. Use when authoring CSS keyframes, animation-delay based timing, animation-fill-mode, animation-play-state, or CSS-only motion that HyperFrames must seek deterministically during preview and rendering.

Biznomad/agent-skills

Read-only queue dashboard for workspace-aware ship. Shows which VERSION slots are currently claimed by open PRs, which sibling Conductor workspaces have WIP work likely to ship soon, and what slot /ship would pick next. No mutations — just a snapshot. Use when asked to "landing report", "what's in the queue", "show me open PRs", or "which version do I claim next". (gstack)

Biznomad/agent-skills

HyperFrames CLI dev loop — `npx hyperframes` for scaffolding (init), validation (lint, inspect), preview, render, and environment troubleshooting (doctor, browser, info, upgrade). Use when running any of these commands or troubleshooting the HyperFrames build/render environment. For asset preprocessing commands (`tts`, `transcribe`, `remove-background`), invoke the `hyperframes-media` skill instead.

Biznomad/agent-skills

Asset preprocessing for HyperFrames compositions — text-to-speech narration (Kokoro), audio/video transcription (Whisper), and background removal for transparent overlays (u2net). Use when generating voiceover from text, transcribing speech for captions, removing the background from a video or image to use as a transparent overlay, choosing a TTS voice or whisper model, or chaining these (TTS → transcribe → captions). Each command downloads its own model on first run.

Biznomad/agent-skills

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, and registry discovery.

Biznomad/agent-skills

Create video compositions, animations, title cards, overlays, captions, voiceovers, audio-reactive visuals, and scene transitions in HyperFrames HTML. Use when asked to build any HTML-based video content, add captions or subtitles synced to audio, generate text-to-speech narration, create audio-reactive animation (beat sync, glow, pulse driven by music), add animated text highlighting (marker sweeps, hand-drawn circles, burst lines, scribble, sketchout), or add transitions between scenes (crossfades, wipes, reveals, shader transitions). Covers composition authoring, timing, media, and the full video production workflow. For dev-loop CLI commands (init, lint, inspect, preview, render) see the hyperframes-cli skill; for asset preprocessing commands (tts, transcribe, remove-background) see the hyperframes-media skill.

Biznomad/agent-skills

Still-to-video conversion guide: model selection, motion prompting, and camera movement. Covers Wan 2.5 i2v, Seedance, Fabric, Grok Video with when to use each. Use for: animating images, creating video from stills, adding motion, product animations. Triggers: image to video, i2v, animate image, still to video, add motion to image, image animation, photo to video, animate still, wan i2v, image2video, bring image to life, animate photo, motion from image

Biznomad/agent-skills

>- The Landing Page Audit skill performs comprehensive evaluations of post-click experiences, combining technical performance analysis with conversion rate optimization (CRO) assessment.

Biznomad/agent-skills

Write high-converting landing page copy using proven frameworks like PAS (Problem-Agitate-Solution), AIDA, and StoryBrand. Creates headlines, value propositions, CTAs, and full page sections optimized for conversion. Use when users need landing page copy, sales page content, or marketing website text.

Biznomad/agent-skills

Optimize landing pages for higher conversion rates using proven frameworks and design patterns. Use when designing, reviewing, or improving landing pages, hero sections, pricing pages, CTAs, or when the user asks about conversion optimization.

Biznomad/agent-skills

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

Biznomad/agent-skills

Building promotion cases, brag documents, tracking wins, and self-advocacy for career advancement. Use when preparing for promotions, documenting accomplishments, or building your case for advancement.

Biznomad/agent-skills

Best practices for Remotion - Video creation in React

Biznomad/agent-skills

Translate an existing Remotion (React-based) video composition into a HyperFrames HTML composition. Use ONLY when the user explicitly asks to port, convert, migrate, translate, or rewrite a Remotion composition as HyperFrames (e.g. "port my Remotion project to HyperFrames"). Do NOT use when (a) authoring a NEW HyperFrames composition (even if A/B-testing a Remotion video); (b) Remotion is mentioned in passing; (c) Remotion code is shared as reference, not for translation; (d) the user wants "the same video as my Remotion one" without explicitly asking to migrate the source — treat as a fresh HyperFrames build. When in doubt, default to the `hyperframes` skill. Detects unsupported patterns (useState, useEffect side effects, async calculateMetadata, third-party React component libraries, `@remotion/lambda`) and recommends the runtime interop escape hatch instead of a lossy translation.

Biznomad/agent-skills

Produce programmable videos with Remotion using scene planning, asset orchestration, and validation gates for automated, brand-consistent video content.

Biznomad/agent-skills

Reviews animation and motion code against a high craft bar derived from Emil Kowalski's design engineering philosophy. Default to flagging; approval is earned.

相关技能