Created
December 18, 2024 07:29
-
-
Save aswild/7d4b895c27705fcb9cf47c967256d8d3 to your computer and use it in GitHub Desktop.
Script to split Mackie DLZ Creator multi track recording polywave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script converts multi-track "polywave" recording files generated by the Mackie DLZ Creator | |
# to A) combines the 2GB split recording files and B) split the multi-track 14-channel WAV file | |
# into 9 separate WAV files: inputs 1-4 (mono) and stereo 5/6, 7/8, 9/10, 11/12, and Stereo LR. | |
# | |
# It does everything in a single pass and joining the split recording parts is done with the | |
# concat filter rather than the concat demuxer (or protocol) so that there's no need for temporary | |
# files and there's less issues with quoting filenames. This script should work on anything that | |
# runs bash and has 'ffmpeg' somewhere in PATH. Tested on Linux but it should work in cygwin/msys | |
# for Windows or on a Mac. | |
set -euo pipefail | |
usage() { | |
cat <<EOF | |
Usage: $0 OUTPUT_PREFIX INPUT_FILE [INPUT_FILE...]" | |
This script will use ffmpeg to split a multi-track recording from the Mackie DLZ Creator | |
into individual wav files for each channel. It can also concatenate split recording files | |
since the DLZ creates a new file every 2G. | |
EOF | |
exit 1 | |
} | |
# not enough args | |
if (( $# < 2 )); then | |
usage | |
fi | |
prefix="$1" | |
shift | |
inputs=("$@") | |
# output_prefix shouldn't be a file that exists. If all arguments are files that exist | |
# then the user probably actually forgot the prefix. | |
if [[ -f "$prefix" ]]; then | |
usage | |
fi | |
for input in "${inputs[@]}"; do | |
if [[ ! -f "$input" ]]; then | |
echo "Error: input file '$input' doesn't exist" | |
exit 1 | |
fi | |
done | |
# build the concat filtergraph | |
concat_filter="" | |
i=0 | |
for input in "${inputs[@]}"; do | |
concat_filter+="[${i}:0]" | |
i=$((i + 1)) | |
done | |
concat_filter+="concat=n=${#inputs[@]}:v=0:a=1[merged]; " | |
# split filter is used to duplicate merged several times, since it doesn't work to use re-use the | |
# same output label multiple times for different inputs of subsequent filterchains | |
split_filter="[merged]asplit=9[m0][m1][m2][m3][m4][m5][m6][m7][m8]; " | |
# ffmpeg filter_complex string to use the pan filter to split a single multi-track input stream | |
# (which we call [merged_input] as the result of concatenation of the original inputs) into 9 | |
# output streams: 4 mono (inputs 1, 2, 3, and 4) and 5 stereo (inputs 5/6, 7/8, 9/10, 11/12, | |
# and the stereo master bus). cN channel numbers in the pan filter are 0 indexed, so numbers | |
# below are one smaller than the actual DLZ input numbers | |
pan_filter='' | |
pan_filter+='[m0]pan=mono|c0=c0[out0]; ' | |
pan_filter+='[m1]pan=mono|c0=c1[out1]; ' | |
pan_filter+='[m2]pan=mono|c0=c2[out2]; ' | |
pan_filter+='[m3]pan=mono|c0=c3[out3]; ' | |
pan_filter+='[m4]pan=stereo|c0=c4|c1=c5[out4]; ' | |
pan_filter+='[m5]pan=stereo|c0=c6|c1=c7[out5]; ' | |
pan_filter+='[m6]pan=stereo|c0=c8|c1=c9[out6]; ' | |
pan_filter+='[m7]pan=stereo|c0=c10|c1=c11[out7]; ' | |
pan_filter+='[m8]pan=stereo|c0=c12|c1=c13[out8]; ' | |
# build the ffmpeg command | |
cmd=(ffmpeg) | |
for input in "${inputs[@]}"; do | |
cmd+=(-i "$input") | |
done | |
# add the full filter to the ffmpeg command | |
cmd+=( -filter_complex "${concat_filter}${split_filter}${pan_filter}" ) | |
# now for the output files. The DLZ records in 24 bit wav and the input files are pcm_s24le, but | |
# that gets forgotten among our filtergraph, so it has to be re-specified for each output. | |
# Alternatively, codec and ext could be changed to transcode to FLAC or another codec in one pass | |
# without needing to waste disk space on intermediate wav files. (TODO: this could be a | |
# command-line option) | |
codec='pcm_s24le' | |
ext='wav' | |
cmd+=( | |
-map "[out0]" -c:a "$codec" "${prefix}_1_ch1.${ext}" | |
-map "[out1]" -c:a "$codec" "${prefix}_2_ch2.${ext}" | |
-map "[out2]" -c:a "$codec" "${prefix}_3_ch3.${ext}" | |
-map "[out3]" -c:a "$codec" "${prefix}_4_ch4.${ext}" | |
-map "[out4]" -c:a "$codec" "${prefix}_5_ch5-6.${ext}" | |
-map "[out5]" -c:a "$codec" "${prefix}_6_ch7-8.${ext}" | |
-map "[out6]" -c:a "$codec" "${prefix}_7_ch9-10.${ext}" | |
-map "[out7]" -c:a "$codec" "${prefix}_8_ch11-12.${ext}" | |
-map "[out8]" -c:a "$codec" "${prefix}_9_main-LR.${ext}" | |
) | |
echo "+ ${cmd[*]}" | |
"${cmd[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment