问题
What options do I have for converting MP3's to OGG on the fly using PHP? I assume the only way to do this is via the command line with an execute statement. Is this true? If so, what converters (and associated commands) would I be best off using?
I have tried:
oggenc2.exe but was told by the program that the MP3 I passed was not a valid filetype
ffmpeg.exe but was unable to figure out how to go from mp3 to ogg (found how to go from ogg to mp3 though)
Convert mp3 to ogg via php
回答1:
You didn't look very far...
exec("/usr/bin/ffmpeg -i infile.mp3 -acodec libvorbis outfile.ogg");
回答2:
It is now recommended (see note below) to use avconv to convert audio and video files instead of ffmpeg.
avconv -i in.mp3 -ar 16000 out.ogg
Where 16000 is the sample rate. You can inspect the sample rate of the source file with:
file in.mp3
Note: I got this warning on my Ubuntu box using ffmpeg: THIS PROGRAM IS DEPRECATED. This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
来源:https://stackoverflow.com/questions/11930636/convert-mp3-m4p-and-the-likes-to-ogg-via-command-line-for-html5-compatibil