Communitygithub.com

Aseel1600/Edit01

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

Edit01 是什麼?

這個技能為 AI 代理(如 Claude Code)提供了一個完整的 FFmpeg 參考手冊,專門針對影片與音訊處理,特別是為了與 Remotion 影片專案整合而設計。它涵蓋了從基本操作(如 GIF 轉 MP4、影片縮放與壓縮)到進階工作流程(如為不同平台批次匯出、調整速度以符合 Remotion 場景時長)的所有內容。此技能詳細說明了各種 FFmpeg 指令的用途、必要參數(如 `-movflags faststart`)與品質設定(如 CRF 值),並提供常見錯誤的解決方案。主要支援透過終端機或腳本使用 FFmpeg 的命令列環境,並特別強調如何為 YouTube、Twitter/X、LinkedIn 以及網頁嵌入等不同平台優化輸出。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Aseel1600/Edit01/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)

極端速度(>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)或降低解析度

品質指南

使用案例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 偏愛 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

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

# 網頁最佳化 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 的縮放濾鏡
“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.

Aseel1600/Edit01

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

Aseel1600/Edit01

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.

Aseel1600/Edit01

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

Aseel1600/Edit01

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

Aseel1600/Edit01

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

Aseel1600/Edit01

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.

Aseel1600/Edit01

Generate expressive, multilingual narration with fish.audio (S1 / S2-generation models) and reuse cloned voices via reference_id. Use when the user prefers fish.audio/Fish Audio TTS, wants a specific playground voice model, or needs high-emotion voice-clone narration.

Aseel1600/Edit01

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

Aseel1600/Edit01

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.

Aseel1600/Edit01

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

Aseel1600/Edit01

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.

Aseel1600/Edit01

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

Aseel1600/Edit01

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.

Aseel1600/Edit01

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

Aseel1600/Edit01

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.

Aseel1600/Edit01

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.

Aseel1600/Edit01

Best practices for Remotion - Video creation in React

Aseel1600/Edit01

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.

Aseel1600/Edit01

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.

Aseel1600/Edit01

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

相關技能