0

I'm trying to convert an audio file in PHP using ffmpeg, I get the audio file via post as a m4a and I want to turn it into mp3. I do the following to do this:

$commandOutput = shell_exec('ffmpeg -i '.$filePath.' -ar 8000 -ab 16000 '.str_replace('m4a', 'mp3', $filePath));

Yet it does nothing, and commandOutput also contains nothing. The file is saved properly but not converted to mp3, when I run the same command in terminal it converts the file properly. Any idea what might be happening?

3
  • I'm not 100% certain, but this might be something to do with PHP (or Apache) running in a chroot jail. If it is, you probably won't have the ability to call certain executables or write to certain file paths. Commented Apr 27, 2012 at 20:47
  • Any way around that? This conversion is crucial to my app. Commented Apr 27, 2012 at 20:49
  • See my answer for an alternative. Commented Apr 27, 2012 at 20:51

2 Answers 2

2

Try wrapping commands like this:

exec($cmd." 2>&1", $out, $ret);
if ($ret){
    echo "There was a problem!\n";
    print_r($out);
}else{
    echo "Everything went better than expected!\n";
}

exec() lets you capture all output and get the exit code. Adding 2>&1 makes sure to redirect STDERR to STDOUT so you can see any error messages.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, this revealed the problem I got this output: sh: ffmpeg: command not found
1) use the full path to ffmpeg: /usr/bin/ffmpeg or whatever
2) set your PATH ENV variable from php first: putenv("PATH=/usr/local/bin");
1

You could use the ffmpeg-php extension: http://sourceforge.net/projects/ffmpeg-php/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.