2

I am executing certain code through ffmpeg to encode avi files to flv. My ffmpeg code is correct and is working fine, but when some error occurs (suppose it is a corrupted avi file, ffmpeg will not encode it), so i want to know what the error is. Here is a sample code:

$v_cmd=" some code to transcode";
exec($v_cmd,$v_output,$v_status);
if($v_status == 0)
{
echo "Success!";
}
else 
{
echo "ERROR: ".$v_output;
}

But this $v_output is just showing up as ERROR: Array ... i tried

echo "ERROR: ".implode($v_output);

but it was blank... how can i get the error message that ffmpeg gave so that i can understand what went wrong. This is a php cron script and it is not run in command line manually.

1 Answer 1

3

In POSIX-compliant systems and applications, errors will be sent to STDERR, not STDOUT. exec will only populate the $output argument with STDOUT:

exec("foo", $output);
var_dump($output);

Displays:

array(0) {
}

You have to redirect STDERR to STDOUT if you want this to work. Per example, on *nix:

exec("foo 2>&1", $output);
var_dump($output);

Will display:

array(1) {
  [0]=>
  string(18) "sh: foo: not found"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks .. the 2>&1 helped. I have modified my code to generate the error based on the var_dump output.

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.