#!/bin/bash # ==================================================================== # Simple script to downmix a 5.0/5.1/5.1 (side) flac file to stereo, # and optionally resample to cd quality # # Dependencies: ffmpeg (built with libsoxr and flac) # ==================================================================== read -p 'Gain db [-6]: ' GAIN if [[ -z "$GAIN" ]]; then GAIN=-6 fi read -p 'Resample to cd quality? [No]: ' RES mkdir -p down for file in *.flac; do if [[ -z "$RES" ]]; then ffmpeg -i "$file" -af "volume=volume=${GAIN}dB:precision=double,pan=stereo| FL = FL + 0.707*FC + 0.707*BL + 0.707*SL + 0.5*LFE | FR = FR + 0.707*FC + 0.707*BR + 0.707*SR + 0.5*LFE" "down/$file" else ffmpeg -i "$file" -af "volume=volume=${GAIN}dB:precision=double,pan=stereo| FL = FL + 0.707*FC + 0.707*BL + 0.707*SL + 0.5*LFE | FR = FR + 0.707*FC + 0.707*BR + 0.707*SR + 0.5*LFE,aresample=resampler=soxr:precision=33:cutoff=0.96:dither_method=triangular:out_sample_rate=44100:out_sample_fmt=s16" "down/${file/%flac/wav}" fi done