#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/audio-norm # # thanks to Reco at gmane.linux.debian.user mm-alter-volume () { local v=$1 local f=$2 local name=${f:r} local ext=${f:e} local out=${name}-${v}.${ext} ffmpeg -y -i $f -filter:a "volume=$v" $out && mv -f $out $f } mm-alter-volume-small () { local inc_dec=$1 local f=$2 local fac=0.1 if [[ $inc_dec == 'inc' ]]; then mm-alter-volume $(( 1 + $fac )) $f elif [[ $inc_dec == 'dec' ]]; then mm-alter-volume $(( 1 - $fac )) $f fi } mm-alter-volume-1 () { local f=$1 mm-alter-volume-small 'inc' $f } mm-alter-volume--1 () { local f=$1 mm-alter-volume-small 'dec' $f } alias viv=mm-alter-volume-1 alias vdv=mm-alter-volume--1 mm-no-middle-audio () { local f=$1 local name=${f:r} local ext=${f:e} local new_name=${name}-no-middle-audio.${ext} local min=0.015625 ffmpeg -y \ -i $f \ -af stereotools=mlev=$min $new_name } # $ pip install ffmpeg-normalize mp3-norm () { local mp3=$1 local dB=$2 ffmpeg-normalize -f \ -c:a libmp3lame \ -t $dB \ -ext mp3 $mp3 } mm-audio () { local files=($@) for f in $files; do if [ -f $f ]; then echo -n "$f:" ffprobe -print_format json 2>&1 $f | grep -i audio mediainfo --Inform="Audio;%Channel(s)%: %ChannelLayout%" $f echo else no-file-msg $f fi done } # ffmpeg default downmix: # # FL-dm = FL + 0.707*FC + 0.707*BL # FR-dm = FR + 0.707*FC + 0.707*BR # options: # # -lfe_mix_level dB +/-32 LFE thunder/explosions # -clev (center_mix_level) dB +/-32 C dialog # -slev (surround_mix_level) dB +/-32 Ls & Rs gunfire mm-downmix () { local f=$1 local name=${f:r} local ext=${f:e} local out=${name}-dm.${ext} ffmpeg -y \ -i $f \ -map 0:0 \ -map 0:1 \ -c:v copy \ -strict -2 \ -c:a libopus \ -b:a 128k \ -ac 2 \ -clev 1.414 \ -slev 0.5 $out }