映像の黒枠を検出してcrop
フィルタで使う引数を返すcropdetect
フィルタの使い方。
基本コマンド
ffmpeg -i input -vf cropdetect -an -f null -
ffplay -i input -vf cropdetect
metadata
フィルタを使ってテキストに出力する方法もある。
ffmpeg -i input -vf cropdetect,metadata=mode=print:file=foo.txt -an -f null -
1枚画像のときはskip=0を指定する。
ffmpeg -i img.jpg -vf cropdetect=skip=0 -f null -
運用例。
ffplay -f lavfi -i color=white -vf fillborders=0:0:32:16:2,cropdetect
ffplay -f lavfi -i color=white -vf fillborders=0:0:32:16:2,crop=320:192:0:32
以下のようなログが1フレーム毎に流れる。
x1:0 x2:319 y1:32 y2:223 w:320 h:192 x:0 y:32 pts:2 t:0.080000 crop=320:192:0:32
- x1, x2 は黒枠を除外した横座標の開始と終了ピクセルで、0ピクセル開始
- y1, y2 は黒枠を除外した縦座標の開始と終了ピクセル、0ピクセル開始
- w, h, x, y は
crop
フィルタで指定する引数
埋め込まれたビデオ領域を見つけ、事前にモーション ベクトルを生成する。
ffmpeg -i input -vf mestimate,cropdetect=mode=mvedges,metadata=mode=print -an -f null -
埋め込まれたビデオ領域を見つけ、デコーダからのベクトルを使用する。
ffmpeg -flags2 +export_mvs -i input -vf cropdetect=mode=mvedges,metadata=mode=print -an -f null -
関連フィルタ
公式ドキュメント:FFmpeg Filters Documentation : cropdetect
Continue reading “映像の黒枠の場所を検出する cropdetect”