2012-04-13 10:20:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
2012-04-13 14:34:53 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of PHP-FFmpeg.
|
|
|
|
|
*
|
|
|
|
|
* (c) Alchemy <info@alchemy.fr>
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-04-13 10:20:54 +02:00
|
|
|
namespace FFMpeg;
|
|
|
|
|
|
2012-05-25 16:21:16 +02:00
|
|
|
use FFMpeg\Exception\BinaryNotFoundException;
|
|
|
|
|
use Monolog\Logger;
|
|
|
|
|
use Symfony\Component\Process\ExecutableFinder;
|
2012-04-13 15:27:10 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Binary abstract class
|
2012-04-13 15:42:34 +02:00
|
|
|
*
|
|
|
|
|
* @author Romain Neutron imprec@gmail.com
|
2012-04-13 15:27:10 +02:00
|
|
|
*/
|
2012-04-13 10:20:54 +02:00
|
|
|
abstract class Binary implements AdapterInterface
|
|
|
|
|
{
|
|
|
|
|
protected $binary;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2012-05-25 16:21:16 +02:00
|
|
|
* @var Logger
|
2012-04-13 10:20:54 +02:00
|
|
|
*/
|
|
|
|
|
protected $logger;
|
|
|
|
|
|
2013-02-03 20:05:25 +01:00
|
|
|
/**
|
|
|
|
|
* @var Integer
|
|
|
|
|
*/
|
|
|
|
|
protected $timeout;
|
|
|
|
|
|
2012-04-13 15:27:10 +02:00
|
|
|
/**
|
|
|
|
|
* Binary constructor
|
|
|
|
|
*
|
2012-05-25 16:22:16 +02:00
|
|
|
* @param type $binary The path file to the binary
|
2012-05-25 16:21:16 +02:00
|
|
|
* @param Logger $logger A logger
|
2013-02-03 20:05:25 +01:00
|
|
|
* @param Integer $timeout The timout for the underlying process
|
2012-04-13 15:27:10 +02:00
|
|
|
*/
|
2013-02-03 20:05:25 +01:00
|
|
|
public function __construct($binary, Logger $logger, $timeout = 60)
|
2012-04-13 10:20:54 +02:00
|
|
|
{
|
2012-09-03 14:52:53 +02:00
|
|
|
if (!is_executable($binary)) {
|
|
|
|
|
throw new \FFMpeg\Exception\BinaryNotFoundException(sprintf('`%s` is not a valid binary', $binary));
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-13 10:20:54 +02:00
|
|
|
$this->binary = $binary;
|
|
|
|
|
$this->logger = $logger;
|
2013-02-03 20:05:25 +01:00
|
|
|
$this->timeout = $timeout;
|
2012-04-13 10:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-13 15:27:10 +02:00
|
|
|
/**
|
2012-05-25 16:21:16 +02:00
|
|
|
* Destructor
|
|
|
|
|
*/
|
|
|
|
|
public function __destruct()
|
|
|
|
|
{
|
|
|
|
|
$this->binary = $binary = $this->logger = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*
|
2012-05-25 16:22:16 +02:00
|
|
|
* @param Logger $logger A logger
|
|
|
|
|
* @return Binary The binary
|
2012-04-13 15:27:10 +02:00
|
|
|
*
|
|
|
|
|
* @throws Exception\BinaryNotFoundException
|
|
|
|
|
*/
|
2012-05-25 16:21:16 +02:00
|
|
|
public static function load(Logger $logger)
|
2012-04-13 10:20:54 +02:00
|
|
|
{
|
2012-04-13 15:27:10 +02:00
|
|
|
$finder = new ExecutableFinder();
|
2012-05-11 00:30:02 +02:00
|
|
|
$binary = null;
|
|
|
|
|
|
|
|
|
|
foreach (static::getBinaryName() as $candidate) {
|
2012-05-11 00:34:19 +02:00
|
|
|
if (null !== $binary = $finder->find($candidate)) {
|
2012-05-11 00:30:02 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-13 14:43:35 +02:00
|
|
|
|
2012-05-11 00:30:02 +02:00
|
|
|
if (null === $binary) {
|
2012-05-25 16:21:16 +02:00
|
|
|
throw new BinaryNotFoundException('Binary not found');
|
2012-04-13 10:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new static($binary, $logger);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-13 15:27:10 +02:00
|
|
|
/**
|
|
|
|
|
* Return the binary name
|
|
|
|
|
*/
|
2012-04-13 10:20:54 +02:00
|
|
|
protected static function getBinaryName()
|
|
|
|
|
{
|
2012-04-13 15:27:10 +02:00
|
|
|
throw new \Exception('Should be implemented');
|
2012-04-13 10:20:54 +02:00
|
|
|
}
|
2012-04-13 15:27:10 +02:00
|
|
|
}
|