Insert silent black screen before and after FFmpeg video

Execution environment

Since it is supposed to be executed in Node.js, it will be JavaScript code. If you type the same command on the command line, you can execute it other than Node.js.

Insert a silent black screen at the beginning of the video

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}`);
}

Parameters

--input: Input video path -duration: Silent black screen time to insert (seconds) --output: Output video path

Command content

-vf tpad = start_duration = $ {duration}: color = black is video, -af" adelay = $ {duration} s: all = 1 " is the audio setting.

If you want to specify the silent black screen period to insert by the number of frames, change tpad = start_duration = to tpad = start =. If you want to insert a white screen, change color = black to color = white. ʻAdelay = $ {duration} s delays the start of audio by duration seconds. ʻAll = 1 specifies all audio channels.

Insert a silent black screen at the end of the video

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}`);
}

Parameters

Same as before

Command content

-vf tpad = stop_duration = $ {duration}: color = black is video, -af" apad = pad_dur = $ {duration} " is the audio setting. If you want to specify the silent black screen period to insert by the number of frames, change tpad = stop_duration = to tpad = stop =.

Recommended Posts

Insert silent black screen before and after FFmpeg video
FFmpeg Split screen and combine multiple videos
How to execute processing before and after docker-entrypoint.sh