Splitting a Surround Sound Audio File in Ubuntu

by @edent | # # # # # | Read ~430 times.

See this update for a better way to do this.

Being mostly notes to myself and following on from my post on Quadrophonic files.

I have:

I want:

  • The single large file to be split into individual chapters with one file per chapter.
  • Each file to be multitrack (that is, to stay in surround sound)

It turns out, that there is no simple way to do this. There are tools to split stereo wav files by their cue sheet, but nothing for 5.1 files.

So, here's how I did it. This process uses mkvtools and avconv.

The Easy (But Fairly Manual) Way!

I can't find an automated way to do this from a cuesheet - so here's what you need to do.

A typical cue looks like

    TITLE "Alice"
    INDEX 01 00:00:00
    TITLE "Carol"
    INDEX 01 04:38:14
    TITLE "Dolly"
    INDEX 01 08:39:09

Track 2 starts at 4 minutes, 38.14 seconds into the file. It finishes at (8m 39.09s - 4m 38.14s) = 4m 0.95s.

avconv -f dts -i original.wav -ss 00:04:38.014 -t 00:04:0.95 -acodec copy track2.wav

That is, avconv forced to use DTS, starting at 4.38.014 and finishing after 4m .95s, copying the codec into a new file.

Calculating Offsets

It's hard to manually calculate all the timings. One quick(ish) way to get them is by using <a href="http://manpages.ubuntu.com/manpages/quantal/man1/cueconvert.1.html">cueconvert</a>.

cueconvert -i cue -o toc cue.cue cue.toc

If you open the newly created .toc file, you should see something like:

FILE "track1.wav" 0 04:38:14
FILE "track2.wav" 04:38:14 04:00:70
FILE "track3" 08:39:09 04:38:57

You can then use those timings as your -ss and -t values - remember to add the extra leading "00:".


  1. The files aren't tagged / named correctly.
  2. It's a pain to calculate the timings correctly.

The Hard (But Somewhat Automated) Way!

Convert the .WAV to .MKV

avconv -i whatever.wav -acodec copy output.mkv

In some cases, avconv will think your 5.1 recording is stereo. Fix it by forcing the codec it detects.

avconv -f dts -i whatever.wav -acodec copy output.mkv

Create a Chapters File

MKVmerge require a specific format of chapter file which is different from a normal .cue file. Creating this will be a manual process.

CHAPTER01NAME=Chapter 01
CHAPTER02NAME=Chapter 02

Save that as chapters.txt.

Add The Chapters to the .MKV

A single command for this one:

mkvmerge output.mkv --chapters chapters.txt -o withchapters.mkv

Split The MKV

There are a couple of ways to do this, I use:

mkvmerge withchapters.mkv --split chapters:all -o track.mkv

You'll now have track-001.mkv, track-002.mkv etc.


At this point, we have two moderately annoying problems.

  1. The files aren't tagged / named correctly.
  2. The DTS audio can't be extracted properly!

That last one is rather a showstopper! For some reason, the .MKV files play back their audio properly. When trying to extract or convert it, all sorts of stream errors occur.


Either write a patch for avconv to get it to split by .cue - or write a small Python script to do everything automagically!

Any suggestions for a better way to do this? Stick them in the comments box.

Leave a Reply

Your email address will not be published. Required fields are marked *