Convert Surround Sound WAV albums to individual opus files

by @edent | # # # # #

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 "file-%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

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.