BinaryBird Posted May 22, 2010 Share Posted May 22, 2010 Hello, me a few friends of mine are developing a php-based music store for a client. The client specifically wanted a preview option where by users could listen to the first 30 seconds of a song. All the songs are .mp3's Could any one tell me, if it is possible to trim down a mp3's duration to the first 30 seconds using php? or suggest any player that will limit the clip duration to 30 seconds? We are currently using a xml based flash player to play the songs on the site. There are quite a high number of songs, so creating a short 30 seconds clips would not be ideal. And please forgive me if i have posted the question in the wrong section. Kindly help me out. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/ Share on other sites More sharing options...
Daniel0 Posted May 22, 2010 Share Posted May 22, 2010 If you've got ffmpeg on your server, you can use it to do it. Something like this should do the trick: ffmpeg -t 30 -i original.mp3 -acodec copy trimmed.mp3 Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/#findComment-1062064 Share on other sites More sharing options...
BinaryBird Posted May 22, 2010 Author Share Posted May 22, 2010 If you've got ffmpeg on your server, you can use it to do it. Something like this should do the trick: ffmpeg -t 30 -i original.mp3 -acodec copy trimmed.mp3 The server has Cent OS 5 running. The option you are suggesting is to trim the song on the fly? Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/#findComment-1062071 Share on other sites More sharing options...
Daniel0 Posted May 22, 2010 Share Posted May 22, 2010 Assuming that you've got ffmpeg installed, that command will take the first 30 seconds of original.mp3 and put them in trimmed.mp3. Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/#findComment-1062075 Share on other sites More sharing options...
paddyhaig Posted May 22, 2010 Share Posted May 22, 2010 I get what you are saying, this is just an idea. But I wonder if it is possible to utilize, this little bit of a timer script. You could put it in the header of the page that play's the mp3 and then the customer would only be able to hear the first few seconds of the tune. As I said it's just an idea. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin redirTime = "26000"; redirURL = "http://your_domain_and_file.htm"; function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); } // End --> </script> Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/#findComment-1062076 Share on other sites More sharing options...
BinaryBird Posted May 22, 2010 Author Share Posted May 22, 2010 Thanks for the suggestion. Is it not possible to limit the duration of a mp3 using php? The main problem is that there are more than 100,000 songs. So creating separate clips for all those songs will take up space and if required to do on the fly, it might take up server resources. So thinking if there is a way to extract 30 seconds from a song or limit the duration to 30 sec using php. In any case thanks for your suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/#findComment-1062078 Share on other sites More sharing options...
BinaryBird Posted May 22, 2010 Author Share Posted May 22, 2010 I get what you are saying, this is just an idea. But I wonder if it is possible to utilize, this little bit of a timer script. You could put it in the header of the page that play's the mp3 and then the customer would only be able to hear the first few seconds of the tune. As I said it's just an idea. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin redirTime = "26000"; redirURL = "http://your_domain_and_file.htm"; function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); } // End --> </script> Thanks for the idea paddy. Will try it out. Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/#findComment-1062079 Share on other sites More sharing options...
Daniel0 Posted May 23, 2010 Share Posted May 23, 2010 Thanks for the suggestion. Is it not possible to limit the duration of a mp3 using php? The main problem is that there are more than 100,000 songs. So creating separate clips for all those songs will take up space and if required to do on the fly, it might take up server resources. So thinking if there is a way to extract 30 seconds from a song or limit the duration to 30 sec using php. In any case thanks for your suggestion. Doing it on-the-fly takes no time. I just tried on a random MP3 file and it took 0.04 seconds completing. If you have a lot of users and are worried about spending a lot of resources, pre-generating them and storing them on the disk would be a good idea. You could implement a trimming function using PHP, but it would be no more efficient than using ffmpeg. Actually, it's unlikely it would be more efficient. I get what you are saying, this is just an idea. But I wonder if it is possible to utilize, this little bit of a timer script. You could put it in the header of the page that play's the mp3 and then the customer would only be able to hear the first few seconds of the tune. As I said it's just an idea. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin redirTime = "26000"; redirURL = "http://your_domain_and_file.htm"; function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); } // End --> </script> Thanks for the idea paddy. Will try it out. That won't work unless you're willing to let anyone download the entire file. What's preventing them from disabling Javascript or just checking out your HTML code? Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/#findComment-1062081 Share on other sites More sharing options...
BinaryBird Posted May 23, 2010 Author Share Posted May 23, 2010 You have got a point. We cannot let users download the songs unless they purchase them. I will try out the ffmpeg method first. Thanks anyways. Quote Link to comment https://forums.phpfreaks.com/topic/202612-need-suggestions-for-trimming-a-mp3/#findComment-1062084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.