Splitting a Surround Sound Audio File in Ubuntu


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

  TRACK 01 AUDIO
    TITLE "Alice"
    PERFORMER "Bob"
    INDEX 01 00:00:00
  TRACK 02 AUDIO
    TITLE "Carol"
    PERFORMER "Bob"
    INDEX 01 04:38:14
  TRACK 03 AUDIO
    TITLE "Dolly"
    PERFORMER "Bob"
    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 cueconvert.

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:".

Limitations

  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.

CHAPTER01=00:00:00.000
CHAPTER01NAME=Chapter 01
CHAPTER02=00:05:06.03
CHAPTER02NAME=Chapter 02
CHAPTER03=00:10:12.000
...

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.

Limitations

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.

TODO

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.


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

What links here from around this blog?

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">