How to Use FFmpeg start_at_zero with Copy Timestamps
This article explains how to use the -start_at_zero
option in FFmpeg when preserving original input timestamps. You will
learn what this option does, why it is necessary for maintaining
audio-video synchronization, and the exact command-line syntax required
to apply it to your media processing workflows.
Understanding the Problem
By default, FFmpeg resets the presentation timestamps (PTS) of the
input file so that the output video starts at zero. However, when you
use the -copyts (copy timestamps) flag—which is often
necessary when cutting or splicing videos without re-encoding—FFmpeg
preserves the original timestamps from the source file.
If your source video segment starts at 10 seconds, the output file’s first frame will also have a timestamp of 10 seconds. This can lead to playback issues, such as a frozen first frame or blank screen for the first 10 seconds in many media players.
The Solution: -start_at_zero
The -start_at_zero option solves this issue. When used
in conjunction with -copyts, it shifts all the copied
timestamps backward by the exact offset of the first packet. This
ensures that the output file starts playing immediately at
00:00:00 while maintaining the relative intervals and
synchronization of the original timestamps.
Basic Command Syntax
To use -start_at_zero, you must place it after the
-copyts option and before the input file (-i).
Here is the standard command structure:
ffmpeg -copyts -start_at_zero -i input.mp4 -c copy output.mp4Parameter Breakdown
-copyts: Instructs FFmpeg to copy the input timestamps to the output rather than generating new ones.-start_at_zero: Shifts the copied timestamps so that the earliest output packet starts at zero. This option only works when-copytsis active.-i input.mp4: Specifies the input file.-c copy: Copies the video and audio streams without re-encoding, preserving quality and processing the file almost instantly.
Practical Example: Cutting Video with Copy Timestamps
A common use case is trimming a video from a specific start time without re-encoding, which requires high timestamp accuracy to prevent audio desynchronization:
ffmpeg -ss 00:01:30 -copyts -start_at_zero -i input.mp4 -t 30 -c copy output.mp4In this command: 1. -ss 00:01:30 seeks to the 1-minute
and 30-second mark. 2. -copyts ensures the timestamps
starting from 00:01:30 are copied. 3. -start_at_zero shifts
that 00:01:30 start point to 00:00:00 in the final output. 4.
-t 30 limits the output duration to 30 seconds.