added support for retrieving progress information via helpers

This commit is contained in:
Robert Gruendler 2012-11-25 15:40:20 +01:00
commit 36b0036285
10 changed files with 463 additions and 7 deletions

View file

@ -16,6 +16,7 @@ use FFMpeg\Exception\LogicException;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Format\Audio;
use FFMpeg\Format\Video;
use FFMpeg\Helper\HelperInterface;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
@ -35,6 +36,11 @@ class FFMpeg extends Binary
protected $prober;
protected $threads = 1;
/**
* @var HelperInterface[]
*/
protected $helpers = array();
/**
* Destructor
*/
@ -44,6 +50,24 @@ class FFMpeg extends Binary
parent::__destruct();
}
/**
* @param HelperInterface $helper
* @return \FFMpeg\FFMpeg
*/
public function attachHelper(HelperInterface $helper)
{
$this->helpers[] = $helper;
$helper->setProber($this->prober);
// ensure the helpers have the path to the file in case
// they need to probe for format information
if ($this->pathfile !== null) {
$helper->open($this->pathfile);
}
return $this;
}
public function setThreads($threads)
{
if ($threads > 64 || $threads < 1) {
@ -76,9 +100,12 @@ class FFMpeg extends Binary
}
$this->logger->addInfo(sprintf('FFmpeg opens %s', $pathfile));
$this->pathfile = $pathfile;
foreach ($this->helpers as $helper) {
$helper->open($pathfile);
}
return $this;
}
@ -135,7 +162,7 @@ class FFMpeg extends Binary
$this->logger->addInfo(sprintf('FFmpeg executes command %s', $process->getCommandline()));
try {
$process->run();
$process->run(array($this, 'transcodeCallback'));
} catch (\RuntimeException $e) {
}
@ -218,7 +245,7 @@ class FFMpeg extends Binary
$this->logger->addInfo(sprintf('FFmpeg executes command %s', $process->getCommandLine()));
try {
$process->run();
$process->run(array($this, 'transcodeCallback'));
} catch (\RuntimeException $e) {
}
@ -344,7 +371,7 @@ class FFMpeg extends Binary
$this->logger->addInfo(sprintf('FFmpeg executes command %s', $process->getCommandline()));
try {
$process->run();
$process->run(array($this, 'transcodeCallback'));
} catch (\RuntimeException $e) {
break;
}
@ -365,6 +392,19 @@ class FFMpeg extends Binary
return $this;
}
/**
* The main transcoding callback, delegates the content to the helpers.
*
* @param string $channel (stdio|stderr)
* @param string $content the current line of the ffmpeg output
*/
public function transcodeCallback($channel, $content)
{
foreach ($this->helpers as $helper) {
$helper->transcodeCallback($channel, $content);
}
}
/**
* Removes unnecessary file
*