4

While searching through U&L I noticed a fair amount of questions asking how to script the generation of ffmpeg command lines like these:

ffmpeg -i video.mp4 -ss 00:00:00 -t 00:10:00 -c copy 01.mp4
ffmpeg -i video.mp4 -ss 00:10:00 -t 00:10:00 -c copy 02.mp4
ffmpeg -i video.mp4 -ss 00:20:00 -t 00:10:00 -c copy 03.mp4

In researching solutions for this I stumbled across this ticket in the ffmpeg issue tracker, titled: Split an input video into multiple output video chunks.

This ticket highlights a patch that would allow you to finally be able to provide a list of time points to cut a video into smaller sections with a single command line like this:

$ ffmpeg -i input.avi -f segment -segment_times 10,20,40,50,90,120,180 \
      -vcodec copy output02%d.avi

The patch appears to have been released in this revision of the code repository:

commit 2058b52cf8a4eea9bf046f72b98e89fe9b36d3e3
Author: Stefano Sabatini <stefasab@gmail.com>
Date:   Sat Jan 28 22:36:38 2012 +0100

    lavf/segment: add -segment_times option

    Address trac ticket #1504.

I downloaded this statically built version of ffmpeg, ffmpeg.static.64bit.2013-10-05.tar.gz from the ffmpeg site, but it apparently didn't include that switch.

$ ./ffmpeg --help |& grep segment
$

Has anyone been able to get this new switch working?

  • Not for ffmpeg version 0.8.16-6:0.8.16-1 built on Sep 16 2014 23:10:48 with gcc 4.7.2 obtained from http://http.debian.net/debian/ wheezy/main ffmpeg amd64 6:0.8.16-1. It fails with Unrecognized option 'segment_times'. – Luis Antolín Cano Nov 13 '14 at 11:38
  • I found this. Is it what you're describing? – Justin Coffi Nov 29 '14 at 2:03
1

Is it because the missing -map option, which designates the input streams as a source for the output file. I'm using ffmpeg 2.6.1 and is able to split the video with -segment_times:

ffmpeg -i foo.mp4 -segment_times 10,20,30,40 -c copy -map 0 -f segment  %03d.mp4

If you need more elaborate splitting, you can use OpenCV to read the original video and write desired frame to the new split. Check these out: "Creating a video with OpenCV" and "Split a video to multiple chunks according to multiple starting and ending frame indices"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.