How to Use FFmpeg tpad Filter for Video Padding
This guide explains how to use the tpad (temporary
padding) filter in FFmpeg to add extra frames to the beginning or end of
a video. You will learn the key parameters of the filter, including how
to control the padding duration, choose custom colors, and clone
existing frames to create a freeze-frame effect at the start or end of
your file.
Understanding the tpad Filter
The tpad filter is a video filter (-vf) in
FFmpeg designed to temporarily pad video streams. This is highly useful
for adding intro/outro buffers, inserting black screens, or holding on
the first/last frame of a video.
The filter is configured using four primary options to control timing:
start: The number of frames to add to the start of the video.stop: The number of frames to add to the end of the video.start_duration: The duration (in seconds) of padding to add to the start.stop_duration: The duration (in seconds) of padding to add to the end.
How to Customize the Padding Style
By default, tpad adds solid black frames. You can
customize this behavior using the following parameters:
color: Specifies the color of the padded frames (e.g.,red,white,blue, or hex codes like0x00FF00).start_modeandstop_mode: Determines what content fills the padded area.add(default): Fills the padding with the color specified in thecolorparameter.clone: Duplicates the very first frame (forstart_mode) or the very last frame (forstop_mode) to create a freeze-frame effect.
Practical Examples
Here are the most common ways to implement the tpad
filter.
1. Add Black Padding by Duration
To add 3 seconds of black video to the beginning and 5 seconds of black video to the end of your input file:
ffmpeg -i input.mp4 -vf "tpad=start_duration=3:stop_duration=5" output.mp42. Freeze the First and Last Frames (Clone Mode)
If you want to pause the video on the first frame for 2 seconds
before it plays, and freeze the last frame for 4 seconds when it ends,
use the clone mode:
ffmpeg -i input.mp4 -vf "tpad=start_duration=2:start_mode=clone:stop_duration=4:stop_mode=clone" output.mp43. Add Custom Colored Padding
To add 2 seconds of solid red padding to the start of the video:
ffmpeg -i input.mp4 -vf "tpad=start_duration=2:color=red" output.mp44. Padding by Frame Count
If you prefer to work with exact frame counts rather than seconds,
use start and stop. For example, to add
exactly 30 frames of padding to the end of a video:
ffmpeg -i input.mp4 -vf "tpad=stop=30" output.mp4Note: If your video contains audio, adding video padding with
tpad will not automatically pad the audio stream. You may
need to use audio filters like adelay or
aresample to keep the audio and video in sync.