5

I'm running the ffmpeg command within PHP's shell_exec() to convert several videos in a list. Is there anyway to detect if an error happened while the video was being converted (or atleast verify it fully completed the conversion)?

I don't want to stop converting other videos if an error happens, just the ability to record the error.

<?php
    shell_exec('ffmpeg -i downloads/flv/file1.flv -vcodec libvpx -acodec libvorbis downloads/webm/file1.webm');

    if(error) {
     //run a command here to report the error (ie. MySQL or email)
    }
?>
3
  • are you looking for an error returned from ffmpeg? Commented Oct 28, 2011 at 0:13
  • shell_exec returns the output of executed commend, if ffmpeg prints the error you should be able to parse it. Commented Oct 28, 2011 at 0:15
  • how to get the error returned from ffmpeg ? Commented Dec 4, 2014 at 11:32

2 Answers 2

14

Capture the exit code with another system call function like exec:

exec('ffmpeg ...', $output, $return);

if ($return != 0) {
    // an error occurred
}

Any decent utility will exit with a code other than 0 on error.

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

2 Comments

Or check if ($return != 1). 1 is an error and 0 is no error exit code. You can debug in the Unix CLI directly with echo "$?" after executing your command.
Well, 0 means "all green", while anything other than 0 means "error". There are more error codes than just 1. I don't know if ffmpeg in particular uses anything besides 0 and 1.
-2
$return=shell_exec('ffmpeg ...');

if ($return) { //look at what it returns do what you will with the data

}

Comments

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.