Skip to content

Instantly share code, notes, and snippets.

@corrooli
Created March 15, 2025 02:21
Show Gist options
  • Save corrooli/c0e3a57f71d73ee3ed980742bf751106 to your computer and use it in GitHub Desktop.
Save corrooli/c0e3a57f71d73ee3ed980742bf751106 to your computer and use it in GitHub Desktop.
Synology Script - Convert .WAV and .AIFF to .MP3
#!/bin/bash
# Script for Synology Task Planner!
# I use it to automatically convert my band practice recordings to .MP3 so we can listen to them instantly after rehearsal with our phones.
# For ARMv7 CPUs: Download https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz and unpack it, place ffpmeg executable to any share you like.
# For Intel CPUs: Don't have the link ready, but Google is your friend ;)
# Be sure to set execution/directory listing permission for the user that runs this script!
TARGET_DIR="/volume1/TARGET_DRIVE" # Adjust here! Replace TARGET_DRIVE with the drive name
LOG_FILE="/volume1/TARGET_DRIVE/wav2mp3.log" # Adjust here! Replace TARGET_DRIVE with the drive name
FFMPEG_CMD="/volume1/TARGET_DRIVE/ffmpeg" # Adjust here! Replace TARGET_DRIVE with the drive name and point it to your ffmpeg executable
find "$TARGET_DIR" \
-type f \
\( -iname "*.wav" -o -iname "*.aif" -o -iname "*.aiff" \) \
-not -path "*@eaDir*" \
-not -path "*@tmp*" \
-not -path "*#recycle*" \
-print0 | while IFS= read -r -d $'\0' file; do
base_file="${file%.*}"
mp3_file="${base_file}.mp3"
if [ ! -f "$mp3_file" ]; then
echo "$(date) - Converting: $file" >> "$LOG_FILE"
"$FFMPEG_CMD" -hide_banner -loglevel error -nostdin -i "$file" \
-acodec libmp3lame -ab 128k "$mp3_file" 2>> "$LOG_FILE"
if [ $? -eq 0 ]; then
echo "Success: $file → $mp3_file" >> "$LOG_FILE"
chmod 644 "$mp3_file"
else
echo "FAILED: $file" >> "$LOG_FILE"
[ -f "$mp3_file" ] && rm "$mp3_file"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment