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

MacFH - C E Macfarlane - News news at macfh.co.uk
Sat Jan 8 22:20:46 EET 2022

On 08/01/2022 19:38, Simon van Bernem via ffmpeg-user wrote:
> ffmpeg -i input.mkv
>      -vf "select='1-between(t,20,25)-between(t,100,200)
>      -between(t,220,300)-between(t,400,600)-between(t,750,800)
>      -between(t,820,860)-between(t,880,900)-between(t,1000,1200)
>      -gt(t,1500)'"
>      -af "aselect='1-between(t,20,25)-between(t,100,200)
>      -between(t,220,300)-between(t,400,600)-between(t,750,800)
>      -between(t,820,860)-between(t,880,900)-between(t,1000,1200)
>      -gt(t,1500)'" output3.mkv
> Is there a way to cut up a video into multiple parts using the select
> filter without having the video and audio go out of sync or having
> glitchy video playback? If not, what is the best alternative?

To select parts of a video, I use ...

FFMPEG -ss <start-time> -i <input> -codec copy -to <end> <output>

... however it's tedious, because with this method the video will only 
break at certain points between compression units (can't remember the 
proper terminology), and it can take some experimentation to find the 
precise timing of these to get the audio right as well, and often, 
because of the way the compression works, the first extracted frame is 
often an unwanted last frame of a previous scene.

I have long lamented that FFMPEG doesn't make this both easier and to 
allow greater resolution, if necessary recreating the start and end 
compression units to get the exact timing wanted.

More information about the ffmpeg-user mailing list