ffmpeg 3.2でリリースしたビデオフィルタ。エッジ検出フィルタに単体ではedgedetect
とfrei0r
のsobelがあり、カーネルを指定するconvolution
でもエッジ検出ができるが、今回のこれらのフィルタはedgedetect
よりもエッジ部分の線が太くconvolution
よりも手軽なのでマスクするのにも便利。sobel
とprewitt
、roberts
はカーネルが少し異なるがオプションは同じである。
- ffmpeg でエッジマスク
- エッジ検出フィルタscharr
- エッジ検出フィルタ roberts
- ffmpeg でエッジ検出をする edgedetect
- 鮮鋭化やぼかし、エンボス処理などができる convolution
基本コマンド
ffmpeg -i input -vf sobel=planes=15:scale=1:delta=0 output
ffmpeg -i input -vf sobel=15:1:0 output
ffplay -i input -vf sobel=15:1:0
- Wikipedia:Sobel operator – Wikipedia
- 公式ドキュメント:FFmpeg Filters Documentation : sobel
- 公式ドキュメント:FFmpeg Filters Documentation : prewitt
オプション
sobel
とprewitt
のオプションは同じ。
- planes[int]
フィルタを当てるチャンネル指定
背景黒とエッジに色をつけるには Y だけに当てる 1 を指定する
詳しくはffmpeg について | チャンネルの順番と注意点を参照
既定値:15(すべてのチャンネル)
範囲:0 から 15 まで - scale[float]
フィルタを当てる乗算値の指定
既定値:1
範囲:0 から 65535 まで - delta[float]
フィルタを当てる加算値の指定
既定値:0
範囲:-65535 から 65535 まで
サンプル画像
アニメ画像



実写画像



opencl を使う
opencl を使ってprewitt_opencl, sobel_opencl
フィルタを使う。
opencl が使えれば以下のコマンドを実行すると対応 CPU、または GPU が表示される。
ffmpeg -hide_banner -v verbose -init_hw_device opencl
出力コマンド例。
ポイントは opencl を使うデバイスを上の例では 0.0 から 1.1 から指定する。能力によって処理速度が大きく異なる。オプション指定は通常と同じ。
コマンド例。
ffmpeg -init_hw_device opencl=ocl:1.0 -filter_hw_device ocl -i input -vf hwupload,prewitt_opencl output
ffmpeg -init_hw_device opencl=ocl:1.0 -filter_hw_device ocl -i input -vf hwupload,sobel_opencl output
通常のフィルタに切り替えるにはhwdownload,format=yuv420p
フィルタを挟む。
ffmpeg -init_hw_device opencl=ocl:1.0 -filter_hw_device ocl -i input -vf hwupload,sobel_opencl,hwdownload,format=yuv420p,lutyuv=val:128:128 output
公式ドキュメント:FFmpeg Filters Documentation : prewitt_opencl
公式ドキュメント:FFmpeg Filters Documentation : sobel_opencl