Shift Video Timestamps with FFmpeg setpts

This article explains how to shift video timestamps forward or backward by a constant offset using FFmpeg's setpts filter. Adjusting the Presentation Time Stamp (PTS) allows you to resolve audio/video desynchronization or correct media stream starting points directly from the command line.

The setpts Filter Syntax

The setpts filter alters the PTS of each incoming video frame using an expression. To shift timestamps by a fixed duration, add or subtract the desired time offset divided by the stream's time base (TB). The general syntax is:

setpts=PTS+[OFFSET]/TB
  • PTS: The original presentation timestamp of the current frame.
  • OFFSET: The time shift in seconds (can be a decimal, such as 0.5).
  • TB: The internal time base of the video stream, which scales seconds to timestamp units.

Shifting Timestamps Forward (Delaying Video)

To delay the video stream by shifting all presentation timestamps forward by 3 seconds:

ffmpeg -i input.mp4 -vf "setpts=PTS+3/TB" -c:a copy output.mp4

This command keeps the audio intact while moving every video frame 3 seconds later into the presentation timeline.

Shifting Timestamps Backward (Advancing Video)

To advance the video stream so frames appear earlier, subtract the offset:

ffmpeg -i input.mp4 -vf "setpts=PTS-2.5/TB" -c:a copy output.mp4

This shifts every frame backward by 2.5 seconds.

Note: Shifting timestamps backward can generate negative timestamps for frames at the beginning of the file. Most modern containers (such as MP4 or MKV) handle initial negative timestamps, but if playback issues occur, you may need to trim the beginning of the stream or remux the container.

Adjusting Audio Simultaneously

If you want the entire file shifted rather than fixing a desync between video and audio, apply the corresponding asetpts filter to the audio stream:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=PTS+2/TB[v];[0:a]asetpts=PTS+2/TB[a]" -map "[v]" -map "[a]" output.mp4