Add accurate option to FFMpeg::extractImage method.

This commit is contained in:
Romain Neutron 2012-12-13 13:03:55 +01:00
commit a8945f7d4d
2 changed files with 26 additions and 9 deletions

View file

@ -1,10 +1,11 @@
CHANGELOG
---------
* 0.2.x
* 0.2.0
* Add HelperInterface and support for realtime progress ( @pulse00 )
* Add HelperInterface and support for realtime progress ( @pulse00 ).
* Add `accurate` option to `FFMpeg::extractImage` method.
* 0.1.0 (30-10-2012)
* First stable version
* First stable version.

View file

@ -143,25 +143,41 @@ class FFMpeg extends Binary
/**
* Extract an image from a media file
*
* @param integer $time The time in second where to take the snapshot
* @param string $output The pathfile where to write
* @param integer|string $time The time where to take the snapshot, time could either be in second or in hh:mm:ss[.xxx] form.
* @param string $output The pathfile where to write
* @param Boolean $accurate Whether to decode the whole video until position or seek and extract. See -ss option in FFMpeg manual (http://ffmpeg.org/ffmpeg.html#Main-options)
*
* @return \FFMpeg\FFMpeg
*
* @throws RuntimeException
* @throws LogicException
*/
public function extractImage($time, $output)
public function extractImage($time, $output, $accurate = false)
{
if (!$this->pathfile) {
throw new LogicException('No file open');
}
$builder = ProcessBuilder::create(array(
/**
* @see http://ffmpeg.org/ffmpeg.html#Main-options
*/
if ($accurate) {
$options = array(
$this->binary, '-ss', $time,
'-i', $this->pathfile,
'-vframes', '1',
'-f', 'image2', $output
);
} else {
$options = array(
$this->binary,
'-i', $this->pathfile,
'-vframes', '1', '-ss', $time,
'-f', 'image2', $output
));
);
}
$builder = ProcessBuilder::create($options);
$process = $builder->getProcess();
$this->logger->addInfo(sprintf('FFmpeg executes command %s', $process->getCommandline()));