Skip to content

Instantly share code, notes, and snippets.

@oxtoacart
Created December 27, 2018 03:57
Show Gist options
  • Save oxtoacart/39e1b3dfd319abeafa31aa180fe10915 to your computer and use it in GitHub Desktop.
Save oxtoacart/39e1b3dfd319abeafa31aa180fe10915 to your computer and use it in GitHub Desktop.
Script for applying advanced crossfeed using Redline Monitor
#!/bin/bash
# Set up parameters
in=`realpath "${1}"`
echo $in
indir="${in%/*}"
infile="${in##*/}"
outdir="${indir}_headphone"
mkdir -p "$outdir"
tmpin="/tmp/in_${infile}"
tmpout="/tmp/out_${infile}"
tmpcover="/tmp/cover_${infile}"
out="${outdir}/${infile}"
# Get the original bit depth for later
original_bit_depth=`file -b "${in}" | cut -d " " -f 5`
if [ "${original_bit_depth}" == "16" ]; then
sample_fmt="s16"
else
sample_fmt="s32"
fi
function remove_temp_files() {
rm "${tmpin}"
rm "${tmpout}"
rm "${tmpcover}"
}
function die() {
echo $*
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && exit 1
remove_temp_files
}
# Note - I'm using a bunch of temp files because I couldn't get streaming processing at high bit depths to work well with mrswatson64
# Reduce level to leave processing headroom for mrwatson
ffmpeg -y -i "${in}" -filter:a "volume=-3dB" -sample_fmt s32 "${tmpin}" || die "unable to reduce input level"
# Apply advanced crossfeed
mrswatson64 --bit-depth 24 -p /Library/Audio/Plug-Ins/VST/Redline\ Monitor.vst --parameter 2,0.333 --input "${tmpin}" --output "${tmpout}" || die "unable to apply crossfeed"
# Normalize to 0dB peak to reduce the amount of amplification needed at playback
vol=`ffmpeg -i "${tmpout}" -af "volumedetect" -vn -sn -dn -f null /dev/null 2>&1 | grep "max_volume" | cut -d ' ' -f 5 | sed 's/\-//'` || die "unable to determine max volume"
# Note, I'm using the highest compression level to save space, but this slows down encoding
ffmpeg -y -i "${tmpout}" -filter:a "volume=+${vol}dB" -sample_fmt "${sample_fmt}" "${out}" || die "unable to encode final output"
# Copy flac metadata
metaflac --no-utf8-convert --export-tags-to=- "${in}" | metaflac --import-tags-from=- "${out}" || die "unable to copy flac metadata"
metaflac --export-picture-to="${tmpcover}" "${in}" && metaflac --import-picture-from="${tmpcover}" "${out}"
remove_temp_files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment