Skip to content

Instantly share code, notes, and snippets.

@kezzico
Last active May 20, 2021 19:49
Show Gist options
  • Save kezzico/3ecc52c48e7caac40ac0635a84794119 to your computer and use it in GitHub Desktop.
Save kezzico/3ecc52c48e7caac40ac0635a84794119 to your computer and use it in GitHub Desktop.
#!/bin/bash
# convert any audio file to Animoog format
# usage: script.sh <source.m4a> <sample start> <sample length>
src="$1"
samplerate=44100
start=$2
duration=$3
#targetduration=0.371519
# multiply sample rate by ratio of duration / target
# to bring ouput length to 0.371519
outrate=`python -c "print($samplerate*$duration/0.371519)"`
if [[ -z "$4" ]]; then
outfile="${src%.*}.mono.wav"
else
outfile="$4"
fi
echo "$outrate"
echo "$outfile"
echo "------------------------"
ffmpeg -ss $start -t $duration -i "$src" \
-filter_complex "[0:a]asetrate=$outrate,aresample=44100" \
-ac 1 -ab 705k "$outfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment