How to Fix Negative Start Timestamps in FFmpeg

Negative start timestamps in FFmpeg commonly occur when stream-copying media, cutting video without re-encoding, or dealing with B-frame reordering and audio sync offsets. This guide explains the root causes of negative initial timestamps and outlines the exact flags and commands required to normalize presentation timestamps (PTS) back to zero without causing audio-video desynchronization.

Why Negative Timestamps Occur

When you inspect a file using ffprobe, you might see a start time like -0.022000. This usually happens for two reasons:

  1. Container Delays: Audio tracks often start slightly before video tracks to prime the decoder.
  2. Stream Copying Cuts: Using -ss with -c copy slices packets at keyframes. If the audio packet or a decoded video frame (like a B-frame) references a frame prior to the cut point, FFmpeg shifts timestamps backward to preserve playback order.

Solution 1: Use the -avoid_negative_ts Flag

The simplest and most effective way to shift timestamps without re-encoding is using the -avoid_negative_ts flag.

ffmpeg -i input.mp4 -c copy -avoid_negative_ts make_zero output.mp4

This flag accepts several parameters:

  • make_zero (or 1): Shifts all timestamps so that the first timestamp becomes exactly 0.
  • make_non_negative: Shifts timestamps only if the first timestamp is less than 0, ensuring no timestamps are negative.
  • auto: Enables shifting automatically if the target container format does not support negative timestamps.
  • disabled (or 0): Preserves the source timestamps, even if negative.

Solution 2: Reset Presentation Timestamps (PTS) During Re-encoding

If you are re-encoding your media, you can explicitly reset the presentation timestamps for both audio and video streams to zero using filters.

ffmpeg -i input.mp4 -vf "setpts=PTS-STARTPTS" -af "asetpts=PTS-STARTPTS" -c:v libx264 -c:a aac output.mp4
  • -vf "setpts=PTS-STARTPTS" resets the video PTS to begin at 0.0.
  • -af "asetpts=PTS-STARTPTS" resets the audio PTS to match the start of the audio stream.

Note: If your audio and video have different initial offsets, resetting both independently may cause a slight sync offset. If drift occurs, use Solution 1 or encode the video with -vf "setpts=PTS-STARTPTS" and let the audio track align via -async 1.


Solution 3: Proper Trimming with -ss and -copyts

When trimming video, the position of the -ss flag in the command determines how timestamps are calculated.

To trim quickly using stream copy while forcing the output to start cleanly at zero:

ffmpeg -ss 00:01:30 -i input.mp4 -to 00:02:30 -c copy -avoid_negative_ts make_zero output.mp4

Placing -ss before -i enables fast seeking to the nearest keyframe, while -avoid_negative_ts make_zero ensures that the newly created segment resets its timeline to 00:00:00.000 instead of carrying over residual timeline offsets.


Verifying the Fix

After running your command, verify that the start time has returned to zero using ffprobe:

ffprobe -v error -show_entries format=start_time -of default=noprint_wrappers=1:nokey=1 output.mp4

The output should return 0.000000 or a very small negligible positive value (e.g., 0.000000 to 0.001000 depending on container format tolerances).