public function testBatchGenerate() { $times = ['00:00:00:01', '00:00:00:11', '00:00:00:21']; foreach ($times as $time) { $timecode = TimeCode::fromString($time); $this->ffmpeg->open('1.mp4')->willReturn($this->video->reveal())->shouldBeCalled(); $this->video->frame($timecode)->willReturn($this->frame->reveal())->shouldBeCalled(); $this->frame->save(str_replace(':', '.', '/' . $time . '.jpg'))->shouldBeCalled(); } $this->videoThumbnailService->batchGenerate('1.mp4', $times, ''); }
/** * {@inheritdoc} */ public function generate($file, $time, $destination) { $destination = $this->normalizeFilename($destination); try { $video = $this->ffmpeg->open($file); $timecode = TimeCode::fromString($time); $frame = $video->frame($timecode); $frame->save($destination); } catch (InvalidArgumentException $e) { // there will be no image file - so nothing to do here } return file_exists($destination); }
/** * @param string $file * @param int $size * @return null|string */ public function createVideoIcon($file, $size = 100) { if (!class_exists('FFMpeg\\FFMpeg')) { return null; } try { $preview = tempnam(sys_get_temp_dir(), 'preview-'); $ffmpeg = FFMpeg::create(); $video = $ffmpeg->open($file); $frame = $video->frame(TimeCode::fromString('0:0:0:0.0')); $frame->save($preview); $content = $this->createImageIcon($preview, $size); @unlink($preview); return $content; } catch (\Exception $e) { return null; } }
/** * @expectedException FFMpeg\Exception\InvalidArgumentException */ public function testFromInvalidString() { TimeCode::fromString('lalali lala'); }