====== Ubuntu - Sound - Bitrate - Change Bitrate ====== ===== Convert MP3 files in all sub-directories to a different bitrate ===== find . -type f -name "*.mp3" -print0 | while IFS= read -r -d '' file; do echo "$file"; lame -b 192 "$file" "${file%.*}".192.mp3; done **NOTE:** The bitrate is set to 192 kbps. ---- ===== Convert MP3 files in all sub-directories to a different bitrate, but only if they have bitrates above a specific value ===== ==== Using only built in Bash functions ==== find . -type f -name "*.mp3" -print0 | while IFS= read -r -d '' file; do echo "$file"; [[ $(file "$file" | sed 's/.*, \(.*\)kbps.*/\1/' | tr -d " ") -gt 192 ]] && lame -b 192 "$file" "${file%.*}".192.mp3 && mv "${file%.*}".192.mp3 "$file"; done **WARNING:** This uses the **file** command to determine the bitrate. * Unfortunately, sometimes the **file** command does not return the bitrate and returns something like **Audio file with ID3 version 2.3.0**. * For these files, the **$(file "$file" | sed 's/.*, \(.*\)kbps.*/\1/' | tr -d " ")** part will not work. * The bitrate is set to 192 kbps for any file that has a bitrate above 192 kbps. ---- ==== Using mp3info ==== find . -type f -name "*.mp3" -print0 | while IFS= read -r -d '' file; do echo "$file"; [[ $(mp3info -r m -p "%r" "$file") -gt 192 ]] && lame -b 192 "$file" "${file%.*}".192.mp3 && mv "${file%.*}".192.mp3 "$file"; done **NOTE:** This uses the **mp3info** command to determine the bitrate. * This **mp3info** command needs to be installed with **sudo apt install mp3info**.