実行環境
Node.jsでの実行を想定しているためJavaScriptコードになります。
コマンドラインで同様のコマンドを打てばNode.js以外でも実行可能です。
動画の先頭に無音黒画面を挿入
const{execSync}=require('child_process');functionInsert_haed_blank(input,duration,output){execSync(`ffmpeg -i ${input} -vf tpad=start_duration=${duration}:color=black -af "adelay=${duration}s:all=1" ${output}`);}
パラメータ
- input:入力動画パス
- duration:挿入する無音黒画面時間(秒)
- output:出力動画パス
コマンド内容
-vf tpad=start_duration=${duration}:color=black
がvideo、-af "adelay=${duration}s:all=1"
がaudioの設定になります。
挿入する無音黒画面期間をフレーム数で指定する場合は、tpad=start_duration=
をtpad=start=
に変更します。
白画面を挿入する場合は、color=black
をcolor=white
に変更します。adelay=${duration}s
で音声の開始をduration秒だけ遅延させています。all=1
はaudioの全チャンネルを指定しています。
動画の末尾に無音黒画面を挿入
const{execSync}=require('child_process');functionInsert_end_blank(input,duration,output){execSync(`ffmpeg -i ${input} -vf tpad=stop_duration=${duration}:color=black -af "apad=pad_dur=${duration}" ${output}`);}
パラメータ
先ほどと同様
コマンド内容
-vf tpad=stop_duration=${duration}:color=black
がvideo、-af "apad=pad_dur=${duration}"
がaudioの設定になります。
挿入する無音黒画面期間をフレーム数で指定する場合は、tpad=stop_duration=
をtpad=stop=
に変更します。