added possibility to set timeout

This commit is contained in:
Robert Gruendler 2013-02-03 20:05:25 +01:00
commit fa651da41a
2 changed files with 10 additions and 1 deletions

View file

@ -30,13 +30,19 @@ abstract class Binary implements AdapterInterface
*/ */
protected $logger; protected $logger;
/**
* @var Integer
*/
protected $timeout;
/** /**
* Binary constructor * Binary constructor
* *
* @param type $binary The path file to the binary * @param type $binary The path file to the binary
* @param Logger $logger A logger * @param Logger $logger A logger
* @param Integer $timeout The timout for the underlying process
*/ */
public function __construct($binary, Logger $logger) public function __construct($binary, Logger $logger, $timeout = 60)
{ {
if (!is_executable($binary)) { if (!is_executable($binary)) {
throw new \FFMpeg\Exception\BinaryNotFoundException(sprintf('`%s` is not a valid binary', $binary)); throw new \FFMpeg\Exception\BinaryNotFoundException(sprintf('`%s` is not a valid binary', $binary));
@ -44,6 +50,7 @@ abstract class Binary implements AdapterInterface
$this->binary = $binary; $this->binary = $binary;
$this->logger = $logger; $this->logger = $logger;
$this->timeout = $timeout;
} }
/** /**

View file

@ -179,6 +179,8 @@ class FFMpeg extends Binary
$builder = ProcessBuilder::create($options); $builder = ProcessBuilder::create($options);
$process = $builder->getProcess(); $process = $builder->getProcess();
$process->setTimeout($this->timeout);
$this->logger->addInfo(sprintf('FFmpeg executes command %s', $process->getCommandline())); $this->logger->addInfo(sprintf('FFmpeg executes command %s', $process->getCommandline()));