Convert Surround Sound WAV albums to individual opus files


As ever, notes to myself. This is a method to take a .wav and .cue and transform it into individual files. In this case, .opus.

Transform to .flac

FLAC is a good intermediary file format, especially for surround sound files.

avconv -i file.wav out.flac

Transform to .opus

An optional step if you want smaller files. Maximum quality for 6 channel audio.

opusenc --bitrate 4096 out.flac out.opus

Create an .mkv

Add to an MKV with all the chapter information.

mkvmerge -o test.mkv --chapters file.cue out.opus

Split to individual files

Individual MKVs

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

Extract the Audio

One at a time:

mkvextract tracks "track-001.mkv" 0:"individual.opus"

All-In-One bash script

#!/bin/bash
json=$(ffprobe -i "file.mkv" -print_format json -show_chapters -loglevel error)
count=$(echo $json | jq ".chapters | length" )

mkvmerge test.mkv -D -S --split chapters:all -o "%02d.mkv"

COUNTER=1
while [ $COUNTER -le $count ]; do

  printf -v zerotrack "%02d" $COUNTER

  json=$(ffprobe -i "$zerotrack.mkv" -print_format json -show_chapters -loglevel error)
  title=$(echo $json | jq ".chapters[0].tags.title" -r)
  filename="[$zerotrack] $title"

  mkvextract tracks "$zerotrack.mkv" 0:"$filename.opus"
  let COUNTER=COUNTER+1
done

Share this post on…

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

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="">