5

I'm trying to run ffmpeg through a PHP exec call, I've been debugging for a while and looked at lot of responses on here, but still not found any answers...

My simplified call is:

$cmd = 'ffmpeg 2>&1';

exec(escapeshellcmd($cmd), $stdout, $stderr);

var_dump($stderr);
var_dump($stdout);
var_dump($cmd);
exit;

My output is $stderr = int(1) and $stdout = array(0) { }

Also I tried shell_exec($cmd) which returns NULL.

cmd.exe has permissions set for the IUSR account - e.g. I can run $cmd = 'dir' and see a directory listing output.

PHP is not running in safe mode.

The ffmpeg.exe is in the same directory as my php file, but I have the same response giving an absolute path to the ffmpeg.exe file in $cmd.

ffmpeg is executing fine from the command line.

I'm running Windows XP, IIS and PHP 5.3.

EDIT:

If I run 'ffmpeg -h' I get the help commands, which must indicated that ffmpeg is recognised

I've increased the PHP memory limit to 1024 - no luck.

1
  • The second parameter to exec() is the return value, not stderr. A return value of 1 implies that it errored. I have no idea why you don't see the error output in $stdout though. Commented Mar 19, 2012 at 13:09

1 Answer 1

7

I've now got this working - I think there may have been several issues:

It turns out that $cmd = 'ffmpeg' returns null, so it's not a good test!

Also running escape shell command on '2>&1' echoes 2^>^&1" - I think this was my original problem.

I've now managed to rea test file using: 'ffmpeg -i SAMPLE.AVI 2>&1'.

Working code:

$cmd = 'ffmpeg -i SAMPLE.AVI 2>&1';

exec($cmd, $output, $value);

var_dump($output);
var_dump($value);
var_dump($cmd);
exit;

As noted above ffmpeg is a bit of a memory hog, so it's worth checking memory too.

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

2 Comments

So in other words, ffmpeg only writes to the stderr instead of the stdout?
the command does not return null, it will list out the configuration. Show the default output with $cmd = 'ffmpeg 2>&1';

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.