Communitygithub.com

9018/mychat

使用 FFmpeg 進行影片與音訊處理。可用於格式轉換、尺寸調整、壓縮、音訊擷取以及為 Remotion 準備素材。觸發情境包括將 GIF 轉換為 MP4、調整影片尺寸、擷取音訊、壓縮檔案或任何媒體轉換任務。

mychat 是什麼?

這個 AI Agent 技能「FFmpeg for Video Production」旨在協助開發者與內容創作者使用 FFmpeg 執行常見的影片與音訊處理任務,特別針對 Remotion 影片專案進行了優化。它提供了詳盡的指令範例與選項說明,涵蓋格式轉換(如 GIF 轉 MP4)、尺寸調整、壓縮、音訊萃取、剪輯、速度調整、影片拼接與淡入淡出等核心功能。此外,技能還包含了 Remotion 專屬的處理模式,例如如何根據場景長度計算速度倍率,以及針對 YouTube、Twitter/X、LinkedIn 和網站嵌入等不同平台的最佳化輸出設定。它同時也整合了錯誤處理指南與品質標準對照表,協助使用者快速診斷問題並選擇合適的編碼參數。整體而言,這是一個兼具通用性與 Remotion 專用場景的實用工具包,適合用於 Cursor、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)

極端速度 (>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 整除"

加入 scale 濾鏡:-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) 或降低解析度

品質指南

使用情境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

網站/嵌入 (針對快速載入最佳化)

# 網路最佳化 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

# 網路嵌入 (小檔案)
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 的 scale 濾鏡
"encoder not found"缺少編解碼器安裝包含完整編解碼器的 FFmpeg
輸出 0 位元組無聲失敗檢查完整的 ffmpeg 輸出以找出錯誤

意見回饋與貢獻

如果這個技能缺少資訊或可以改進:

  • 缺少指令? 描述您需要的功能
  • 發現錯誤? 告訴我哪裡出了問題
  • 想要貢獻? 我可以幫助您:
    1. 更新此技能以進行改進
    2. 建立 PR 至 github.com/digitalsamba/claude-code-video-toolkit

只需說「改進此技能」,我將引導您更新 .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.

相關技能