Created by
Krzysztof Ożóg
| <?php
protected function createThumbnails($video, $videoDir)
{
$thumbsDir = $videoDir.'/thumbs/';
if (!file_exists($thumbsDir) ) {
mkdir($thumbsDir);
chmod($thumbsDir, 0777);
}
$ffmpeg = $this->getFFMpeg();
$ffprobe = $this->getFFProbe();
$ffmpeg = $ffmpeg->open($videoDir.'/'.$video->getOriginal());
$duration = $video->getDuration();
$step = floor($duration/12);
for ($i=1; $i < 13; ++$i) {
$ffmpeg->extractImage($i*$step, $thumbsDir.$i.'.jpg');
}
$ffmpeg->close();
$this->createSprite($video, $thumbsDir);
}
protected function createSprite($video, $thumbsDir)
{
$imagine = new \Imagine\Gd\Imagine();
$image = $imagine->create(
new \Imagine\Image\Box(200*12, 150)
);
for ($i=1; $i < 13; ++$i) {
$thumb = $imagine->open($thumbsDir.'/'.$i.'.jpg');
$thumb->resize(new \Imagine\Image\Box(200, 150));
$image->paste($thumb, new \Imagine\Image\Point(($i-1)*200, 0));
}
$image->save($thumbsDir.'/../sprite.jpg');
}
|