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

batchGenerate() public method

public batchGenerate ( $video, array $times, $destinationPath )
$times array
    public function batchGenerate($video, array $times, $destinationPath)
    {
        if ($this->ffmpeg !== null) {
            $failed = [];
            foreach ($times as $time) {
                $filename = $destinationPath . DIRECTORY_SEPARATOR . $time . '.jpg';
                $success = $this->generate($video, $time, $filename);
                if (!$success) {
                    $failed[] = $filename;
                }
            }
            return $failed;
        }
        return false;
    }

Usage Example

 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, '');
 }