tags:

views:

152

answers:

3

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?

+2  A: 

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
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
Sorry, no clue.
eliah
+1  A: 

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
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
@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
i would give this a try. if encoder setting match then this will probably work and be a very lightweight solution.
fsb
I guess I should go do some research on optimal compression and encoding settings? Hmm....
Scott
+1  A: 

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
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
'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