castogg.sh – make podcasts smaller

As you might know, podcasts are like radio shows recorded and distributed digitally (read: mp3 and RSS). Since pretty much anyone can record a show and distribute it over the Internet – everyone and their brother do that.

The file sizes of some podcasts are huge. There are shows that last for more than an hour and include pieces of music and stereo special effects. I’ve seen this eat up more than 50 MBytes each.

Since I only have a 128 MByte memory card (and about 20 of those MBytes are eaten by software intallations and other data), I was looking at ways to minimize the file sizes of the podcasts that I wanted to listen to.

As the first step I found a general-purpose mp3 to Ogg converter (mp32ogg). I had a directory with about 15 podcasts from different sources that I was doing my tests at. The total disk space used by all mp3 podcasts was about 380 MBytes. After I converted them to Ogg Vorbis with mp32ogg.pl same shows were occupying 350 MBytes. An improvement, but not significant.

After some poking around and looking here and there I realized what was the main problem. Most of these mp3s were of a far better quality (read: bitrate) than I needed. Some were even 256 kbit/s – sound level that is impossible to enjoy using my phone’s headphones.

I tried a few different bitrates and stopped at 64 kbit/s. This one is both good enough on the quality side (considering the factors) as well as small enough for my phone. I converted my test samples to 64 kbit/s Ogg Vorbis files and now all those files needed only a 250 MBytes of disk space. Not that’s a 130 MBytes improvement. Good enough for me.

All that I needed to do was to automate the procedure. And so I did with this really simple shell script.

#!/bin/bash

# What bitrate to use for the resulting Ogg files
BITRATE=64

# Process all files with .mp3 extension
for FILE in *.mp3
do
    # Give some progress feedback
    echo Processing "$FILE"
    # Convert mp3s to WAVs and write to STDOUT
    mpg321 -w - "$FILE" | \
    # Convert WAVs coming from STDIN to Ogg Vorbis
    oggenc - -b $BITRATE -o `basename $FILE .mp3`.ogg
done

One thought on “castogg.sh – make podcasts smaller”

Leave a Comment