Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top