If you trim an audio stream to keep the same section as a video, removing samples does not by itself guarantee that the retained audio starts at the video’s timeline origin. In FFmpeg, use atrim to select the audio interval and, when the retained segment should start at timestamp zero, follow it with asetpts=PTS-STARTPTS. Then verify that the video and audio are meant to share that origin and review the opening, an internal edit point, and the audio tail. Resetting timestamps changes timing labels; it does not add, remove, or repair audio content.
Decide what “start at zero” means
A stream’s presentation timestamps (PTS) tell a media pipeline when its audio frames should be presented. They are distinct from the samples themselves. Trimming can discard samples outside a chosen interval while the kept frames retain timestamps tied to their earlier position in the source. The result may therefore begin later on the output timeline than intended.
Write down three times before changing the filtergraph: the source interval to retain, the intended start of that interval on the video timeline, and the audio PTS of the first retained frame. If the video excerpt itself begins at zero and its matching audio should begin with it, the target audio PTS is usually zero. If the audio is intentionally delayed relative to the video, preserve that offset instead of resetting it to zero.
The FFmpeg `atrim` documentation describes sample or timestamp-based selection and notes that atrim does not modify timestamps. The FFmpeg `asetpts` documentation covers setting audio timestamps, including expressions for rebasing them. These are separate operations, not two names for the same trim.
Apply the filters in the right order
- Choose the retained audio interval using the source timeline and the same intended boundaries as the video. Be explicit about whether your trim values are timestamps or sample counts; they are different ways to define a selection.
- Apply
atrimfirst so it removes the unwanted part and passes forward the retained audio. - Apply
asetpts=PTS-STARTPTSafteratrimif that retained audio should be rebased so its first output timestamp is zero. In a simple filter chain, the conceptual order isatrim=...,asetpts=PTS-STARTPTS. - Keep the video’s intended timing coherent with the new audio origin. Do not assume that rebasing audio alone changes the video start or automatically synchronizes independently trimmed streams.
- Export a short review segment before producing the full deliverable, then inspect stream timing and listen at the relevant boundaries.
The filter documentation supports the roles of the two filters and their use in a chain. It does not establish that a particular pair of trim values, output container, or export command will suit every source. Confirm option units and time bases for your actual filtergraph, and do not substitute a time-reset expression for the selection boundaries.
Keep a trim record
Use this worksheet to make the intended relationship explicit. The figures below are hypothetical, not a result measured from a real file.
| Checkpoint | Hypothetical value | What to confirm |
|---|---|---|
| Source interval | 12.4–20.0 s | Both streams refer to the intended source passage |
| Video timeline start | 0.0 s | The selected video begins at the output origin |
| First retained audio sample | At source 12.4 s | The intended sound has not been cut off |
| First retained audio PTS before reset | 12.4 s | The kept audio still carries its source-relative time |
| First audio PTS after reset | 0.0 s | Rebased only if the audio should start with the video |
| First audible event | A hypothetical word at output 0.3 s | Its position matches the picture and the edit intent |
A waveform’s first visible non-silent sample is not necessarily the first audible event. Room tone, a breath, or a fade may be intentional. Compare what you hear with the picture and the intended synchronization point rather than requiring all audio energy to begin at zero.
Accept or diagnose the export
Check the opening first: play from the beginning and compare the first intended sound with the corresponding image. A blank audio lead-in can indicate an unintended offset, but it can also be deliberate silence. Next, inspect an internal edit point. If the opening aligns but sound shifts at a later cut, do not assume a global timestamp reset is the answer; check that the audio selection and video cut refer to the same source moment. Finally, listen through the tail and compare the expected end of the retained audio with the video end. Rebasing the start does not guarantee that both streams have matching end boundaries.
If the sound is consistently late by roughly the same amount from opening through the tail, compare the first retained audio PTS with the video origin and decide whether a rebase is intended. If only the start is wrong, revisit the trim boundary and whether a real leading pause should be retained. If timing diverges later, inspect the later cut and stream timing rather than repeatedly shifting the entire audio track. If the audio already has an intentional offset, retain that offset and set the target timeline accordingly.
Do not treat this procedure as a fix for every form of drift, a guarantee of sample-accurate synchronization, or a way to restore samples removed by trimming. Output encoding and the source’s timing characteristics can affect what you observe; the cited filter documentation does not prescribe an export format or certify a particular export. Compare the rendered result in a suitable player or editor, not only the filter expression.
Common questions
Does `atrim` reset the audio clock?
No. Its documented role is to select audio; it does not change timestamps. Use a timestamp-setting filter afterward when a new origin is actually required.
Should I reset audio to zero if the video starts at zero?
Only when the retained audio is intended to start at the same output time. If the edit deliberately places audio later, resetting it to zero would remove that planned offset from the timeline.
Will `asetpts` fix audio that drifts out of sync near the end?
Not by itself. Rebasing changes the timestamp origin; it does not establish that the audio and video durations, later edit boundaries, or source timing are otherwise correct. Check the opening, an internal point, and the tail to locate where the mismatch begins.
Sources and next step
- FFmpeg Filters Documentation
- 8.67 atrim — FFmpeg official documentation
- 20.19 setpts, asetpts — FFmpeg official documentation
This guide interprets public documentation and uses explicitly hypothetical acceptance examples, not application tests. Controls and availability can change; verify the cited manual against your installed version.
For work created in Imagild, carry the input requirements and acceptance checklist into the film workspace. The external software controls discussed above belong to their respective products.