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, ''); }
/** * @param Frame $frame * * @throws \Exception * @return \SplFileInfo */ public function getScreenshot(Frame $frame) { if (!file_exists($this->screenshotDirectory)) { mkdir($this->screenshotDirectory, 0777, true); } $file = tempnam($this->screenshotDirectory, 'ss_'); $file = rename($file, $file . '.png') ? $file . '.png' : $file; if ($file === false) { throw new \Exception("Could not create a file in: " . $this->screenshotDirectory); } try { @$frame->save($file, true); } catch (\Exception $e) { // Do nothing } chmod($file, 0777); return new \SplFileInfo($file); }