Andrew
Andrew

Reputation: 43

ffmpeg audio convert not working

I cannot get the ffmpeg audio convert working on my site. The idea is that file should be converted when it's uploaded on the site.

I've got this on my upload form determining the audio file's format:

if(isset($_POST['audio']) && $_POST['audio'] != ''){
                $ext1 = substr($_POST['audio'], -4);

This is the best I've come up with for converting m4a to mp3:

if(isset($_POST['audio']) && $_POST['audio'] != ''){ $file = $_POST['audio'];     if($ext1==".m4a"){ $call="/usr/local/bin/ffmpeg -i ".$file." -ab 192k -f -acodec mp3";}
$convert = (popen("start /b ".$call, "r")); pclose($convert);

The problem is, it won't convert. The path to ffmpeg is correct.

Now I may be way over my head with this one, but if there's a simple solution for this, I'd love to hear it.

EDIT.

With this:

if(isset($_POST['audio']) && $_POST['audio'] != ''){
    $file = $_POST['audio'];
                    $ext1 = substr($_POST['audio'], -4); /*get the last 4 chars*/
                    $mp3 = echo 'mp3';
if($ext1=".m4a"){ 
"/usr/local/bin/ffmpeg -i \"". $file . "\" -ab 192k -y -f mp3 \"".ext1.$mp3."\"";
}
}

I think I'm right on the money with conversion itself, but the form just loads infinitly when submitted. So I'm guessing the conversion is happening, but the form does not know when it's done. Any ideas on that?

Upvotes: 0

Views: 728

Answers (1)

Ivelin
Ivelin

Reputation: 13269

Use SoX - the Swiss Army knife of sound processing. Very easy to use.

It is a command line tool not a PHP library so to use from PHP you need to execute a shell command and get the result with in your code. I have used it with in few projects.

Example with PHP:

SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files, and, as an added bonus, SoX can play and record audio files on most platforms.

SoX is very mature project! Here is the link: http://sox.sourceforge.net/

Here are some examples I googled for you: http://www.thegeekstuff.com/2009/05/sound-exchange-sox-15-examples-to-manipulate-audio-files/

Upvotes: 1

Related Questions