Jeremy Roy
Jeremy Roy

Reputation: 1291

exec ffmpeg is failing, possible reasons or solutions?

I have this code failing:

$newName = $_SERVER['REMOTE_ADDR'].'_'.time();
$fileName=$newName.$extension;
$flvName=$newName.'.flv';
$ffmpegPath = "/usr/bin/ffmpeg";
$destination_file = $this->folder.basename($fileName);
$destination_movie = $this->folder.'original/'.basename($fileName);
$destination_flv = $this->folder.'flv/'.basename($flvName);
$destination_image = $doc_upload.'thumb/'.$newName.'.jpg';
$ffmpegDo = $ffmpegPath." -i ".$destination_movie." -ar 22050 -ab 128 -b 3600 -f flv -s 320x240 ".$destination_flv;
if (!exec($ffmpegDo)) { $error[] = ERROR_EXEC_FFMPEGDO.':'.$ffmpegDo; }

Any idea why this can fail? Thanks guys.

Edit: No error file is getting generated.

$ffmpegDo looks like this:

/usr/local/bin/ffmpeg -i /home/myaccount/public_html/upload/videos/original/86.69.191.177_1305714026.mpeg -ar 22050 -ab 128 -b 3600 -f flv -s 320x240 /home/myaccount/public_html/upload/videos/flv/86.69.191.177_1305714026.flv

Using the method described in the answer below, I got this error:

[0] => sh: /usr/local/bin/ffmpeg: No such file or directory

This is strange because my server guys specified me that this was my ffmpeg location. Now what?

Upvotes: 0

Views: 1051

Answers (2)

Jon Skarpeteig
Jon Skarpeteig

Reputation: 4128

Looking at your error:

[0] => sh: /usr/local/bin/ffmpeg: No such file or directory

It's fairly explicit on what's wrong (ffmpeg binary simply isn't there). What you can try is to ommit the leading path, and simply do:

ffmpeg -i /home/myaccount/public_html/upload/videos/original/86.69.191.177_1305714026.mpeg -ar 22050 -ab 128 -b 3600 -f flv -s 320x240 /home/myaccount/public_html/upload/videos/flv/86.69.191.177_1305714026.flv

That way, it will look for ffmpeg in all paths defined in the PATH variable of the OS. (typically places like /bin /sbin /usr/bin /usr/sbin etc.)

Upvotes: 0

mario
mario

Reputation: 145512

See also using shell_exec to call a perl script from php. In your case you can get the specific error messages, but also a general $result errorlevel using:

exec("$ffmpegDo 2>&1", $output, $result);
if ($result != 0) {
    $error[] = ERROR_EXEC_FFMPEGDO.':'.$ffmpegDo; 
}

The third parameter to exec specifies the result variable. For most Unix commands it will contain a 0 for success, and any other integer if an error occured.

Upvotes: 2

Related Questions