20080822

oneliner

Bash oneliner to convert all those pesky MP3's in a directory to a proper open format...
        for f in *.mp3; do 
            mpg321 "$f" -w - | oggenc -o "${f%.*}.ogg" -; 
        done;
Notice the subtle use of Bash pattern matching and manipulation...

yeah yeah yeah, come on guys, it's not about lossy and/or non-lossy conversion, it's about the funky pattern matching abilities in Bash. Do the words 'dirname' and 'basename' come to mind perhaps??? And how cool it is that you don't need them in a Bash script? And how much faster that is if you need to do a lot of files??? :-)

9 comments:

Sebastian said...

I count three lines, not one :P

leinir said...

Mmm... yummy quality degradation ;)

Dareus said...

what about tags?
That's the main issue that keeps away from switching format.

Marcel said...

A stupid thing to do. Quality loss hooray!

Paul Gideon Dann said...

@quality degradation => There are some situations in which the pain of using MP3 is worse than the pain of quality degradation. Some people have lower pain-tolerance-thresholds than others :)

Pieter Steyn said...

Don't use ls.

You can simply do

for f in *.mp3;...

Reason behind this is redundancy, and yours won't work on files with spaces in the name...

close2 said...

I find the ${f/%.mp3/.ogg} syntax easier. You should also use "" around the old and new names.

Another problem, which could arise: filenames which start with -

Ralesk said...

http://jensrex.net/bin/heehee.ogg

(The Transcode Song)

Awa said...

Boy do i need to see this kind of bad blogs on dot.kde Planet Developer. make a filter