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, ''); }
public function testAddFiltersAddsAFilter() { $driver = $this->getFFMpegDriverMock(); $ffprobe = $this->getFFProbeMock(); $timecode = $this->getTimeCodeMock(); $filters = $this->getMockBuilder('FFMpeg\\Filters\\FiltersCollection')->disableOriginalConstructor()->getMock(); $filter = $this->getMock('FFMpeg\\Filters\\Frame\\FrameFilterInterface'); $filters->expects($this->once())->method('add')->with($filter); $frame = new Frame($this->getVideoMock(__FILE__), $driver, $ffprobe, $timecode); $frame->setFiltersCollection($filters); $frame->addFilter($filter); }
/** * {@inheritdoc} */ public function apply(Frame $frame) { $dimensions = null; $commands = array(); foreach ($frame->getVideo()->getStreams() as $stream) { if ($stream->isVideo()) { try { $dimensions = $stream->getDimensions(); $commands[] = '-s'; $commands[] = $dimensions->getWidth() . 'x' . $dimensions->getHeight(); break; } catch (RuntimeException $e) { } } } return $commands; }
/** * @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); }