Communitygithub.com

FFmpeg スキル

FFmpeg を使用したトランスコード、変換、編集、オーディオ/ビデオ処理。フォーマット変換、音声抽出、圧縮、トリミング、結合、サムネイル作成、フィルター適用、解像度/ビットレート変更、GIF作成、ウォーターマーク追加、音声正規化、ストリーミング、自動化パイプライン構築に対応。

FFmpeg スキル とは?

FFmpeg スキルは、FFmpeg を活用してほぼすべてのメディア処理タスクを実行するための包括的なツールです。対応プラットフォームは、Claude Code、Cursor、Codex などのターミナルベースのAIエージェントを想定しており、Ubuntu/Debian、macOS で動作します。このスキルは、フォーマット変換(WebM から MP4 など)、コーデックトランスコード、音声抽出、トリミング、結合、解像度/ビットレート変更、サムネイル抽出、字幕埋め込み、フィルター、GIF作成、ウォーターマーク追加、音声正規化、バッチ処理など、10のステップに体系化されています。各ステップには具体的なコマンド例とオプションの説明が含まれており、ffprobe によるメディア情報の取得もサポートします。特に yt-dlp でダウンロードした WebM ファイルを iPhone で再生可能な MP4 に変換する実用的なユースケースが例示されており、ストリームコピーによる高速処理と再エンコードが必要なケースの判断基準も示されています。エージェントはユーザーの要求に応じて適切なコマンドを選択・実行し、結果をレポートします。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/TerminalSkills/skills/tree/HEAD/skills/ffmpeg

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

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

# 任意フォーマット → MP4(Web最適化 fast start 付き)
ffmpeg -i input.* -c:v libx264 -crf 23 -preset medium -c:a aac -movflags +faststart output.mp4

CRF(Constant Rate Factor): 品質を制御。低いほど高品質、ファイルサイズ大。

  • 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

# 対象ファイルサイズ向け2パスエンコード
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: サムネイルとスクリーンショット

# タイムスタンプで1枚のスクリーンショット
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 ファイルです。iPhone で再生できるように MP4 に変換してください。」

エージェントは以下の処理を行います:

  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 フラグによりメタデータをファイル先頭に移動し、モバイルデバイスやWebブラウザでの即時再生を可能に。
  4. 変換結果をファイルサイズの前後比較とともに報告。

例2: 複数クリップからのハイライトリール作成

ユーザープロンプト: 「カンファレンスのビデオクリップが5つあります。ベストパートをトリミングして、フェードトランジション付きで1つのビデオに結合してください。」

エージェントは以下の処理を行います:

  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. concat ファイルリストを作成し結合: 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)を使用して再エンコードを避けてください。即時かつロスレスです。コーデック変更、フィルター適用、またはソースとターゲットコンテナが互換性がない場合のみ再エンコードしてください。
  • Web またはモバイル再生用の MP4 ファイルを作成するときは、必ず -movflags +faststart を追加してください。moov アトムをファイル先頭に移動し、即時ストリーミングを可能にします。
  • 処理前に ffprobe を使用して入力フォーマットを理解し、不要な再エンコードを避けてください。
  • バッチ操作の場合は、ディレクトリ全体で実行する前に必ず単一ファイルでコマンドをテストしてください。
  • シングルパスエンコードではビットレートモードよりも CRF モードを推奨します。異なるコンテンツタイプで一貫した品質が得られます。

Individual skills in this repo

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

TerminalSkills/skills

>- Run GitHub Actions locally with act. Use when a user asks to test GitHub Actions workflows locally, debug CI pipelines without pushing, or run workflows offline.

TerminalSkills/skills

>- You are an expert in AG2 (formerly AutoGen), the open-source multi-agent conversation framework. You help developers build systems where multiple AI agents collaborate through structured conversations — with tool use, human-in-the-loop, code execution, group chat orchestration, and nested conversations — for complex tasks like software development, research, and data analysis.

TerminalSkills/skills

>- Generate short-form videos with AI — script writing, text-to-speech narration, stock footage selection, subtitle generation, and video assembly. Use when: creating TikTok/YouTube Shorts/Reels content, automating video production, building content pipelines.

TerminalSkills/skills

>- Animate 3D objects and characters in Blender with Python. Use when the user wants to keyframe properties, create armatures and rigs, set up IK/FK chains, animate shape keys for facial animation, edit F-Curves, use the NLA editor to blend actions, add drivers for expression-based animation, or script any animation workflow in Blender.

TerminalSkills/skills

>- Automate motion capture and tracking workflows in Blender with Python. Use when the user wants to import BVH or FBX mocap data, retarget motion to armatures, track camera or object motion from video, solve camera motion, clean up motion capture data, or script any tracking pipeline in Blender.

TerminalSkills/skills

>- You are an expert in Bolt.new by StackBlitz, the AI-powered full-stack development environment that runs entirely in the browser. You help developers go from idea to deployed app in minutes using natural language prompts — Bolt generates complete applications with frontend, backend, database, and deployment, all running in a WebContainer without local setup.

TerminalSkills/skills

>- Assists with using Bun as an all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Use when building HTTP servers, managing packages, running tests, or migrating from Node.js. Trigger words: bun, bun serve, bun install, bun test, bun build, javascript runtime, bun runtime.

TerminalSkills/skills

>- Self-host customer support with Chatwoot. Use when a user asks to set up open-source customer support, add live chat without SaaS costs, build a multi-channel inbox, or deploy a free Intercom alternative.

TerminalSkills/skills

>- You are an expert in Chi, the lightweight, idiomatic Go HTTP router built on `net/http`. You help developers build composable HTTP services using Chi's middleware stack, route groups, URL parameters, sub-routers, and context-based request scoping — providing Express-like ergonomics while staying 100% compatible with Go's standard library.

TerminalSkills/skills

When the user wants to edit, review, or improve existing marketing copy. Also use when the user mentions 'edit this copy,' 'review my copy,' 'copy feedback,' 'proofread,' 'polish this,' 'make this better,' or 'copy sweep.' This skill provides a systematic approach to editing marketing copy through multiple focused passes.

TerminalSkills/skills

>- Add live chat and customer support with Crisp. Use when a user asks to add a chat widget, implement live customer support, set up a help desk, create a knowledge base, or add a chatbot to a website.

TerminalSkills/skills

>- Assists with building custom interactive data visualizations using D3.js. Use when creating charts, graphs, maps, force layouts, or hierarchical diagrams that require fine-grained control beyond what charting libraries provide. Trigger words: d3, data visualization, chart, svg, scales, force graph, treemap, choropleth.

TerminalSkills/skills

dbt (data build tool) transforms data in your warehouse using SQL SELECT statements. Learn project setup, models, tests, documentation, incremental materializations, and integration with data warehouses like PostgreSQL, BigQuery, and Snowflake.

TerminalSkills/skills

>- You are an expert in dlt, the open-source Python library for building data pipelines. You help developers load data from any API, file, or database into warehouses and lakes using simple Python decorators — with automatic schema inference, incremental loading, and built-in data contracts. dlt is the "requests library for data pipelines.

TerminalSkills/skills

Data Version Control for ML projects. Track large datasets and models alongside Git, build reproducible ML pipelines, and run experiments with metric comparison. Works with any storage backend including S3, GCS, Azure, and local filesystems.

TerminalSkills/skills

>- You are an expert in E2B, the cloud platform for running AI-generated code in secure sandboxes. You help developers give AI agents the ability to execute code, install packages, read/write files, and run long processes in isolated cloud environments — each sandbox is a lightweight VM that boots in ~150ms with full Linux, filesystem, and networking.

TerminalSkills/skills

>- Create advanced animations with GSAP. Use when building complex timelines, scroll-driven animations, SVG morphing, text animations, or high-performance web animations beyond CSS capabilities.

TerminalSkills/skills

>- Generate deterministic MP4 videos from HTML, CSS, media, and seekable animations using HeyGen's HyperFrames framework. Use when someone asks to "render HTML to video", "make a video with HyperFrames", "create a programmatic video", "turn an animation into MP4", "build a launch/product video from HTML", "render GSAP/Lottie/Three.js to video", or set up an agent-driven video pipeline. Covers init/preview/render/add/lint/inspect commands, data-* timing attributes, animation adapters, and the component catalog.

TerminalSkills/skills

When the user wants to perform load testing, stress testing, or performance testing of APIs and websites using k6. Also use when the user mentions "k6," "load test," "performance test," "stress test," "spike test," "soak test," "thresholds," "virtual users," or "VUs." For browser-based testing, see selenium.

TerminalSkills/skills

>- Lovable (formerly GPT Engineer) is a browser-based AI app builder that turns a natural-language description into a working full-stack web app with a built-in backend, authentication, database and one-click publishing. Use when the user wants to prototype or ship a web app with Lovable, write effective Lovable prompts, connect Supabase or GitHub, review generated security rules, or move a Lovable project into their own editor.

関連スキル