Combine/Concatenate MP3 Files Using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scotthoff
Forum Newbie
Posts: 2
Joined: Fri Jan 29, 2010 1:04 pm

Combine/Concatenate MP3 Files Using PHP

Post by scotthoff »

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.

Code: Select all

 
function appendMP3(originalMP3, newChunk){
      originalMP3 = originalMP3 + newChunk;
}
 
Where do I start? Are there any existing resources?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Combine/Concatenate MP3 Files Using PHP

Post by Christopher »

You wouldn't do it that way. ;)

If you want to combine the files, then you would probably call some program using exec() (or similar function). However, it might make more sense to find a MP3 player that supports playlists. Then you can just generate a playlist (usually XML) to "combine" the files.
(#10850)
scotthoff
Forum Newbie
Posts: 2
Joined: Fri Jan 29, 2010 1:04 pm

Re: Combine/Concatenate MP3 Files Using PHP

Post by scotthoff »

Well then,

So I have the PHP execute some program on the linux box? Would GoDaddy let me do that?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Combine/Concatenate MP3 Files Using PHP

Post by Christopher »

Ask them. ;)

Some types of files can simply be concatenated. Others need the headers removed, to be spliced together, and a new header generated. If you know about MP3 internals it may be possible to read the file headers of the multiple files, generate a new header, send it to the browser, and then send the data from each file to the browser sequentially. The browser would see it as one longer MP3. There may be some PHP code that does this already out then on the interwebs somewhere.
(#10850)
Post Reply