1

I have a basic php script which converts an avi using ffmpeg:

<?php
if (exec("/usr/bin/ffmpeg -i testvideo.avi -sameq -ar 22050 convertvideo.mp4 2> logfile.log")){ 
echo "Success";
}else{ 
    echo "Error"; 
}
?>

now as an extension to this I would like to use php to check if the file is still being converted if not an email should be sent can anyone advise how I can achieve this?

Also despite using the code above and the file being converted successfully, the output I always get is "Error", can anyone help with this as well?

Thanks

Dino
  • 1,445
  • 4
  • 24
  • 43
  • 1
    Regarding your second question - see return values of exec here: http://us.php.net/manual/en/function.exec.php. Its not 0/1. – jman Jun 11 '12 at 20:33

1 Answers1

2

the following should work:

exec("/usr/bin/ffmpeg -i testvideo.avi -sameq -ar 22050 convertvideo.mp4 2> logfile.log", $ret, $val);

if ($val != 0) {        
    // Video conversion fail for some reason
    $msg = "Error converting video: $ret" . "\n";
    echo ($msg);

    // send the email
    mail("no@body.com", "Error convering video", $msg);
}

If you want to set a timeout to the ffmpeg process consider using the proc_open way (see example).

Community
  • 1
  • 1
EladG
  • 794
  • 9
  • 21