TransWikia.com

Trim video into multiple sections ffmpeg

Super User Asked by fitzmode on January 10, 2021

I need to trim a video into multiple sections of unequal duration and output them as separate files.

For example a .mp4 100 seconds long and I need to extract and keep

  • output0.mp4 from 5 – 10sec
  • output1.mp4 from 10 – 20 sec
  • output2.mp4 from 35 – 60 sec

Current Solution:

ffmpeg -i video.mp4 -c copy  -t 5  output0.mp4 -ss 10 -c copy -t 10 output1.mp4 -ss 20 -c copy -ss 35 t 60  output2.mp4 -y

Current solution works but is there a way to group process and index the output with a format specifier?
Something like below or an alternative method without re-encoding?

ffmpeg -i video.mp4  -c copy -t 5 -ss 10  -t 10 -ss 20 -y output%d.mp4

My alternative solution using segment has the problem that it also returns an output3.mp4 from 60 – 100sec and the durations aside from output0.mp4 do not match the expected values.

ffmpeg -i video.mp4 -c copy -f segment -segment_times 5,10,20,35,60 output%d.mp4

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP