Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting an audio MP3 file [closed]

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?

like image 330
jvrdelafuente Avatar asked Jan 31 '14 22:01

jvrdelafuente


2 Answers

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.

like image 90
Parris Avatar answered Oct 05 '22 23:10

Parris


You may be able to use node-lame to decode an mp3 into raw PCM and then just split the data directly... I can't admit to being an expert on audio formats, but my assumption is that PCM is a fairly naive format without much in the way of bit-twiddling going on, so simply figuring out the percentage of the file that should be in the first section vs the second, and then cutting there should give you two bits of data that you can re-encode using the same module back into mp3s.

Provided the mp3s are constant bit-rate, then you may be able to the same thing with the mp3 file directly. I remember back in the wild-west days of Napster and Kazaa and their ilk that I would have downloads cut off halfway through and I'd be able to listen to half of the song without issue. I don't know how likely that is to work exactly the way you want it to, but worth a shot.

like image 41
Jason Avatar answered Oct 05 '22 22:10

Jason