<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>surround sound &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/surround-sound/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Tue, 15 Jul 2025 08:01:16 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>surround sound &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[HOWTO: Split WAV and CUE files on Linux]]></title>
		<link>https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/</link>
					<comments>https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Mon, 04 Feb 2019 20:48:18 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mkv]]></category>
		<category><![CDATA[mkvmerge]]></category>
		<category><![CDATA[surround sound]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=31357</guid>

					<description><![CDATA[Mostly notes to myself, as a follow-up to this older post.  This is a 3-step process.  Add the file to an MKV  Use MKVmerge:  mkvmerge &#34;audio.wav&#34; --chapters &#34;audio.cue&#34; -o &#34;audio.mkv&#34;   You can see that chapter names have been added to the .mkv if you run ffmpeg -i or mkvinfo.  Split the MKV by chapter  This generates one file per chapter:  mkvmerge -D -S &#34;audio.mkv&#34; --split chapters:all -o…]]></description>
										<content:encoded><![CDATA[<p>Mostly notes to myself, as a follow-up to <a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/">this older post</a>.  This is a 3-step process.</p>

<h2 id="add-the-file-to-an-mkv"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#add-the-file-to-an-mkv">Add the file to an MKV</a></h2>

<p>Use <a href="https://mkvtoolnix.download/">MKVmerge</a>:</p>

<pre><code class="language-_">mkvmerge "audio.wav" --chapters "audio.cue" -o "audio.mkv"
</code></pre>

<p>You can see that chapter names have been added to the .mkv if you run <code>ffmpeg -i</code> or <code>mkvinfo</code>.</p>

<h2 id="split-the-mkv-by-chapter"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#split-the-mkv-by-chapter">Split the MKV by chapter</a></h2>

<p>This generates one file per chapter:</p>

<pre><code class="language-_">mkvmerge -D -S "audio.mkv" --split chapters:all -o "split-%02d.mkv"
</code></pre>

<p>The <code>-D</code> switch means no video will be copied. <code>-S</code> means no subtitles.</p>

<h2 id="extract-the-audio"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#extract-the-audio">Extract the audio</a></h2>

<p>This quickly pulls out the audio, raw, without changing anything.</p>

<pre><code class="language-_">mkvextract split-01.mkv tracks "0:output"
</code></pre>

<p>The raw audio is placed in a file called <code>output</code></p>

<p>You can also do this with:</p>

<pre><code class="language-_">ffmpeg -i "split-01.mkv" -acodec copy "whatever.wav"
</code></pre>

<p>Replace <code>.wav</code> with <code>.ac3</code> or <code>.flac</code> or whatever the audio format is.
You can transcode the audio to something else. I recommend <a href="https://opus-codec.org/">Opus</a></p>

<pre><code class="language-_">ffmpeg -i "split-01.mkv" -af aformat=channel_layouts="7.1|5.1|stereo" -b:a 1536k "whatever.opus"
</code></pre>

<p>There is a <a href="https://trac.ffmpeg.org/ticket/5718">bug with the surround sound mapping in ffmpeg</a>.</p>

<h2 id="rename-it"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#rename-it">Rename it</a></h2>

<p>This is bit convoluted. <code>ffprobe</code> can get the chapter name:</p>

<pre><code class="language-_">ffprobe -i "split-01.mkv" -show_chapters -loglevel error
</code></pre>

<p>The use of <code>-loglevel error</code> means you only get the data, rather than the debug cruft.</p>

<p>In order to get the title, we get <code>ffprobe</code> to spit out JSON and then get <code>jq</code> to interpret it:</p>

<pre><code class="language-_">ffprobe -i "split-01.mkv" -print_format json -show_chapters -loglevel error | jq ".chapters[0].tags.title" -r
</code></pre>

<h2 id="all-in-one-script-to-extract-the-audio-and-rename-it"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/#all-in-one-script-to-extract-the-audio-and-rename-it">All in one script to extract the audio <em>and</em> rename it</a></h2>

<pre><code class="language-_">#!/bin/bash
AUDIO="audio.wav"
CUE="audio.cue"
MKV="audio.mkv"

# What's the audio format?
FORMAT=$(ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$AUDIO")

# Create the MKV
mkvmerge "$AUDIO" --chapters "$CUE" -o "$MKV"

# How many chapters are there?
JSON=$(ffprobe -i "$MKV" -print_format json -show_chapters -loglevel error)
COUNT=$(echo $JSON | jq ".chapters | length" )

# Split the MKV into chapters
mkvmerge -D -S "$MKV" --split chapters:all -o "split-%02d.mkv"

# Loop through all the created .mkv files
COUNTER=1
while [ $COUNTER -le $COUNT ]; do

  # Zero pad the counter
  printf -v ZEROTRACK "%02d" $COUNTER

  # Get the chapter name
  JSON=$(ffprobe -i "split-$ZEROTRACK.mkv" -print_format json -show_chapters -loglevel error)
  TITLE=$(echo $JSON | jq ".chapters[0].tags.title" -r)
  FILENAME="[$ZEROTRACK] $TITLE.$FORMAT"

  # Raw Audio
  mkvextract "split-$ZEROTRACK.mkv" tracks "0:$FILENAME"
  # Transcode. Optional
  #ffmpeg -i "split-$ZEROTRACK.mkv" "$FILENAME.opus"

  let COUNTER=COUNTER+1 
done

# Delete the generated MKVs. Optional
#rm *.mkv
</code></pre>

<p>Note, there is <a href="https://gitlab.com/mbunkus/mkvtoolnix/issues/2498">no single command in MKVtools to do this</a></p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=31357&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[Splitting a Surround Sound Audio File in Ubuntu]]></title>
		<link>https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/</link>
					<comments>https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#respond</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Wed, 15 Jul 2015 21:22:25 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[avconv]]></category>
		<category><![CDATA[dts]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[surround sound]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=21171</guid>

					<description><![CDATA[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:       A DTS album stored as a .WAV     A .cue file with chapter markings   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,…]]></description>
										<content:encoded><![CDATA[<p><ins datetime="2019-02-04T20:49:45+00:00"><a href="https://shkspr.mobi/blog/2019/02/howto-split-wav-and-cue-files-on-linux/">See this update for a better way to do this.</a></ins></p>

<p>Being mostly notes to myself and following on from <a href="https://shkspr.mobi/blog/2014/08/dealing-with-quadrophonic-dvd-a-files-in-linux/">my post on Quadrophonic files</a>.</p>

<p>I have:</p>

<ul>
    <li>A <a href="https://web.archive.org/web/20150708071611/https://diatonis.com/surround_sound_music.html">DTS album stored as a .WAV</a></li>
    <li>A .cue file with chapter markings</li>
</ul>

<p>I want:</p>

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

<p>It turns out, that there is no simple way to do this.  There are tools to <a href="https://bytebin.wordpress.com/2009/11/20/split-flac-by-cue-file-in-linux/">split <em>stereo</em> wav files by their cue sheet</a>, but nothing for 5.1 files.</p>

<p>So, here's how I did it.  This process uses <a href="https://www.bunkus.org/videotools/mkvtoolnix/downloads.html">mkvtools</a> and <a href="https://stackoverflow.com/questions/9477115/what-are-the-differences-and-similarities-between-ffmpeg-libav-and-avconv">avconv</a>.</p>

<h2 id="the-easy-but-fairly-manual-way"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#the-easy-but-fairly-manual-way">The Easy (But Fairly Manual) Way!</a></h2>

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

<p>A typical cue looks like</p>

<pre>  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
...
</pre>

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

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

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

<h2 id="calculating-offsets"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#calculating-offsets">Calculating Offsets</a></h2>

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

<pre>cueconvert -i cue -o toc cue.cue cue.toc</pre>

<p>If you open the newly created .toc file, you should see something like:</p>

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

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

<h2 id="limitations"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#limitations">Limitations</a></h2>

<ol>
    <li>The files aren't tagged / named correctly.</li>
    <li>It's a pain to calculate the timings correctly.</li>
</ol>

<h2 id="the-hard-but-somewhat-automated-way"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#the-hard-but-somewhat-automated-way">The Hard (But Somewhat Automated) Way!</a></h2>

<h2 id="convert-the-wav-to-mkv"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#convert-the-wav-to-mkv">Convert the .WAV to .MKV</a></h2>

<pre>avconv -i whatever.wav -acodec copy output.mkv</pre>

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

<pre>avconv -f dts -i whatever.wav -acodec copy output.mkv</pre>

<h2 id="create-a-chapters-file"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#create-a-chapters-file">Create a Chapters File</a></h2>

<p>MKVmerge require a <a href="http://savvyadmin.com/adding-chapters-to-videos-using-mkv-containers/">specific format of chapter file</a> which is different from a normal .cue file.  Creating this will be a manual process.</p>

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

<p>Save that as <code>chapters.txt</code>.</p>

<h2 id="add-the-chapters-to-the-mkv"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#add-the-chapters-to-the-mkv">Add The Chapters to the .MKV</a></h2>

<p>A single command for this one:</p>

<pre>mkvmerge output.mkv --chapters chapters.txt -o withchapters.mkv</pre>

<h2 id="split-the-mkv"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#split-the-mkv">Split The MKV</a></h2>

<p>There are <a href="http://superuser.com/questions/795373/split-mkv-based-on-chapters">a couple of ways to do this</a>, I use:</p>

<pre>mkvmerge withchapters.mkv --split chapters:all -o track.mkv</pre>

<p>You'll now have track-001.mkv, track-002.mkv etc.</p>

<h2 id="limitations"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#limitations">Limitations</a></h2>

<p>At this point, we have two moderately annoying problems.</p>

<ol>
    <li>The files aren't tagged / named correctly.</li>
    <li>The DTS audio can't be extracted properly!</li>
</ol>

<p>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.</p>

<h2 id="todo"><a href="https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/#todo">TODO</a></h2>

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

<p>Any suggestions for a better way to do this? Stick them in the comments box.</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=21171&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2015/07/splitting-a-surround-sound-audio-file-in-ubuntu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
