コード例 #1
0
 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, '');
 }
コード例 #2
0
ファイル: VideoThumbnailService.php プロジェクト: sulu/sulu
 /**
  * {@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);
 }
コード例 #3
0
ファイル: MediaService.php プロジェクト: CarsonF/WhatsApi
 /**
  * @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;
     }
 }
コード例 #4
0
 /**
  * @expectedException FFMpeg\Exception\InvalidArgumentException
  */
 public function testFromInvalidString()
 {
     TimeCode::fromString('lalali lala');
 }