Splitting an audio MP3 file

audio, javascript, mp3, node.js

Solution

You could probably use ffmpeg. It is command line based, which is great since it is accessible, but subprocesses can sometimes die. Here is a node interface that abstracts ffmpeg usage out of command line calls: https://npmjs.org/package/ffmpeg

Your final commands, in the command line would probably look like this:

ffmpeg -i long.mp3 -acodec copy -ss 00:00:00 -t 00:30:00 half1.mp3
ffmpeg -i long.mp3 -acodec copy -ss 00:30:00 -t 00:30:00 half2.mp3

This command states:

- `-i`: the input file is `long.mp3`

- `-acodec`: use the audio codec

- `copy`: we are making a copy

- `-ss`: start time

- `-t`: length

- and finally the output file name

To handle potentially timeouts/hung processes you should 'retry' and supply timeouts. Not sure how well the error callbacks work. That is do they fail appropriately on a process that hangs.

Problem

I would like to split an audio file into smaller parts using NodeJS. I would then like to retain the smaller parts as separate audio files. Can anyone recommend a viable approach with relatively low computational time?

Original source