Bash script: convert FLAC to MP3

Requirements

  • lame (sudo apt-get install lame)
  • flac (sudo apt-get install flac)
  • directory with flac files

Script



#!/bin/bash
flac -d *.flac
find -name "* *.wav" -type f | rename 's/ /_/g'
for i in $( ls -b *.wav ); do
  lame -hV0 $i
  rm $i
done
find -name "*.mp3" -type f | rename 's/_/ /g'


This script will decompress the flac files to wav files, remove any spaces in the file name, it will then convert the wavs to mp3 using lame's highest variable bitrate setting, then finally replace the underscores back to spaces.  If you don't want spaces in your file names, you can remove the last line.

To use the script, create a new file on your system, copy the contents of the script inside, give it executable properties (sudo chmod +x scriptname), then run it in the directory containing the flac files, (./scriptname) where scriptname is the name of your script.

Enjoy!

No comments:

Post a Comment