Communitygithub.com

Zuhair-01/claude-skills-and-systems

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

claude-skills-and-systems 是什麼?

此技能提供了一套全面的 FFmpeg 命令參考,專門針對 Remotion 專案中的視訊與音訊處理工作流程而設計。它涵蓋了從基本的 GIF 轉 MP4、視訊調整尺寸與壓縮,到進階的音訊提取、剪輯、速度調整與串接等操作。對於使用 Remotion 的開發者,此技能特別提供了關於速度調整的詳細指南,說明了何時應使用 FFmpeg 預處理而非 Remotion 的 `playbackRate`,並提供了計算速度因子與鏈接 atempo 濾鏡的具體方法。此外,它也包含了針對不同發布平台(如 YouTube、Twitter/X、LinkedIn 與網站嵌入)的輸出最佳化設定,並提供批次匯出腳本與常見錯誤的解決方案。整體而言,此技能旨在幫助 AI 代理與開發者快速、準確地完成影片製作流程中的媒體處理任務,確保輸出檔案符合 Remotion 專案與各平台的需求。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Zuhair-01/claude-skills-and-systems/tree/HEAD/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

注意: 建議使用重新編碼進行修剪。如果 seek 點未與關鍵幀對齊,串流複製 (-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"

加入 scale 濾鏡:-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/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. 向 github.com/digitalsamba/claude-code-video-toolkit 建立 PR

只需說「改善此技能」,我就會引導您更新 .claude/skills/ffmpeg/SKILL.md。

Individual skills in this repo

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

Zuhair-01/claude-skills-and-systems

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.

Zuhair-01/claude-skills-and-systems

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.

Zuhair-01/claude-skills-and-systems

Edit existing videos using AI — remix style, upscale, remove background, and add audio via fal.ai's hosted video models.

Zuhair-01/claude-skills-and-systems

Author or edit a custom HyperFrames composition when no specialized workflow fits, or when BRIEF.md sets flow: companion. Use for longer or multi-scene pieces, brand and sizzle reels, montages, static loops, static title cards, footage remixes, and freeform builds. Use motion-graphics instead for a short unnarrated motion-first unit, including an animated title. Route fresh creation through hyperframes before using this skill.

Zuhair-01/claude-skills-and-systems

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

Zuhair-01/claude-skills-and-systems

Generate HeyGen presenter videos via the v3 Video Agent pipeline — handles Frame Check (aspect ratio correction), prompt engineering, avatar resolution, and voice selection. Required for any HeyGen video generation. Replaces deprecated endpoints with v3. Use when: (1) generating any HeyGen video (via API or otherwise), (2) sending a personalized video message (outreach, update, announcement, pitch, knowledge), (3) creating a HeyGen presenter-led explainer, tutorial, or product demo with a human face, (4) "make a video of me saying...", "send a video to my leads", "record an update for my team", "create a video pitch", "make a loom-style message", "I want to appear in this video", "generate a HeyGen video", "make a talking head video". Accepts avatar_id from heygen-avatar for identity-first HeyGen videos, or uses a stock presenter. Returns video share URL + HeyGen session URL for iteration. Chain signal: when the user wants to create/design an avatar AND make a video in the same request, run heygen-avatar f...

Zuhair-01/claude-skills-and-systems

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). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.

Zuhair-01/claude-skills-and-systems

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.

Zuhair-01/claude-skills-and-systems

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

相關技能