2つ以上の映像を入力してフィルタを当てるときにそれらの読み込み開始時間は等しくなる。これを -ss
オプションや trim
フィルタを使って読み込み開始時間をずらす方法。対象となるフィルタは overlay, blend
などの2映像のチャンネルを合わせるフィルタである。
コマンド例
overlay
フィルタは有効になると2入力が映り、無効になると1入力が映る。color は黒映像のテストソース、testsrc2 は時間とフレーム番号のテストソース。
2映像とも開始0秒から overlay
フィルタを適用する
ffmpeg -f lavfi -i color -f lavfi -i testsrc2 -filter_complex overlay output
2映像とも開始3秒から overlay
フィルタを適用する。詳しくは 特定の区間だけフィルタを当てるタイムライン編集について を参照
ffmpeg -f lavfi -i color -f lavfi -i testsrc2 -filter_complex overlay=enable='gte(t,3) output
1映像は開始0秒から、2映像は開始2秒から overlay
フィルタを適用する。指定した時間に GOP 間隔が途切れていればこれでよい
ffmpeg -f lavfi -i color -ss 2 -f lavfi -i testsrc2 -filter_complex overlay output
1映像は開始0秒から、2映像は開始2秒から overlay
フィルタを適用する。上の方法で2秒から始まらない場合はこちらを使う
ffmpeg -f lavfi -i color -f lavfi -i testsrc2 -filter_complex [1:v]trim=2,setpts=PTS-STARTPTS,[0:v]overlay output
1映像は開始0秒から2秒まで、2映像は開始0秒から overlay
フィルタを適用する
上下同じ結果になるが下の方は overlay
フィルタが2秒以降無効になるのでこちらの方が処理が早い
ffmpeg -f lavfi -i color -f lavfi -i testsrc2 -filter_complex [1:v]split[1a],trim=duration=2,setpts=PTS-STARTPTS[1b];[1b][1a]concat,[0:v]overlay=enable='gt(t,2)' output
ffmpeg -re -f lavfi -i color -f lavfi -i testsrc2 -filter_complex [1:v]split[1a],trim=duration=2[1b];[1b][1a]concat,setpts=PTS-STARTPTS[1c];[1c][0:v]overlay=enable='lte(t,2)' output