mcpField
F
ffmpeg-command-syntax

ffmpeg-command-syntax

github.com/josiahsiegelクリエイティブ・メディア5983 回インストール19 週間前に更新
リポジトリ

ffmpeg-command-syntax について

ffmpeg-command-syntaxは、FFmpegコマンドの作成を支援するリファレンススキルで、オプションの位置が入力と出力に与える影響を中心に説明します。オプションの分類、ストリーム指定子、複数ファイルのコマンド、よくある配置ミスも扱います。

主な機能

  1. 01グローバル、入力、出力オプションの説明
  2. 02位置によって変わるオプション動作の解説
  3. 03ストリーム指定子の構文例
  4. 04複数入力・複数出力のコマンド解説
  5. 05詳細なオプション資料への案内

活用シーン

  1. 01シークや長さのオプションを正しく配置
  2. 02出力のコーデックとフィルターを設定
  3. 03メディア間で対象ストリームをマッピング
  4. 04FFmpegコマンドの配置ミスを回避

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/josiahsiegel/claude-plugin-marketplace --skill ffmpeg-command-syntax

インストール後、Claude Code で/ffmpeg-command-syntaxを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
complete-option-reference.md
format-specific-options.md
hardware-device-init.md
stream-specifiers.md
timestamps-bitstream-metadata.md

詳細

重要:FFmpeg オプションの順序規則

FFmpeg で最もよくある間違いは、オプションを誤った位置に置くことです。 FFmpeg のオプションは位置に依存し、その後に指定された次のファイルに適用されます。

基本ルール
ffmpeg [global_options] {[input_options] -i input}... {[output_options] output}...

重要な原則:オプションは次のファイルに適用されます。ファイルごとにリセットされます。


オプションの種類一覧

種類配置場所主なオプション
グローバル最初、-i より前-y、-n、-v、-hide_banner、-filter_complex、-init_hw_device
入力前の出力(またはコマンドの開始位置)と次の -i の間-ss、-t、-to、-re、-stream_loop、-hwaccel、-itsoffset
出力すべての -i の後、対応する出力ファイルの前-c:v、-c:a、-crf、-preset、-vf、-af、-map、-movflags

カテゴリ別の全オプション一覧(各オプションの説明を含む)は、references/complete-option-reference.md にあります。

グローバルオプション(簡易一覧)
ffmpeg -y -hide_banner -v warning -i input.mp4 output.mp4

よく使われるグローバルフラグ:-y、-n、-v/-loglevel、-stats、-progress、-report、-hide_banner、-filter_complex、-filter_complex_threads、-init_hw_device、-filter_hw_device。

入力オプション(簡易一覧)

適用する -i の直前に配置します。ファイルの読み込み/デコード方法に影響します。

よく使われるオプション:-ss、-t、-to、-itsoffset、-itsscale、-re、-readrate、-stream_loop、-hwaccel、-hwaccel_device、-hwaccel_output_format、-c:v/-c:a(デコーダーとして)、-r/-s/-pix_fmt(RAW 入力の場合)、-accurate_seek、-thread_queue_size。

# Correct: Input options before their -i
ffmpeg -ss 00:01:00 -t 30 -i input.mp4 output.mp4

# Wrong: -ss after -i becomes an OUTPUT (slow) seek
ffmpeg -i input.mp4 -ss 00:01:00 output.mp4

ハードウェアアクセラレーションのオプションは、必ず -i より前に置きます。

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 \
  -c:v h264_nvenc output.mp4
出力オプション(簡易一覧)

すべての入力の後、適用する出力ファイルの前に配置します。ファイルのエンコード/書き込み方法に影響します。

よく使われるオプション:-c:v/-c:a/-c:s(エンコーダーとして)、-b:v/-b:a、-crf、-qp、-preset、-tune、-profile:v、-level、-r/-s/-aspect/-pix_fmt、-vf/-af、-map、-ss/-t/-to(出力用の形式)、-fs、-frames:v/-frames:a、-movflags、-metadata、-disposition、-shortest、-an/-vn/-sn。

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium output.mp4

配置によって動作が変わるオプション

オプションによっては、-i の前にあるか後にあるかで、意味がまったく異なります。

-ss(シーク/開始時刻)— 配置が重要
# BEFORE -i (INPUT): Fast keyframe seek, then decode to exact position with -accurate_seek (default)
ffmpeg -ss 00:01:00 -i input.mp4 -t 30 -c copy output.mp4

# AFTER -i (OUTPUT): Frame-accurate but slow - decodes everything, discards until target
ffmpeg -i input.mp4 -ss 00:01:00 -t 30 -c:v libx264 output.mp4

# BOTH (recommended): coarse seek + fine seek
ffmpeg -ss 00:00:55 -i input.mp4 -ss 00:00:05 -t 30 -c:v libx264 output.mp4

注:-i より前に置いた -ss は、タイムスタンプを 0 にリセットします。元の値を保持するには -copyts を使用してください。

-t と -to
# -t BEFORE -i: limits how much of input to READ
ffmpeg -t 60 -i input.mp4 -c copy output.mp4

# -t AFTER -i: limits output DURATION
ffmpeg -i input.mp4 -t 60 -c copy output.mp4

# -ss + -to: with timestamp reset, -to is relative to new zero
ffmpeg -ss 00:01:00 -i input.mp4 -to 00:00:30 output.mp4  # 30s clip
ffmpeg -ss 00:01:00 -copyts -i input.mp4 -to 00:01:30 output.mp4  # also 30s clip
-r(フレームレート)
# BEFORE -i: input frame rate (raw/image sequences)
ffmpeg -r 30 -i frame_%04d.png output.mp4

# AFTER -i: output frame rate (adds/drops frames)
ffmpeg -i input.mp4 -r 24 output.mp4
-s(サイズ)
# BEFORE -i: raw input size
ffmpeg -s 1920x1080 -pix_fmt yuv420p -i raw.yuv output.mp4

# AFTER -i: scales output (prefer -vf scale instead)
ffmpeg -i input.mp4 -s 1280x720 output.mp4
-c/-codec
# BEFORE -i: DECODER selection
ffmpeg -c:v h264_cuvid -i input.mp4 -c:v h264_nvenc output.mp4

# AFTER -i: ENCODER selection (common case)
ffmpeg -i input.mp4 -c:v libx264 -c:a aac output.mp4

ストリーム指定子(簡易形式)

-option[:specifier] を使って特定のストリームを対象にします。

ffmpeg -i input.mkv -c:v libx264 -c:a aac -c:s mov_text output.mp4
ffmpeg -i a.mp4 -i b.mp4 -map 1:0 -c copy output.mp4

よく使われる指定子::v、:V、:a、:s、:d、:t、:v:0、:a:1、:0、:m:key:value、:p:0。全一覧表とストリームごとの例は、references/stream-specifiers.md を参照してください。


複数の入力と出力

# Per-input options
ffmpeg \
  -ss 10 -i first.mp4 \
  -ss 5 -i second.mp4 \
  -filter_complex "[0:v][1:v]overlay" output.mp4

# Per-output options (they RESET between outputs)
ffmpeg -i input.mp4 \
  -c:v libx264 -crf 23 output_h264.mp4 \
  -c:v libx265 -crf 28 output_h265.mp4
# WRONG: second output silently gets no encoding options
ffmpeg -i input.mp4 -c:v libx264 -crf 23 out1.mp4 out2.mp4

よくある間違いと修正方法

1. 入力オプションを -i の後に置く
# WRONG: -hwaccel after -i has no effect
ffmpeg -i input.mp4 -hwaccel cuda -c:v h264_nvenc output.mp4
# CORRECT
ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc output.mp4
2. 出力オプションを -i の前に置く
# WRONG: -c:v before -i tries to choose a decoder
ffmpeg -c:v libx264 -i input.mp4 output.mp4
# CORRECT
ffmpeg -i input.mp4 -c:v libx264 output.mp4
3. オプションが出力間で引き継がれると思い込む
# WRONG
ffmpeg -i input.mp4 -c:v libx264 -crf 23 out1.mp4 out2.mp4
# CORRECT
ffmpeg -i input.mp4 \
  -c:v libx264 -crf 23 out1.mp4 \
  -c:v libx264 -crf 23 out2.mp4
4. 正確さが必要なのに -ss の位置を誤る
# Fast but may snap to keyframe
ffmpeg -ss 00:05:00 -i input.mp4 -t 30 -c copy output.mp4
# Accurate but slow
ffmpeg -i input.mp4 -ss 00:05:00 -t 30 -c:v libx264 output.mp4
# Fast AND accurate
ffmpeg -ss 00:04:55 -i input.mp4 -ss 5 -t 30 -c:v libx264 output.mp4
5. 入力と出力を混在させる
# WRONG
ffmpeg -i input1.mp4 -c:v libx264 output1.mp4 -i input2.mp4 output2.mp4
# CORRECT
ffmpeg -i input1.mp4 -i input2.mp4 \
  -map 0 -c:v libx264 output1.mp4 \
  -map 1 -c:v libx264 output2.mp4
6. -ss によるタイムスタンプのリセットと -t/-to の使い分け
ffmpeg -ss 00:01:00 -i input.mp4 -to 00:00:30 output.mp4         # 30s clip
ffmpeg -ss 00:01:00 -copyts -i input.mp4 -to 00:01:30 output.mp4 # 30s clip
ffmpeg -ss 00:01:00 -i input.mp4 -t 00:00:30 output.mp4          # 30s clip
7. -vf と -filter_complex の使い分け
# Single-input filter (per-output)
ffmpeg -i input.mp4 -vf "scale=1280:720" output.mp4

# Multi-input filter (global)
ffmpeg -i video.mp4 -i overlay.png \
  -filter_complex "[0:v][1:v]overlay=10:10" output.mp4

# WRONG: -vf cannot reference multiple inputs
ffmpeg -i video.mp4 -i overlay.png -vf "overlay=10:10" output.mp4

コマンド構成の例

# Basic transcode
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac output.mp4

# With input seeking
ffmpeg -ss 60 -i input.mp4 -t 30 -c:v libx264 output.mp4

# Hardware acceleration
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 \
  -c:v h264_nvenc -preset p4 output.mp4

# Multiple inputs with filters
ffmpeg -i main.mp4 -i overlay.png \
  -filter_complex "[0:v][1:v]overlay=10:10[v]" \
  -map "[v]" -map 0:a -c:v libx264 -c:a copy output.mp4

# Real-time streaming
ffmpeg -re -i input.mp4 -c:v libx264 -f flv rtmp://server/live/stream

# Full structure
ffmpeg \
  -y -hide_banner \
  -hwaccel cuda -ss 10 -i input1.mp4 \
  -stream_loop -1 -i input2.mp4 \
  -filter_complex "[0:v][1:v]overlay[v]" \
  -map "[v]" -map 0:a \
  -c:v h264_nvenc -b:v 5M \
  -c:a aac -b:a 192k \
  -movflags +faststart \
  output.mp4

クイック配置チートシート

オプション-i の前-i の後備考
-ss高速シーク正確なシーク前=キーフレーム、後=デコード
-t入力の制限出力の制限読み込みと書き込み
-to入力の終了位置出力の終了位置タイムスタンプのリセットの影響を受けます
-r入力 FPS出力 FPS生データ/出力の変換
-s入力サイズ出力サイズ生データ/スケーリング
-c:v/-c:aデコーダーエンコーダー前=デコード
-hwaccel、-re、-itsoffset、-stream_loop必須該当なし入力専用
-vf、-af、-map、-crf、-preset、-movflags該当なし必須出力専用
-y、-v、-filter_complexグローバルグローバル先頭に配置

詳細リファレンスマップ

網羅的な情報については、付属のリファレンスファイルをご覧ください。


外部リファレンス

コメント