0

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?

Jeremy Roy
  • 1,291
  • 5
  • 18
  • 31
  • 2
    ffmpeg is quite verbose with it's output, what does it say? What happens when you try the same thing from the command line? – Raoul May 18 '11 at 10:39
  • 1
    If you aren't piping error messages to stdout, look into the servers `error.log` for hints. – mario May 18 '11 at 10:40
  • Thanks @Raoul, that error produces the error messages simply. Is there a way to get other / more precise error messages? I didn't try that in the command line since I'm testing directly on the distant server. – Jeremy Roy May 18 '11 at 10:42
  • look for log files created, also connect remotely and test it from the command line. It's a waste of time to try and automate something if you don't know that it works at all from the command prompt – Raoul May 18 '11 at 10:45

2 Answers2

2

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.

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291
  • thanks @mario. What is the second parameter? Also I have declared none of the 2nd and 3rd variables here. – Jeremy Roy May 18 '11 at 11:11
  • 1
    The `$output` will be an array of the actual output. The exec() result string only contains the last output line from the command. – mario May 18 '11 at 11:12
  • Thanks @mario, I am doing this test. – Jeremy Roy May 18 '11 at 11:24
  • @mario, by doing this, the exec condition passes since I see no error, but, nothing gets stored in the intended directory, means, the function exec returns to true, but it doesn't do what it should do. – Jeremy Roy May 18 '11 at 11:43
  • Can't tell. I would get a permissions error and a correct errorlevel if anything goes wrong. Add the generated and complete output anyway to your question.-- Your only other option then is to prepend the command with `strace` (must be installed) and sift through the log output. – mario May 18 '11 at 11:49
  • Finally I could get this error from output: `[0] => sh: /usr/local/bin/ffmpeg: No such file or directory` now this is strange, because I got confirmation from my server that this is the correct place where my ffmpeg is installed. – Jeremy Roy May 18 '11 at 12:23
  • 1
    Use `echo exec("which ffmpeg");` to verify. – mario May 18 '11 at 12:33
  • @mario, I am getting nothing with exec("which ffmpeg"). I was extracting the in an array, like this: `$error[] = exec("which ffmpeg")`and then on var_dump, I got `[1]=> string(0) ""` for this one. – Jeremy Roy May 18 '11 at 12:58
  • I then went to a new php page, and typed echo echo `'test => '. exec('which ffmpeg').' end of test';` on refreshing, I get `test => end of test` – Jeremy Roy May 18 '11 at 13:03
  • 1
    You should have tested with `echo exec(` just. If it outputs nothing, then ffmpeg is not installed. Which would explain why it doesn't work. – mario May 18 '11 at 13:15
  • thanks @mario, just by doing echo exec('which ffmpeg'); I get nothing printed. Strange in that case because my server administrator is repeatedly telling me that ffmpeg is installed. I submitted a ticket to my server. Many thanks. – Jeremy Roy May 18 '11 at 13:17
  • Hi, you were right, the ffmpeg was not there. They had a server upgrade when they didn't reinstall the ffmpeg. Ha ! – Jeremy Roy May 18 '11 at 20:27
0

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.)

Jon Skarpeteig
  • 4,118
  • 7
  • 34
  • 53