Splitting an audio file into chunks of a specified length

With recent ffmpeg (download a static build from here):

ffmpeg -i in.m4a -f segment -segment_time 300 -c copy out%03d.m4a

This uses the segment muxer and copies the bitstreams. If your file has audio and video streams, you can disable the video stream with -vn.


Here's a one-liner, you just need Ruby and FFmpeg installed:

ruby -e '(0..4500).step(300) { |x| system "ffmpeg -ss #{x} -i in.m4a -c copy -t 300 out-#{x}.m4a"}'

Simply execute that in the same folder where in.m4a is. It'll copy the audio bitstream, so executing this will probably take less than a few seconds.

To explain:

  • 4800 seconds is the length of the audio file (80 minutes × 60 seconds), so our last split is at 4500 (4800 - 300 seconds).
  • We go from 0 to 4500, and we split every 300 seconds (5min × 60s).
  • FFmpeg will start at the time specified by -ss
  • And it'll copy for the time specified by -t
  • It'll write several output files called out-<x>.mp4, where <x> is the start time in seconds.

I was looking for a solution for this myself. The easiest way I found to do this is via MP4Box:

mp4box -split 300 infile.m4a

Where "300" is the time in seconds. MP4Box will automatically write numbered output files.

(You don't need to install the whole big GPAC application. These are the files you can extract from the archive for it to work: js.dll; libeay32.dll; libgpac.dll; MP4Box.exe; ssleay32.dll)


It has been a while since this question was asked, but after fooling around with Ruby and ffmpeg I decided there has to be an easier way to do this within Windows, and I found there is.

Download and install Audacity

Create a text file somewhere you can find it and paste the following string into it: (300 second intervals, ie. 5 minutes, 10 minutes would be 600 intervals, etc...)

0       300  
300     600  
600     900  
900     1200  
1200    1500  
1500    1800  
1800    2100  
2100    2400  
2400    2700  
2700    3000  
3000    3300  
3300    3600  
3600    3900  
3900    4200  
4200    4500  
4500    4800  
4800    5100  
5100    5400  
5400    5700  
5700    6000  
6000    6300  
6300    6600  
6600    6900  
6900    7200  
7200    7500  
7500    7800  
7800    8100  
8100    8400  
8400    8700  
8700    9000  
9000    9300  
9300    9600  
9600    9900  
9900    10200  
10200   10500  
10500   10800  
10800   11100  
11100   11400  
11400   11700  
11700   12000  
12000   12300  
12300   12600  
12600   12900  
12900   13200  
13200   13500  
13500   13800  
13800   14100  
14100   14400  
14400   14700  
14700   15000  

Just make sure that the numbers of intervals is greater than the total length of your audio files, I created this one which runs for over three hours, plenty long for my needs, append more to it to suit your needs.

Import the audio file into Audacity and make whatever balancing and whatever other edits you want to, then click on file>labels>import labels

Select your text file, then select the label track and the audio track at the same time and click on file>Export Multiple.

Change the filetype you want to export to and adjust the settings, then select the destination folder.

I always change the numbering pattern to Numbering After Filename Prefix and type the filename I want in the box and the program will add the numbers, hit Export and viola!