Advertisement
PrimePastes

MP3 To WAV File .sh File

Apr 21st, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/bin/bash
  2. set -e # exit script if control-c is used
  3. USAGE="Usage: convert_music.sh source_dir destination_dir"
  4. # --- Options processing -------------------------------------------
  5. if [ $# == 0 ] ; then
  6. echo $USAGE
  7. exit 1;
  8. fi
  9. # Convert relative path to absolute. Also remove trailing slash
  10. SOURCE_DIR="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
  11. SOURCE_DIR=$(dirname "$SOURCE_DIR/temp") # this fixes . and ./
  12. DESTINATION_DIR="$(cd "$(dirname "$2")"; pwd)/$(basename "$2")"
  13. DESTINATION_DIR=$(dirname "$DESTINATION_DIR/temp") # this fixes . and ./
  14. find "$SOURCE_DIR" \( -iname '*.mp3' -or -iname '*.m4a' \) -type f -print | while read -r FILE
  15. do
  16. ORIG_DIR=$(dirname "$FILE")
  17. # Get basename and remove extension
  18. BASE=$(basename "$FILE") # get filename
  19. BASE=${BASE%.*} # remove extension from filename
  20. NEW_DIR=${ORIG_DIR/$SOURCE_DIR/$DESTINATION_DIR}
  21. mkdir -p "$NEW_DIR"
  22. NEW_FILE="$NEW_DIR/$BASE.wav"
  23. if [ ! -f "$NEW_FILE" ]; then
  24. echo "Converting $FILE to $NEW_FILE"
  25. # </dev/null added so ffmpeg doesn't read input
  26. ffmpeg -hide_banner -i "$FILE" "$NEW_FILE" </dev/null
  27.  
  28. # Use the following line on Synology NAS. Comment out line above.
  29. #ffmpeg -hide_banner -i "$FILE" -c:a libfaac -b:a 320k "$NEW_FILE" </dev/null
  30. fi
  31. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement