Downsample

By Hal Canary, 2007-12-12 12:40:06 (link)
#computers-code

I can't tell the difference between a 32KBps and 224KBps mp3 file. Can you?

So I'm down-sampling all my mp3s to fit on my new mp3 player. I should be able to fit around 3 days of music onto my 1GB player this way.

Here's a script to do that---a work in progress

#!/bin/sh

## Compressmp3s - Copyright 2007 Hal Canary
## Dedicated to the Public Domain.

## Arguments: a list of directories to search for mp3s
## This script will use lame to create a 32kbps version
## of those mp3 and save it in a subdirectory of $TARGETDIR

if [ "$#" -lt 1 ] ; then
    echo "Give me an argument!"
    exit 1
fi

TARGETDIR="$HOME/tmp/CompressedAudio"
mkdir -p "$TARGETDIR" || {
    echo "Use a directory you have permissions for.";
    exit 1 ; }

## for FILE in "$@" ; do
find "$@" -name '*.mp3' | while read FILE; do
    IN="$FILE"
    OUT="${TARGETDIR}/$FILE"
    ## Grab the id3 info for later use
    artist=`id3info "$IN" | grep TPE1 | \
        awk -F ': ' '{print $2}'`
    album=`id3info "$IN" | grep TALB | \
        awk -F ': ' '{print $2}'`
    track=`id3info "$IN" | grep TRCK | \
        awk -F ': ' '{print $2}'`
    song=`id3info "$IN" | grep TIT2 | \
        awk -F ': ' '{print $2}'`
    echo "$OUT"
    ## refuse to clobber a file
    if [ ! -f "$OUT" ] ; then
        echo "  artist=$artist"
        echo "  album=$album"
        echo "  track=$track"
        echo "  song=$song"
        echo ""
        DIRECTORY=`dirname "$OUT"`
        mkdir -p "$DIRECTORY" || { echo "permission error" ;
            exit 1 ; }
        lame -b 32 "$IN" "$OUT" \
            --ta "$artist" --tl "$album" \
            --tn "$track" --tt "$song" \
            --add-id3v2
    else
        echo "  already exists!"
    fi
done

Okay, on some files, I *can* tell the difference.

* * *

Compare: 032kbps mp3 versus 128kbps mp3.


(back)