0

I've got time codes using which I want to slice a short MP4 video (average length 5-7 minutes)

[ 0, 15, 35, 52, 142, 215, ...] // time codes in seconds

Usually there are 5-7 time codes meaning that I need to create 5-7 clips out of my initial video
The fist clip is from start to 15 sec, the second one is from 15 sec to 35 sec, 35-52, etc.

It's trivial operation in Bash but I'm using ffmpeg on NodeJS and I'd like to do it without iteration in one go

// Slicing a single clip
ffmpeg -i input.mp4 -ss 0 -to 15 -c copy clip-01.mp4

// Same command in NodeJS
ffmpeg(`/tmp/${id}/input.mp4`)
  .renice(5)
  .outputOptions([
    '-ss 0',
    '-to 15',
    '-c copy'
  ])
  .on('end', () => {})
  .on('error', (e, stdout, stderr) => {})
  .save(`/tmp/${id}/clip-01.mp4`);

No need for re-encoding, no need for precise timestamps (1 second out of sync is OK)
Any thoughts or ideas would be greatly appreciated!

Igniter
  • 857
  • 9
  • 24
  • what prevents you to write a function with signature ```(ss, to, outname)``` which calls ffmpeg on the corresponding slice? – grodzi Dec 01 '19 at 18:12
  • The segment muxer has a -segment_times option which takes in a series of comma-separated timestamps for segmenting the input e.g.: `ffmpeg -i in -c copy -f segment -segment_times 0,15,35,52,142,215 out%d.mp4` – Gyan Dec 01 '19 at 18:26
  • @Gyan thank you, this looks exactly what I was looking for! checking how it will work out on NodeJS – Igniter Dec 01 '19 at 19:27

0 Answers0