Anything to recode mp3 files in the ports?

dgmm freebsd01 at dgmm.net
Sun Apr 16 19:17:47 UTC 2006


On Saturday 15 April 2006 14:08, Mikhail Teterin wrote:
> Hi!
>
> I have a sizable collection of mp3 files (most of my CDs, actually) encoded
> at high ratio for archiving.
>
> I'd like to put some of them on a low-capacity player. Is there a utility
> (preferably -- a ported one), that can reencode an existing mp3 file at
> lower quality settings (hence smaller size), or do I have to re-rip the CDs
> from scratch?
>
> Thanks!
>
> 	-mi

I used this last year to convert a collection of radio shows, audio books and 
music.  I wanted different rates dependant on content and at the time thought 
this was the way to go.  If you try it, beware that it does not cope well 
with "odd" filesnames, eg with spaces in the name etc.

(watch out for line wrap)

#!/bin/sh
basedir=/home1/convert
touch ${basedir}/mp3lock
# Convert all mp3 files in $basedir to $bitrate, $samplerate, $channels
# where $bitrate, $samplerate and $channels are derived from the pathname.
#
# $basedir - "top" of the tree to convert. Below $basedir should be two
#            directories named "todo" and "done".
#            Below "todo" you must create directories named using this
#            convention:
#            @bb at ss@cc@ - where bb is the desired bitrate, ss is the desired
#                         samplerate and cc is the channels or mode.  The mode
#                         may be one of s, stereo, j, joint-stereo, m, mono,
#                         f, forced joint-stereo or d, duel channel.
#            The mp3 files will be stored  below "todo/@bb at ss@cc@" and will be
#            converted using the parameters extracted from the directory name 
and
#            then saved into an identical dir structure below "done".
#
#            Note:  Spaces in the filenames will be replaced with underscores.
#                   Spaces in directory names will remain as is
#
#            The original file will be deleted after it has been converted.
#            Comment out the rm "$filename" near the end to keep the original.
#
# $ffile  - just the filename (in case we need this at a future date)
#
# $destfile - full, modified, path to the "done" dir tree

find "$basedir"/todo -name "*.mp3" -type f |
while read filename
  do
    destfile=`echo -n "$filename" | sed 's/\/todo\//\/done\//' | sed 
's/ /_/g'`
    ffile=${destfile##*/}
    fpath=${destfile%/*}
# Check if dest. path exists, create if req.
    if [ ! -d "$fpath" ]
      then
        mkdir -p "$fpath"
    fi
# Get conversion parameters from pathname
    bitrate=`echo $destfile | cut -f 2 -d @`
    samplerate=`echo $destfile | cut -f 3 -d @`
    channels=`echo $destfile | cut -f 4 -d @`
    nice -n 20 lame -h -b $bitrate --resample $samplerate -m $channels 
"$filename" "$destfile"
#   rm "$filename"
  done
rm `echo ${basedir}/mp3lock`



-- 
Dave


More information about the freebsd-questions mailing list