Skip to content

Instantly share code, notes, and snippets.

@willsthompson
Last active January 3, 2021 20:25
Show Gist options
  • Save willsthompson/c6686cf129babb95afd8bc2ce99549b9 to your computer and use it in GitHub Desktop.
Save willsthompson/c6686cf129babb95afd8bc2ce99549b9 to your computer and use it in GitHub Desktop.
Scripts for processing multichannel audio for playback on Apple TV

Multichannel audio-processing scripts for Apple TV

Prerequisites

Apple TV

  1. Infuse can play back FLAC and ALAC-encoded multichannel audio wrapped in an MKV container.
  2. VLC might play multichannel FLAC without a container. But that stopped working for me when I changed my audio setup to use ARC, so YMMV.

Computer

  1. ffmpeg
  2. mkvtoolnix
  3. cuetools/shntool

Steps

  1. If encoded as a single DTS WAV, split into multiple track WAVs from the CUE:

    for i in *.cue; do cue="$i"; wav="`basename "$i" .cue`.wav"; shnsplit -d mkv_audio -f "$cue" -t "%n %t" "$wav"; done;
    

    Note: This will output files to a mkv_audio subdirectory, and if the directory doesn't exist first shnsplit will throw a cryptic error.

  2. Convert WAV tracks to either FLAC or ALAC:

    • WAVs to ALAC

      for i in *.wav; do ffmpeg -i "$i" -acodec alac "`basename "$i" .wav`.m4a"; done;
      
    • WAVs to FLAC

      for i in *.wav; do ffmpeg -i "$i" "`basename "$i" .wav`.flac"; done;
      
  3. If original tracks are in either FLAC or ALAC, and you want to transcode to the other:

    • FLAC to ALAC

      for i in *.flac; do ffmpeg -i "$i" -acodec alac "`basename "$i" .flac`.m4a"; done;
      
    • ALAC to FLAC

      for i in *.m4a; do ffmpeg -acodec alac -i "$i" "`basename "$i" .m4a`.flac"; done;
      
  4. Wrap audio files in MKV container:

    • ALAC to MKV:

      for i in *.m4a; do outfile="`basename "$i" .m4a`.mkv"; mkvmerge "$i" -o "$outfile" ; done;
      
    • FLAC to MKV:

      for i in *.flac; do outfile="`basename "$i" .flac`.mkv"; mkvmerge "$i" -o "$outfile" ; done;
      
  5. Remuxing MKVs:

    • FLAC MKV to ALAC MKV:

      for i in *.mkv; do ffmpeg -i "$i" -acodec alac "./output/$i"; done;
      
    • ALAC MKV to FLAC MKV:

      for i in *.mkv; do ffmpeg -i "$i" -c:a flac "./output/$i"; done;
      

Quadraphonic

  1. Convert 5.1-encoded audio with empty Center and LFE channels to true 4.0

    for i in *.flac; do ffmpeg -i "$i" -filter_complex "channelmap=0|1|4|5:channel_layout=quad" "./quad_mix/$i"; done;
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment