ComSoc Community

Users helping users!

In Memory of Jacques "Jack" Berlin
General Meeting Aug 27, 2019 Amherst Audubon Library   

Splitting a large mp3 file into smaller chunks for an mp3 player
Read 13250 times
* December 29, 2008, 08:07:13 am
I'm posting this because it may be useful to someone in the same situation.  Also, I want to show a little bit of the process I went through to solve the problem.  A lot of the time when I see a solution, it's tempting to think that some genius just sat down and knocked it out first try.  But more often than not, it takes a few tries and false starts before something works.

I know that not too many in this group are familiar with bash programming so I also show the script I wrote to turn the solution into a utility I can reuse.  I don't comment much on the script itself, but if anyone has questions, feel free.

I had an audio version of a book in the form of one 21+ hour mp3 file.
This file is difficult to manage and my stand-alone player gives up
after playing about 2 hours - and if the battery dies, it loses its place and I have to hold down the fast forward button for an hour before it gets back to where I left off.

I decided to break the file into one hour chunks.

I tried loading it into audacity (which took 15 minutes and created 15GB of wav files that almost crashed my system).   This took awhile to find in a hidden directory .audacity* in my home directory.  Meanwhile I had no disk space to do anything on my root partition.  I couldn't even save an email until I found some other stuff to delete.

I figured I could select one section at a time and save it to its own file.
I was finally able to select a section and save it to disk, but there were a few tricks.  In the audacity save as dialog, you have to select files of type mp3 or it saves it in wav format and you have to run each section through lame afterwards to change it back to mp3 - not fun.

The audacity help function doesn't work on my system, but I finally managed to download the manual in pdf form from the audacity site on sourceforge from the project documentation area.

Next, I found a utility called mp3split, but could not find a deb that would
install (found one for it, but not for its library) and could not
compile it from source.

All of this proved unnecessary when someone finally pointed out that the package (which didn't show up in adept) was actually called mp3splt.

This is a really neat program that does just what I wanted it to do.  It's really fast because it doesn't convert the file to another format like audacity does.  It just copies it while keeping its structure intact.

All that was left to do was to write a shell script that would invoke it nicely:

## Audiobook splitter

## Usage is audiobooksplit [-t minutes-per-part] file.mp3

NAME=$(basename $"0")
USAGE="Usage is $NAME [-t minutes-per-part] file.mp3"

if [ "$1" == "-t" ]

if (( LENGTH < 1 ))
  echo $USAGE >&2
  exit 1

if [ ! -r "${1}" ]
  echo "Cannot read [$1]" >&2
  exit 1


mp3splt -o "${OUT} part @n.mp3" -t ${LENGTH}.00 "${IN}"


The -o lets you control the names given to the partial files with @n
giving a three digit part number to make the file names unique.

mp3splt does a less than stellar job of filling in the id3 tags on the
new files, but at least it tries.

If you find any of this useful, let me know.