Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8691

FFmpeg 動画の前後に無音黒画面を挿入

$
0
0

実行環境

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=blackcolor=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=に変更します。


Viewing all articles
Browse latest Browse all 8691

Trending Articles