Seek FFmpeg Input with Broken Timestamps

Seeking in media files with broken, corrupt, or missing presentation timestamps (PTS) using FFmpeg often results in inaccurate seek points, frozen video, or out-of-sync audio. This article explains how to successfully seek through damaged files by using output-side seeking, forcing FFmpeg to regenerate missing timestamps, ignoring corrupted packets, or remuxing the file to reconstruct a healthy index.

Method 1: Use Output-Side Seeking

The most straightforward way to bypass broken container timestamps is to perform output-side seeking.

By default, placing the seek parameter (-ss) before the input (-i) performs an input-seeking operation, which relies heavily on the container’s index. If you place -ss after the input, FFmpeg will read and decode the stream from the very beginning, discarding the frames until it reaches the specified timestamp.

ffmpeg -i input.mp4 -ss 00:02:30 -c:v libx264 -c:a aac output.mp4

Note: This method is highly accurate but slower because FFmpeg must decode the video from the beginning up to the seek point.

Method 2: Regenerate Timestamps on the Fly

If the file is missing timestamps entirely, you can force FFmpeg to generate new presentation timestamps (PTS) during the input reading phase using the -fflags +genpts flag.

ffmpeg -fflags +genpts -ss 00:02:30 -i input.mp4 -c:v copy -c:a copy output.mp4

Combining -fflags +genpts with input seeking allows FFmpeg to rebuild the timeline as it parses the file, often restoring the ability to seek quickly and accurately.

Method 3: Ignore Corrupt Decoding Timestamps

When files have corrupted Decoding Timestamps (DTS), FFmpeg may get stuck or throw errors during seeking. You can instruct FFmpeg to ignore DTS stream data and rely on the generated PTS instead by combining flags:

ffmpeg -fflags +igndts+genpts -ss 00:02:30 -i input.mp4 -c:v libx264 output.mp4

Method 4: Remux the File to Fix the Index

If you need to perform multiple seek operations on the same file, it is more efficient to repair the file container first. Remuxing copies the audio and video streams into a new container without re-encoding, while regenerating a clean timestamp index.

ffmpeg -err_detect ignore_err -fflags +genpts -i input.mp4 -c copy fixed_input.mp4

Once the repaired fixed_input.mp4 file is generated, you can use standard, fast input-side seeking without any issues:

ffmpeg -ss 00:02:30 -i fixed_input.mp4 -c copy output.mp4