#!/bin/bash # A Shell Script To Convert All .flac Files To .MP3 Format # Note: I found this script somewhere on usenet and I've modified it for my needs METAFLAC=/usr/bin/metaflac FLAC=/usr/bin/flac ID3=/usr/bin/id3 LAME=/usr/bin/lame FIND=/usr/bin/find t=$(${FIND} . -type f -iname "*.flac") if [ "$t" == "" ] then echo "There are no *.flac file in $(pwd) directory" exit 1 fi for f in *.flac do OUTF=$(echo "$f" | sed s/\.flac$/.mp3/g) ARTIST=$(${METAFLAC} "$f" --show-tag=ARTIST | sed s/.*=//g) TITLE=$(${METAFLAC} "$f" --show-tag=TITLE | sed s/.*=//g) ALBUM=$(${METAFLAC} "$f" --show-tag=ALBUM | sed s/.*=//g) GENRE=$(${METAFLAC} "$f" --show-tag=GENRE | sed s/.*=//g) TRACKNUMBER=$(${METAFLAC} "$f" --show-tag=TRACKNUMBER | sed s/.*=//g) DATE=$(${METAFLAC} "$f" --show-tag=DATE | sed s/.*=//g) $FLAC -c -d "$f" | $LAME -m j -q 0 --vbr-new -V 0 -s 44.1 - "$OUTF" $ID3 -t "$TITLE" -T "${TRACKNUMBER:-0}" -a "$ARTIST" -A "$ALBUM" -y "$DATE" -g "${GENRE:-12}" "$OUTF" done
Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 9 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Transcoding from one lossy format to another isn’t a good idea.
FLAC is not lossy it is in fact lossless. I don’t see any reason to convert a lossless format to a lossy format?
Most car mp3-players are supporting only mp3.
Hi guys,
I want to write a shell script based in some of the code posted here. I just want to ask you a few things…
I want to normalize my music collection, which is about 20 GB by now. Some files are encoded as mp3 vbr 320 kbps. I want to go OSS so, do you think it’s a good idea to convert those big mp3 bitrate files to quality, say 4 or 5, ogg files??
So, in order to achieve this, I need to read various directory levels with files encoded at different bitrates, which I only want to encode if they’re higher or equal than 160 kbps.
I have read a large number of articles and it seems that the only way to encode to ogg is decoding to wav first. So in summary, I need to check bitrate, stream out (I’m guessing here) the mp3 file, somewhere in the middle get the ID3 tags, pipe it to ogg vorbis function that encodes it. Right?
I’m hoping you guys can help me by maybe pointing at some guide where I can understand how to get the properties needed, stream out, encode in ogg format. Thanks in advance :D
Cool Script – Thanks
An incredibly badly written and inefficient script.
First, the hardcoding of utility locations will not work on many systems.
Instead, this section would have been better used to check for the existence of the necessary commands — no matter where they are located. (On my system, for example, lame is in /usr/local/bin)
That is followed by an unnecessary find and test block.
Then for each file, there is an unnecessary call to sed when shell parameter expansion was called for.
That is followed by six calls each to metaflac and sed when one would have done.
Thanks for sharing your wisdom :)
Both scripts are really nice… But could you explain me what sed does in those scripts.
sed s/.*=//g
sed ‘s/=\(.*\)/=”\1″/’
It seems that it assigns variables – but how? I know sed a bit – but this writing doesn’t tell me a thing.
Kind regards,
Lukasz
The output of the metaflac –show-tag command is apparently something like:
ARTIST=PeterGabriel
The first sed command in the fist script removed the “ARTIST=” portion, leaving “PeterGabriel” as the result and assigning that to a shell variable named ARTIST. (Without loss of generality there)
The 2nd sed is craftier. It encloses the value (PeterGabriel) in this case, in quotes and uses eval to do the assignment. Hence, the string to be evaled os morphed from ARTIST=PeterGabriel to ARTIST=”PeterGabriel”.