[FFmpeg-user] Removing parts of a video using the select filter

Leo Butler leo.butler81 at googlemail.com
Sun Jan 9 22:06:26 EET 2022


Simon van Bernem via ffmpeg-user <ffmpeg-user at ffmpeg.org> writes:

>  Those look very promising, but my version of ffmpeg doesn'tknow the segment filter. I found it in the changelog for version5, but the website lets me only download 4.4 and the github'slast release is 3.0 from 2016. Is the segment filter not availablefor the general public yet?
> Regards,Simon
>
>     Am Sonntag, 9. Januar 2022, 15:53:27 MEZ hat Nicolas George <george at nsup.org> Folgendes geschrieben:  
>  
>  Simon van Bernem via ffmpeg-user (12022-01-08):
>> Hi,
>> I am trying to remove parts of a video (with audio) using the select
>> filter. I constructed this command to remove seconds 20-25:
>> 
>> (newlines only for readability)
>> 
>> ffmpeg -i input.mkv
>>   -vf "select='1-between(t,20,25)', setpts=N/FRAME_RATE/TB"
>>   -af "aselect='1-between(t,20,25)', asetpts=N/SR/TB" output.mkv
>> 
>> This works great, except that when I use multiple "between" clauses
>> to discard multiple sections, audio and video will start to get out of
>> sync.
>
> The select filter is very generic, and therefore not very robust. It
> does not update the timestamps, hence the need to update them
> afterwards. Furthermore, it works with whole frames, which can
> accumulate for audio.
>
> For your use case, consider the segment and concat filters.

If you do not want any re-coding, then I suggest using the concat
muxer. I use this for cutting editing screencasts before adding chapter
markers, etc., and doing a transcoding.

See section 20.5 of the ffmpeg manual.

https://ffmpeg.org/ffmpeg-all.html#toc-concat-1

Otherwise, as Nicolas says, use the concat filter with multiple inputs,
e.g.

ffmpeg -ss time1 -t duration1 input1 -ss time2 -t duration2 input2
...concat=n=2:v=1:a=1...

Leo


More information about the ffmpeg-user mailing list