5

I have a site that will be hosting small MP3 files.

I want to create a utility that will allow me to combine the mp3 files together to create a single MP3 file.

I'm somewhat new to PHP but not new to programming.

Ideally, I would have a function that let me specify the a starting file and then append the second file to the existing file.

function appendMP3(originalMP3, newChunk){
   originalMP3 = originalMP3 + newChunk;
   return newMP3
}

compilation = append(compilaton, "sound.mp3");

Where do I start? Are there any existing resources?

hakre
  • 193,403
  • 52
  • 435
  • 836
Scott
  • 877
  • 4
  • 12
  • 24

4 Answers4

2

If you can access the shell from within PHP on your environment, I would just call out to the shell (with the backtick operator) and use SoX.

eliah
  • 2,267
  • 1
  • 21
  • 23
  • I have my hosting on goDaddy. I have never really messed with Linux before. I can learn if I need to and it is efficient. Any idea about what godaddy would allow you to use? – Scott Jan 29 '10 at 19:41
1

Not sure how well it will work, but this blog on merging mp3 with php might help you.

Also, depending on the server it is on, you might have access to tools like sox using system() calls.

gnarf
  • 105,192
  • 25
  • 127
  • 161
  • That is the only thing I could find as well. The thing that made me nervous was that the guy who developed it said that it would be slow and memory intensive. Maybe no matter what happens will be slow and memory intensive. I don't know. – Scott Jan 29 '10 at 19:39
  • 'slow and memory intensive' is absolutely unavoidable when you use php to do something so un-php. my suggestion is - use it, i do, it works – Nir Gavish Feb 09 '10 at 11:19
0

There is an library called getID3. It has the ability to join multiple MP3 files into one , although I have never used this functionality. There is an demo available at the Source Forge site of getID3 here http://getid3.sourceforge.net/source/demo.joinmp3.phps. It seems that it works around without using any command line system calls.

I have used this library for getting lengths and other data from various media formats. It worked like a charm. However, as said, I have not tested the CombineMultipleMP3sTo() function in it...

You should test this as if it would work for you it would be a far easier option than LAME (which is powerful yet rather complicated to use in my opinion).

Michal
  • 3,262
  • 4
  • 30
  • 50
0

I would suggest taking a look at the PHP fopen function. If concatenating two MP3 files is as simple as stringing the bits together, then you should be able to use fopen (don't forget the "b" flag for binary) and fwrite to read in the data from one file and append it to the other.

Peter Loron
  • 1,156
  • 10
  • 15
  • It is not that simple, you need to strip the IDv3 tags, etc from the end of the sound streams... Also, if they are in different bitrates, you might have some small issues. – gnarf Jan 29 '10 at 19:33
  • @gnarf: I am in for a world of trouble b/c before I started working on Drupal file uploads I had never even heard of the IDv3 tags. Or at best, I heard about them and forgot. Regarding byte rate, I am going to be the site admin and I could mandate that it be at the same bitrate. I would need to figure out what that optimal rate would be... – Scott Jan 29 '10 at 19:38
  • i would give this a try. if encoder setting match then this will probably work and be a very lightweight solution. –  Jan 29 '10 at 20:12
  • I guess I should go do some research on optimal compression and encoding settings? Hmm.... – Scott Jan 29 '10 at 20:32