Are there any ways to automatically trim an MP3 uploaded to a website to 30 seconds (or some other length) in PHP? If not, is there any good 3rd party services that could be integrated (transparently to the user) to achieve the same effect?
Thanks.
Are there any ways to automatically trim an MP3 uploaded to a website to 30 seconds (or some other length) in PHP? If not, is there any good 3rd party services that could be integrated (transparently to the user) to achieve the same effect?
Thanks.
In Debian/ubuntu try installing mpgtx:
I'm sure you'll find mpgtx available in other fine Linux distros too, or just install from source.
source : https://github.com/thegallagher/PHP-MP3/blob/master/README.md
You could try the MP3 Class on PHPClasses. It features the following example:
In this case, the 'frame' can be substituted with 'second' to base the cut on a time-frame.
I used PHP MP3 for my project.
For your case you can use
extract(0,30)
orextract(30,60)
.I put together a script that outputs a 30 second clip of an MP3 file on the fly. If you're looking to save the file, one of the other options using a class/library will probably be best. But, if you just want to play/download the preview, on the fly might be better. It will definitely save you hard drive space.
Check it out at http://www.stephenwalcher.com/2013/06/17/how-to-extract-and-play-part-of-an-mp3-in-php/.
Here's the code, but a deeper explanation can be found on my blog.
I had problems processing some mp3s with both MP3 Class and mpgtx. The best option here is ffmpeg I think. This page has some good examples on splitting media files with ffmpeg.