Skip to content

Instantly share code, notes, and snippets.

@deviationist
Last active November 20, 2021 02:23
Show Gist options
  • Select an option

  • Save deviationist/d4f1f346adcce23000d83735eb540fef to your computer and use it in GitHub Desktop.

Select an option

Save deviationist/d4f1f346adcce23000d83735eb540fef to your computer and use it in GitHub Desktop.
FFMPEG reduce audio sample rate (AIFF, WAV)
#!/bin/bash
toConvertFolder="to-convert/"
convertedFolder="converted/"
maxKhz=48000
mkdir -p $convertedFolder
formats=( "aiff" "wav" )
for i in "${formats[@]}"
do
# Reduce sample rate
find $toConvertFolder -type f -name "*.${i}" | while read line; do
tempFilename="${line/%.${i}/-temporary.${i}}"
mv "${line}" "${tempFilename}"
ffmpeg -y -nostdin -i "${tempFilename}" -ar $maxKhz -write_id3v2 1 -c:v copy "${line}" && rm "${tempFilename}" && mv "${line}" "${convertedFolder}"
mv "${tempFilename}" "${line}" 2>/dev/null
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment