Can now use avconv and avprobe
This commit is contained in:
parent
83408e985f
commit
7f3d76c5fe
3 changed files with 65 additions and 82 deletions
|
|
@ -20,7 +20,6 @@ use \Symfony\Component\Process\ExecutableFinder;
|
|||
*/
|
||||
abstract class Binary implements AdapterInterface
|
||||
{
|
||||
|
||||
protected $binary;
|
||||
|
||||
/**
|
||||
|
|
@ -39,8 +38,7 @@ abstract class Binary implements AdapterInterface
|
|||
{
|
||||
$this->binary = $binary;
|
||||
|
||||
if ( ! $logger)
|
||||
{
|
||||
if ( ! $logger) {
|
||||
$logger = new \Monolog\Logger('default');
|
||||
$logger->pushHandler(new \Monolog\Handler\NullHandler());
|
||||
}
|
||||
|
|
@ -58,9 +56,15 @@ abstract class Binary implements AdapterInterface
|
|||
public static function load(\Monolog\Logger $logger = null)
|
||||
{
|
||||
$finder = new ExecutableFinder();
|
||||
$binary = null;
|
||||
|
||||
if (null === $binary = $finder->find(static::getBinaryName()))
|
||||
{
|
||||
foreach (static::getBinaryName() as $candidate) {
|
||||
if (null !== $binary = $finder->find(static::getBinaryName())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $binary) {
|
||||
throw new Exception\BinaryNotFoundException('Binary not found');
|
||||
}
|
||||
|
||||
|
|
@ -76,5 +80,4 @@ abstract class Binary implements AdapterInterface
|
|||
{
|
||||
throw new \Exception('Should be implemented');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ use \Symfony\Component\Process\Process;
|
|||
*/
|
||||
class FFMpeg extends Binary
|
||||
{
|
||||
|
||||
protected $pathfile;
|
||||
|
||||
/**
|
||||
|
|
@ -32,8 +31,7 @@ class FFMpeg extends Binary
|
|||
*/
|
||||
public function open($pathfile)
|
||||
{
|
||||
if ( ! file_exists($pathfile))
|
||||
{
|
||||
if ( ! file_exists($pathfile)) {
|
||||
$this->logger->addError(sprintf('Request to open %s failed', $pathfile));
|
||||
|
||||
throw new Exception\InvalidFileArgumentException(sprintf('File %s does not exists', $pathfile));
|
||||
|
|
@ -68,8 +66,7 @@ class FFMpeg extends Binary
|
|||
*/
|
||||
public function extractImage($time, $output)
|
||||
{
|
||||
if ( ! $this->pathfile)
|
||||
{
|
||||
if ( ! $this->pathfile) {
|
||||
throw new Exception\LogicException('No file open');
|
||||
}
|
||||
|
||||
|
|
@ -82,17 +79,13 @@ class FFMpeg extends Binary
|
|||
|
||||
$process = new Process($cmd);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
$process->run();
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
} catch (\RuntimeException $e) {
|
||||
|
||||
}
|
||||
|
||||
if ( ! $process->isSuccessful())
|
||||
{
|
||||
if ( ! $process->isSuccessful()) {
|
||||
$this->logger->addError(sprintf('Command failed :: %s', $process->getErrorOutput()));
|
||||
|
||||
$this->cleanupTemporaryFile($output);
|
||||
|
|
@ -117,15 +110,13 @@ class FFMpeg extends Binary
|
|||
*/
|
||||
public function encode(Format\AudioFormat $format, $outputPathfile, $threads = 1)
|
||||
{
|
||||
if ( ! $this->pathfile)
|
||||
{
|
||||
if ( ! $this->pathfile) {
|
||||
throw new Exception\LogicException('No file open');
|
||||
}
|
||||
|
||||
$threads = max(min($threads, 64), 1);
|
||||
|
||||
switch (true)
|
||||
{
|
||||
switch (true) {
|
||||
case $format instanceof Format\VideoFormat:
|
||||
$this->encodeVideo($format, $outputPathfile, $threads);
|
||||
break;
|
||||
|
|
@ -161,17 +152,13 @@ class FFMpeg extends Binary
|
|||
|
||||
$process = new Process($cmd);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
$process->run();
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
} catch (\RuntimeException $e) {
|
||||
|
||||
}
|
||||
|
||||
if ( ! $process->isSuccessful())
|
||||
{
|
||||
if ( ! $process->isSuccessful()) {
|
||||
throw new Exception\RuntimeException(sprintf('Encoding failed : %s', $process->getErrorOutput()));
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +174,7 @@ class FFMpeg extends Binary
|
|||
* @return \FFMpeg\FFMpeg
|
||||
* @throws Exception\RuntimeException
|
||||
*/
|
||||
protected function encodeVideo(Format\VideoFormat $format, $outputPathfile, $threads)
|
||||
protected function encodeVideo(Format\VideoFormat $format, $outputPathfile, $threads, $control)
|
||||
{
|
||||
$cmd_part1 = $this->binary
|
||||
. ' -y -i '
|
||||
|
|
@ -218,16 +205,19 @@ class FFMpeg extends Binary
|
|||
|
||||
$process = null;
|
||||
|
||||
foreach ($passes as $pass)
|
||||
{
|
||||
foreach ($passes as $pass) {
|
||||
$process = new Process($pass);
|
||||
|
||||
try
|
||||
{
|
||||
$process->run();
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
try {
|
||||
// $process->run();
|
||||
$process->run(function($data, $dodo) {
|
||||
// echo $data.$dodo."\nend chunk\n";
|
||||
$matches = array();
|
||||
preg_match('/time=([0-9:\.]+)/', $dodo, $matches);
|
||||
if ($matches[1])
|
||||
var_dump($matches);
|
||||
});
|
||||
} catch (\RuntimeException $e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -236,8 +226,7 @@ class FFMpeg extends Binary
|
|||
$this->cleanupTemporaryFile(getcwd() . '/ffmpeg2pass-0.log');
|
||||
$this->cleanupTemporaryFile(getcwd() . '/ffmpeg2pass-0.log.mbtree');
|
||||
|
||||
if ( ! $process->isSuccessful())
|
||||
{
|
||||
if ( ! $process->isSuccessful()) {
|
||||
throw new Exception\RuntimeException(sprintf('Encoding failed : %s', $process->getErrorOutput()));
|
||||
}
|
||||
|
||||
|
|
@ -251,8 +240,7 @@ class FFMpeg extends Binary
|
|||
*/
|
||||
protected function cleanupTemporaryFile($pathfile)
|
||||
{
|
||||
if (file_exists($pathfile) && is_writable($pathfile))
|
||||
{
|
||||
if (file_exists($pathfile) && is_writable($pathfile)) {
|
||||
unlink($pathfile);
|
||||
}
|
||||
}
|
||||
|
|
@ -264,7 +252,6 @@ class FFMpeg extends Binary
|
|||
*/
|
||||
protected static function getBinaryName()
|
||||
{
|
||||
return 'ffmpeg';
|
||||
return array('avconv', 'ffmpeg');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ class FFProbe extends Binary
|
|||
*/
|
||||
public function probeFormat($pathfile)
|
||||
{
|
||||
if ( ! is_file($pathfile))
|
||||
{
|
||||
if ( ! is_file($pathfile)) {
|
||||
throw new Exception\InvalidFileArgumentException($pathfile);
|
||||
}
|
||||
|
||||
|
|
@ -51,8 +50,7 @@ class FFProbe extends Binary
|
|||
*/
|
||||
public function probeStreams($pathfile)
|
||||
{
|
||||
if ( ! is_file($pathfile))
|
||||
{
|
||||
if ( ! is_file($pathfile)) {
|
||||
throw new Exception\InvalidFileArgumentException($pathfile);
|
||||
}
|
||||
|
||||
|
|
@ -69,19 +67,15 @@ class FFProbe extends Binary
|
|||
*/
|
||||
protected function executeProbe($command)
|
||||
{
|
||||
try
|
||||
{
|
||||
try {
|
||||
$process = new Process($command);
|
||||
|
||||
$process->run();
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new Exception\RuntimeException(sprintf('Failed to run the given command %s', $command));
|
||||
}
|
||||
|
||||
if ( ! $process->isSuccessful())
|
||||
{
|
||||
if ( ! $process->isSuccessful()) {
|
||||
throw new Exception\RuntimeException(sprintf('Failed to probe %s', $command));
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +89,6 @@ class FFProbe extends Binary
|
|||
*/
|
||||
protected static function getBinaryName()
|
||||
{
|
||||
return 'ffprobe';
|
||||
return array('avprobe', 'ffprobe');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue