Communitygithub.com

Biznomad/agent-skills

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

agent-skills 是什麼?

這個技能為 AI 代理提供了使用 FFmpeg 進行全面影片與音訊處理的能力,特別針對 Remotion 影片專案進行了最佳化。它涵蓋了從基礎的轉換任務(如將 GIF 轉為 MP4、調整影片尺寸、壓縮影片、擷取音訊)到更高階的編輯操作(如修剪、加速/減速、拼接、添加淡入淡出效果)的所有步驟。該技能也提供了針對特定平台的輸出最佳化指引,包括 YouTube、Twitter/X、LinkedIn、網站嵌入以及 GIF 預覽圖,並包含批處理腳本以簡化工作流程。此外,它還提供了常見錯誤的排錯方法、品質指南(CRF 與 Preset 的選擇),以及一個詳細的比較表,說明何時應使用 FFmpeg 而非 Remotion 內建功能來調整速度。對於需要處理媒體素材的開發者、內容創作者或 AI 代理來說,這是一個不可或缺的技能,支援在 Cursor、Claude Code 或任何可執行 shell 命令的代理平台上的應用。

相容平台✓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 秒的場景中: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)或降低解析度

品質指南

使用情境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 動態1080x13504GB60 秒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.

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.

相關技能