Configure Padding Color and Duration in FFmpeg tpad

The tpad (temporal pad) video filter in FFmpeg allows you to add extra video frames to the beginning, the end, or both ends of a video stream. This article explains how to define the exact duration of the added padding using either time or frame counts, and how to set a specific solid color for those padded frames using color names or hexadecimal values.

Core Parameters for Duration and Color

The tpad filter accepts several key options to control where frames are added, how long they last, and what color they display:

  • start: Number of frames to delay the input video by padding at the start.
  • stop: Number of frames to append after the input video ends.
  • start_duration: Duration of the padding at the start, specified in seconds (e.g., 3) or time format (e.g., 00:00:03.5).
  • stop_duration: Duration of the padding at the end, specified in seconds or time format.
  • color: The color of the padded frames. Defaults to black. Accepts standard color names (such as white, red, blue) or hexadecimal color codes (such as 0x00FF00 or #FF5733).

Setting Duration by Time

To specify padding based on seconds rather than calculating individual frame counts, use start_duration or stop_duration.

Pad 3 seconds of black frames at the beginning and 5 seconds of black frames at the end:

ffmpeg -i input.mp4 -vf "tpad=start_duration=3:stop_duration=5" -c:a copy output.mp4

Setting Custom Colors

By default, padded frames are black. You can change this using the color parameter.

To add 2 seconds of white padding to the start of the video:

ffmpeg -i input.mp4 -vf "tpad=start_duration=2:color=white" -c:a copy output.mp4

To use a hexadecimal color (for example, an orange background #FF6600) for 4 seconds at the end:

ffmpeg -i input.mp4 -vf "tpad=stop_duration=4:color=#FF6600" -c:a copy output.mp4

Setting Duration by Frame Count

If you require frame-accurate padding matching a specific timeline, use start and stop instead of duration.

To add 60 frames to the beginning and 120 frames to the end using blue padding:

ffmpeg -i input.mp4 -vf "tpad=start=60:stop=120:color=blue" -c:a copy output.mp4

Audio Synchronization Considerations

The tpad filter only affects the video stream. If your source video contains audio, you must also delay or pad the audio stream to keep it synchronized. Use the adelay or apad audio filters alongside tpad:

ffmpeg -i input.mp4 -filter_complex "[0:v]tpad=start_duration=2:color=black[v];[0:a]adelay=2000|2000[a]" -map "[v]" -map "[a]" output.mp4

In this command, adelay=2000|2000 delays both audio channels by 2,000 milliseconds (2 seconds) to match the 2-second tpad video delay.