Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a folder full of FFMPEG batch files that I've written to do various conversion tasks. These allow me to drag and drop a bunch of files and do a conversion - for example, decompressing MP3 to WAV files, cropping XVID files etc.

Now I want to write one that splits an MP3 into smaller chunks. There's a neat FFMPEG command for this

ffmpeg -f mp3 -i /path/to/file.mp3 -t 00:00:00 -ss 00:10:00 -y /path/to/save.mp3

However, this only extracts the first 10 minutes. To go through the whole MP3 I'd have to write similar statements for every 10 minutes of the MP3's length. Is there a way to tokenise this in batch files?

share|improve this question

Well, there's two ways to go about this:

  1. You can provide the batch file with command line arguments ffchunk.cmd *start* *end* which will give you flexibility in determining the chunk lengths. The batch file would look something like this:

    `ffmpeg -f mp3 -i /path/to/file.mp3 -t 00:%1:00 -ss 00:%2:00 -y

    , where the %1 and %2 represent the first and second arguments given at the command line, respectively. You would invoke it as ffchunk 00 10.

  2. Provide a loop inside the batch file to iterate as much as you need:

     `@echo off
     for /L %%i in (1,1,10) do (
      set /a j=%%i-1
      set k=%%i
      if !j! lss 10 set j=!j!0
      if !k! lss 10 set k=!k!0
      ffmpeg -f mp3 -i /path/to/file.mp3 -t 00:!j!:00 -ss 00:!k!:00 -y /path/to/save!j!-!k!.mp3
share|improve this answer
Thanks scott. Good answer re: looping and and iterating. I'm accepting the other answer as it's a simpler way to do what I'm after, but I'm also giving yours an upvote. – roryok Sep 26 '13 at 8:48

You could use ffmpeg's segment muxer. Something like:

ffmpeg -i input.mp3 -map 0 -c copy -f segment -segment_time 600 out-%02d.mp3

...will produce a number of files along the lines of out-00.mp3, out-01.mp3, and so on, each 600 seconds long (except for the final part, which will be the remainder). There are accuracy issues using the segment muxer with videos (though these can be overcome, see the documentation I linked to), but I've never had any problems when working with audio files.

share|improve this answer
That seems like the best way to do it. a neat, one line ffmpeg command. thanks! – roryok Sep 26 '13 at 8:49
EDIT: I get a bunch of errors with that 'unrecognized option -c', if I change that to -acodec 'unrecognized option -segment_time' – roryok Sep 26 '13 at 8:58
@royok what version of ffmpeg are you using? Make sure you're using an up-to-date version (works for me with the static version linked to here). – evilsoup Sep 26 '13 at 9:19
I am using an older version. but when I upgrade to that static version I get other errors associated with using a drag and drop batch file. ffmpeg seems to take the name of the batch file as a parameter rather than the name of the dropped file! – roryok Sep 26 '13 at 13:46
Dang, sorry to hear that. Sounds like you might want to hit up the ffmpeg users mailing list (they will insist that you use the most recent version though). More than once I've brought issues up there, and then some developer has fixed it within the week. – evilsoup Sep 26 '13 at 16:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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