Sulu\Bundle\MediaBundle\Media\Video\VideoThumbnailService::generate PHP Method

generate() public method

public generate ( $file, $time, $destination )
    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);
    }

Usage Example

 public function testGenerate()
 {
     $timecode = TimeCode::fromString('00:00:00:01');
     $this->ffmpeg->open('1.mp4')->willReturn($this->video->reveal())->shouldBeCalled();
     $this->video->frame($timecode)->willReturn($this->frame->reveal())->shouldBeCalled();
     $this->frame->save('1.jpg')->shouldBeCalled();
     $this->videoThumbnailService->generate('1.mp4', '00:00:00:01', '1.jpg');
 }