[FFmpeg-user] the trim filter

Mark Filipak markfilipak.imdb at gmail.com
Fri Jul 5 22:50:00 EEST 2024


On 04/07/2024 17.11, Paul B Mahol wrote:
> On Thu, Jul 4, 2024 at 10:44 PM Mark Filipak <markfilipak.imdb at gmail.com>
> wrote:
> 
>> On 04/07/2024 14.22, Paul B Mahol wrote:
>>> On Thu, Jul 4, 2024 at 8:05 PM Mark Filipak <markfilipak.imdb at gmail.com>
>>> wrote:
>>>
>>>> Is there some secret to the trim filter?
>>>>
>>>> --filter_complex "split=2[i5][i6],
>>>>     [i5]trim=start_frame=481:end_frame=134047[o5],
>>>>     [i6]trim=start_frame=138745:end_frame=246719[o6],
>>>>     [o5][o6]concat=n=2"
>>>>
>>>> I get "dup=481", instead, and wind up with 20.061708[3..] seconds of
>> black
>>>> frames preceding the
>>>> segment I want, and the frame rate is 19.181 FPS.
>>>>
>>>>
>>> You need to rewrite audio timestamps, otherwise you get 'empty' gaps.
>>
>> Have you found an atrim expression that works?
>>
>> I tried adding atrim=start=20.062. Now playback goes for 20.061708[3..]
>> sec of black frames, then
>> freezes for another 20.061708[3..] sec, then continues as though nothing
>> strange had happened.
>>
> 
> You need to rewrite timestamps otherwise you get discontinuities.
> Also note that each frame have certain number of audio samples in it.

Thanks, Paul.

Unless FFmpeg surprises me yet again, rewriting TSes should be unnecessary. I've been careful to 
always use '-copyts' and '-muxdelay 0' to keep FFmpeg from changing TSes. In an m2ts, all timebases 
are 1/90000Hz, so after the trims and the splice, all the TSes should be correct and should not need 
rewriting -- at least, that's what I hope.

--Mark.



More information about the ffmpeg-user mailing list