Communitygithub.com

ComeOnOliver/skillshub

FFmpeg 是媒體處理的瑞士軍刀,幾乎支援所有音訊與視訊格式、編解碼器和容器。此技能涵蓋格式轉換、編解碼轉碼、裁剪、合併、濾鏡、壓縮、縮圖提取、字幕嵌入、音量正規化、GIF 製作、浮水印,以及與 yt-dlp 和 gallery-dl 等工具的管線整合。

skillshub 是什麼?

此技能「FFmpeg」旨在作為一個全方位的媒體處理能力,可在 AI 代理環境中使用,例如 Claude Code、Cursor 或 Codex。它將 FFmpeg 轉變為一個智慧工具,能夠處理幾乎所有音訊和視訊格式、編解碼器和容器,提供格式轉換、編解碼轉碼、精確裁剪、檔案合併、濾鏡效果、壓縮、縮圖提取、字幕嵌入、音量標準化、GIF 建立、浮水印添加,並與 yt-dlp 和 gallery-dl 等工具無縫整合為媒體處理管線。此技能支援多種平台,包括 Ubuntu/Debian 和 macOS,並提供詳細的安裝指令。其核心優勢在於將複雜的 FFmpeg 單行命令轉換為可重複使用、可組合的動作,讓開發者透過簡單的指令就能高效完成從簡單格式轉換到高階多步驟處理的工作,無需手動記憶繁瑣的參數,顯著提升媒體處理的生產力。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/TerminalSkills/skills/ffmpeg

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

FFmpeg

概述

FFmpeg 是媒體處理的瑞士軍刀。它幾乎可以處理所有現有的音訊和視訊格式、編解碼器和容器。此技能涵蓋格式轉換、編解碼器轉換、裁剪、串接、濾鏡、壓縮、縮圖提取、字幕嵌入、音訊標準化、GIF 製作、浮水印,以及與 yt-dlp 和 gallery-dl 等工具的流程整合。

操作說明

步驟 1:安裝

# Ubuntu/Debian
sudo apt install -y ffmpeg

# macOS
brew install ffmpeg

# 驗證
ffmpeg -version
ffprobe -version   # 媒體資訊工具,與 ffmpeg 捆綁

步驟 2:格式轉換

最常見的任務——在容器格式和編解碼器之間進行轉換。

# WebM → MP4(重新編碼為 H.264 + AAC 以實現通用相容性)
ffmpeg -i input.webm -c:v libx264 -c:a aac -movflags +faststart output.mp4

# WebM → MP4(如果已是 H.264/AAC,則直接複製串流——即時且無品質損失)
ffmpeg -i input.webm -c copy output.mp4

# MKV → MP4(複製串流,無需重新編碼)
ffmpeg -i input.mkv -c copy output.mp4

# AVI → MP4
ffmpeg -i input.avi -c:v libx264 -crf 23 -c:a aac -b:a 128k output.mp4

# MOV → MP4(Apple ProRes 轉 H.264)
ffmpeg -i input.mov -c:v libx264 -crf 18 -preset slow -c:a aac output.mp4

# 任何格式 → 支援 Web 優化快速啟動的 MP4
ffmpeg -i input.* -c:v libx264 -crf 23 -preset medium -c:a aac -movflags +faststart output.mp4

CRF(固定速率因子): 控制品質。數值越低 = 畫質越好,檔案越大。

  • 18:視覺上無損
  • 23:預設值,良好平衡
  • 28:檔案較小,有些許品質損失
  • 51:最差品質

步驟 3:音訊操作

# 從視訊提取音訊
ffmpeg -i video.mp4 -vn -c:a copy audio.aac          # 複製編解碼器(快速)
ffmpeg -i video.mp4 -vn -c:a libmp3lame -q:a 2 audio.mp3  # 轉換為 MP3
ffmpeg -i video.mp4 -vn -c:a flac audio.flac          # 無損 FLAC

# 在音訊格式之間轉換
ffmpeg -i input.wav -c:a libmp3lame -b:a 320k output.mp3
ffmpeg -i input.mp3 -c:a libopus -b:a 128k output.opus
ffmpeg -i input.flac -c:a aac -b:a 256k output.m4a

# 標準化音訊音量
ffmpeg -i input.mp3 -af loudnorm=I=-16:LRA=11:TP=-1.5 output.mp3

# 更改取樣率
ffmpeg -i input.wav -ar 44100 output.wav

# 將音訊合併到視訊
ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4

步驟 4:裁剪、剪切和串接

# 從時間戳記開始裁剪指定時長
ffmpeg -i input.mp4 -ss 00:01:30 -t 00:00:45 -c copy clip.mp4    # 從 1:30 開始,持續 45 秒

# 從開始時間戳記裁剪到結束時間戳記
ffmpeg -i input.mp4 -ss 00:05:00 -to 00:10:00 -c copy clip.mp4   # 從 5:00 到 10:00

# 前 30 秒
ffmpeg -i input.mp4 -t 30 -c copy first30.mp4

# 串接檔案(先建立檔案清單)
cat > filelist.txt << 'EOF'
file 'clip1.mp4'
file 'clip2.mp4'
file 'clip3.mp4'
EOF
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4

# 使用重新編碼串接(當編解碼器不同時)
ffmpeg -f concat -safe 0 -i filelist.txt -c:v libx264 -c:a aac output.mp4

步驟 5:解析度和壓縮

# 調整大小至 1080p(保持寬高比)
ffmpeg -i input.mp4 -vf "scale=-2:1080" -c:v libx264 -crf 23 -c:a copy output.mp4

# 調整大小至 720p
ffmpeg -i input.mp4 -vf "scale=-2:720" -c:v libx264 -crf 23 -c:a copy output.mp4

# 調整大小至指定寬度(高度自動計算)
ffmpeg -i input.mp4 -vf "scale=1280:-2" output.mp4

# 積極壓縮(檔案更小)
ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset faster -c:a aac -b:a 96k small.mp4

# 雙遍編碼以控制目標檔案大小
ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -pass 1 -an -f null /dev/null
ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -pass 2 -c:a aac -b:a 128k output.mp4

# 更改影格率
ffmpeg -i input.mp4 -r 30 output.mp4

步驟 6:縮圖和螢幕截圖

# 在時間戳記處擷取單張螢幕截圖
ffmpeg -i input.mp4 -ss 00:01:30 -frames:v 1 thumb.jpg

# 每隔 10 秒擷取一張螢幕截圖
ffmpeg -i input.mp4 -vf "fps=1/10" thumbs/frame_%04d.jpg

# 縮圖網格(4x4 聯絡表)
ffmpeg -i input.mp4 -vf "select='not(mod(n,300))',scale=320:-1,tile=4x4" -frames:v 1 grid.jpg

# 提取第一影格
ffmpeg -i input.mp4 -frames:v 1 first_frame.png

步驟 7:字幕

# 將字幕嵌入視訊(硬編碼)
ffmpeg -i input.mp4 -vf "subtitles=subs.srt" output.mp4

# 嵌入帶有樣式的 ASS/SSA 字幕
ffmpeg -i input.mp4 -vf "ass=subs.ass" output.mp4

# 添加字幕軌(軟字幕,用戶可切換)
ffmpeg -i input.mp4 -i subs.srt -c copy -c:s mov_text output.mp4

# 從視訊提取字幕
ffmpeg -i input.mkv -map 0:s:0 subs.srt

步驟 8:濾鏡和特效

# 從視訊片段建立 GIF
ffmpeg -i input.mp4 -ss 5 -t 3 -vf "fps=15,scale=480:-1:flags=lanczos" output.gif

# 使用調色板的高品質 GIF
ffmpeg -i input.mp4 -ss 5 -t 3 -vf "fps=15,scale=480:-1:flags=lanczos,palettegen" palette.png
ffmpeg -i input.mp4 -i palette.png -ss 5 -t 3 -lavfi "fps=15,scale=480:-1:flags=lanczos[v];[v][1:v]paletteuse" output.gif

# 添加浮水印
ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=W-w-10:H-h-10" output.mp4

# 加速 / 減速
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" fast.mp4
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" slow.mp4

# 旋轉視訊
ffmpeg -i input.mp4 -vf "transpose=1" rotated.mp4    # 順時針 90°
ffmpeg -i input.mp4 -vf "transpose=2" rotated.mp4    # 逆時針 90°

# 裁切視訊(寬度:高度:x:y)
ffmpeg -i input.mp4 -vf "crop=1280:720:0:180" cropped.mp4

# 淡入 / 淡出
ffmpeg -i input.mp4 -vf "fade=in:0:30,fade=out:870:30" -af "afade=in:0:30,afade=out:870:30" output.mp4

步驟 9:媒體資訊

# 完整媒體資訊
ffprobe -v quiet -print_format json -show_format -show_streams input.mp4

# 僅時長
ffprobe -v quiet -show_entries format=duration -of csv=p=0 input.mp4

# 解析度
ffprobe -v quiet -select_streams v:0 -show_entries stream=width,height -of csv=p=0 input.mp4

# 編解碼器資訊
ffprobe -v quiet -select_streams v:0 -show_entries stream=codec_name -of csv=p=0 input.mp4

步驟 10:批次處理

# 將所有 WebM 檔案轉換為 MP4
for f in *.webm; do
  ffmpeg -i "$f" -c:v libx264 -crf 23 -c:a aac "${f%.webm}.mp4"
done

# 壓縮目錄中的所有 MP4 檔案
for f in *.mp4; do
  ffmpeg -i "$f" -c:v libx264 -crf 28 -preset fast -c:a aac "compressed_${f}"
done

# 從所有視訊中提取音訊
for f in *.mp4; do
  ffmpeg -i "$f" -vn -c:a libmp3lame -q:a 2 "${f%.mp4}.mp3"
done

範例

範例 1:將 yt-dlp 下載的 WebM 檔案轉換為 MP4

使用者提示:「我用 yt-dlp 下載了幾個影片,但都是 .webm 檔案。把它們轉成 MP4,好讓我在 iPhone 上播放。」

代理程式會:

  1. 使用 ffprobe 檢查 WebM 檔案是否包含 H.264+AAC(可進行串流複製)還是 VP9+Opus(需要重新編碼)。
  2. 對於 VP9/Opus 檔案,執行:for f in *.webm; do ffmpeg -i "$f" -c:v libx264 -crf 23 -preset medium -c:a aac -movflags +faststart "${f%.webm}.mp4"; done
  3. -movflags +faststart 標記會將元數據移到檔案開頭,從而在行動裝置和網頁瀏覽器上實現即時播放。
  4. 報告轉換結果,顯示轉換前後的檔案大小。

範例 2:從多個片段創建精彩片段合輯

使用者提示:「我有 5 個會議的影片片段。把最好的部分剪下來,用淡入淡出效果拼成一個影片。」

代理程式會:

  1. 使用 -ss 和 -to 標記將每個片段裁剪到指定的時間戳記。
  2. 將所有片段重新編碼為匹配的編解碼器/解析度:ffmpeg -i clip.mp4 -c:v libx264 -crf 23 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,fade=in:0:15,fade=out:st=DURATION:d=0.5" -c:a aac -ar 44100 segment_N.mp4
  3. 建立串接檔案清單並合併:ffmpeg -f concat -safe 0 -i filelist.txt -c copy highlight_reel.mp4

指引

  • 轉換 yt-dlp 下載的檔案(通常是 WebM/VP9+Opus)時,務必重新編碼為 H.264+AAC 以獲得最大的裝置相容性。使用 -c:v libx264 -crf 23 -c:a aac -movflags +faststart。
  • 盡可能使用串流複製(-c copy)以避免重新編碼——即時且無損。僅在更改編解碼器、應用濾鏡或來源與目標容器不相容時才重新編碼。
  • 建立用於網頁或行動裝置播放的 MP4 檔案時,務必添加 -movflags +faststart;它會將 moov atom 移到檔案開頭,實現即時串流。
  • 在處理之前使用 ffprobe 了解輸入格式,避免不必要的重新編碼。
  • 對於批次操作,請先在單個檔案上測試命令,然後再對整個目錄執行。
  • 對於單遍編碼,優先使用 CRF 模式而非位元率模式;它能為不同類型的內容提供一致的品質。

Individual skills in this repo

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

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相關技能