The result depends on what your boundary means. atrim=start=1:end=2 follows audio frame timestamps in seconds, while start_sample=... and end_sample=... count samples that pass through the filter. Those choices can diverge when the input begins at a non-zero timestamp or its timestamps are inaccurate. Trimming also leaves timestamps unchanged, so a correctly selected excerpt can still begin at 2.4 seconds until asetpts is applied. The decision is therefore two-part: select by source clock or sample count, then decide whether the delivered clock should begin at zero.
Decide and operate
Use timestamp boundaries when the source clock is the contract: for example, keep the material whose interval is 3.4–4.4 seconds in the input audio timestamps' time coordinate. These values are not offsets from the first sample. Before trimming, confirm that the input timestamp coordinate matches the source-time coordinate meant by the delivery requirement. Use sample boundaries when the required result is an exact number of samples, such as a fixed-length processing window. For a half-open sample range, if the first retained sample number is N and the required count is L, use start_sample=N:end_sample=N+L; end_sample is the number of the first sample to drop. Do not treat a duration expressed in seconds as an exact sample-count request; the documentation describes duration as a timestamp-based option.
- Record the input sample rate, channel layout, first audio timestamp, requested boundary basis and expected output start. A non-zero first timestamp is a trigger to compare both methods rather than assuming they are equivalent.
- Make a timestamp-based candidate, such as
-af "atrim=start=3.4:end=4.4", only after confirming that 3.4 and 4.4 are in the input audio timestamp coordinate used by the source-time requirement. For a sample-count requirement, identify the first retained sample number N and required count L, then use-af "atrim=start_sample=N:end_sample=N+L". The range is half-open: N is retained and N+L is the first sample dropped, so the requested range contains L samples. - If the output must start at zero, append
asetpts=PTS-STARTPTSafteratrim, for example-af "atrim=start=3.4:end=4.4,asetpts=PTS-STARTPTS". The official `atrim` documentation explicitly separates selection from timestamp modification. - Inspect the decoded first and last audio content, the retained sample count and the output start timestamp. Approve the candidate only against the recorded contract, not against a filename or command exit status.
When several atrim start or end constraints are combined, the filter keeps samples satisfying at least one constraint. If the requirement is that all constraints apply together, chain separate atrim filters, as described in the same FFmpeg filter reference.
Acceptance worksheet
The following is a hypothetical comparison, not a measured FFmpeg result; comparing candidates is an author-recommended check. Assume a 48,000 Hz mono source whose first timestamp is 2.4 seconds, and that its input timestamp coordinate is also the source-time coordinate required for delivery. The requested timestamp interval is 3.4–4.4 seconds. For the separate exact-count candidate, assume the first retained sample number is N and the required count is 48,000, so the half-open sample range is N through N+48,000, with N+48,000 as the first dropped sample. Record observations from the actual decoded candidates.
| Candidate | Boundary contract | Hypothetical observation to record | Decision |
|---|---|---|---|
| A | Input timestamp coordinate 3.4–4.4 s, confirmed to match the required source-time coordinate | Record the first retained sample's input timestamp and the first dropped sample's timestamp; output start may remain at 3.4 s | Use when source-time alignment governs |
| B | Half-open sample range [N, N+48,000) | Record first retained number N, first dropped number N+48,000, and actual retained count (expected: 48,000); content may not align with the requested source clock if timestamps drift | Use when sample count governs |
| C | Candidate A plus asetpts | Same selected content as A; verify that the output timestamp begins at zero | Use when source alignment and zero-based delivery are both required |
This worksheet distinguishes the documented selection rule from your observation. The documentation does not establish a universal sample index or duration-reporting format for every container, so verify those fields with the inspection tools used in your workflow.
Limits and next steps
If A and B disagree, first classify the mismatch: non-zero start, inaccurate timestamps, or an input whose timestamp progression is not suitable for the intended contract. Do not “fix” the disagreement by changing the boundary until the delivery requirement is explicit. If source-time placement matters, retain the timestamp-based result and investigate the input timing. If exact samples matter, retain the sample-based result and verify the count independently.
If the first or last spoken syllable is wrong, inspect decoded audio around both edges. atrim selects a continuous subpart; it does not infer speech boundaries, remove clicks, repair missing samples or guarantee perceptual silence. If several constraints were intended as an intersection but were supplied to one filter, chain them. If the output clock is wrong, check that asetpts follows atrim and inspect the resulting timestamps rather than assuming the filter graph changed the audio selection.
Three quick questions
Why did `end=1` not produce exactly one second? Because end is evaluated against frame timestamps and the first dropped sample is the one at that boundary. It is not the sample-count form of the request. Use end_sample when the contract is an exact count.
Why does the excerpt sound right but begin at 2.4 seconds? Selection and timestamp origin are separate. A non-zero source start can remain until a timestamp-reset filter is applied after trimming.
Should I use `start_pts` instead? Use it when the boundary is expressed in the input’s sample-based timestamp units. Do not confuse it with start_sample: the documentation treats the former as a timestamp boundary and the latter as a count of samples passing through the filter.
Sources and next step
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.