User Tools

Site Tools


ubuntu:sound:bitrate:change_bitrate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ubuntu:sound:bitrate:change_bitrate [2022/09/19 11:06] – created peterubuntu:sound:bitrate:change_bitrate [2022/09/19 11:11] (current) – [Using only built in Bash functions] peter
Line 1: Line 1:
 ====== Ubuntu - Sound - Bitrate - Change Bitrate ====== ====== Ubuntu - Sound - Bitrate - Change Bitrate ======
 +
 +===== Convert MP3 files in all sub-directories to a different bitrate =====
 +
 +<code bash>
 +find . -type f -name "*.mp3" -print0 | while IFS= read -r -d '' file; do echo "$file"; lame -b 192 "$file" "${file%.*}".192.mp3; done
 +</code>
 +
 +<WRAP info>
 +**NOTE:** The bitrate is set to 192 kbps.
 +</WRAP>
 +
 +----
 +
 +===== 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 ====
 +
 +<code bash>
 +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
 +</code>
 +
 +<WRAP warning>
 +**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.
 +</WRAP>
 +
 +----
 +
 +==== Using mp3info ====
 +
 +<code bash>
 +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
 +</code>
 +
 +<WRAP info>
 +**NOTE:** This uses the **mp3info** command to determine the bitrate.
 +
 +    * This **mp3info** command needs to be installed with **sudo apt install mp3info**.
 +
 +</WRAP>
  
ubuntu/sound/bitrate/change_bitrate.1663585613.txt.gz · Last modified: 2022/09/19 11:06 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki