LoginSignup
2
1

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-10-04

実行環境

Node.jsでの実行を想定しているためJavaScriptコードになります。
コマンドラインで同様のコマンドを打てばNode.js以外でも実行可能です。

動画の先頭に無音黒画面を挿入

const { execSync } = require('child_process');

function Insert_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');

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

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1