示例#1
0
 public function setFile($path)
 {
     $finfo = new finfo(FILEINFO_MIME_TYPE);
     $mime = $finfo->file($path);
     if (!in_array($mime, GiiyVideoTypeEnum::$mime)) {
         throw new CException('wrong video file');
     }
     $movie = new FFmpegMovie($path);
     $this->type = GiiyVideoTypeEnum::createByMime($mime);
     if ($this->type->id != GiiyVideoTypeEnum::FLV) {
         $movie->convertToFLV();
         $this->type = new GiiyVideoTypeEnum(GiiyVideoTypeEnum::FLV);
         $movie = new FFmpegMovie($path);
     }
     $this->width = $movie->getFrameWidth();
     $this->height = $movie->getFrameHeight();
     $this->duration = $movie->getDuration();
     $this->bit_rate = $movie->getVideoBitRate();
     $this->codec = $movie->getVideoCodec();
     try {
         $gd = $movie->getFrameAtTime($this->duration / 2)->toGDImage();
         $tmpFile = TMP_PATH . DIRECTORY_SEPARATOR . uniqid('video_');
         imagepng($gd, $tmpFile);
         $preview = new GiiyPicture();
         $preview->name = 'video preview for ' . $this->name;
         $preview->setFile($tmpFile);
         $preview->save();
         $this->picture = $preview;
         unlink($tmpFile);
     } catch (Exception $e) {
     }
     if (!$this->id) {
         $this->_tmpPath = $path;
     } elseif ($path != $this->getPath()) {
         copy($path, $this->getPath());
     }
 }
示例#2
0
 /**
  * Create a video thumbnail
  *
  * @param integer $id Attachment Id
  * @param integer $w New Width
  * @param integer $h New Height
  * @param array $options Options array
  */
 public function createVideoThumbnail($id, $w, $h, $options = array())
 {
     if (!class_exists('FFmpegMovie')) {
         throw new RunTimeException('FFmpegMovie class not found');
     }
     $this->recursive = -1;
     $this->contain(array('AssetsAsset'));
     $attachment = $this->findById($id);
     $asset =& $attachment['AssetsAsset'];
     $path = rtrim(WWW_ROOT, '/') . $asset['path'];
     $info = pathinfo($asset['path']);
     $ind = sprintf('.resized-%dx%d.', $w, $h);
     $uploadsDir = str_replace('/' . $options['uploadsDir'] . '/', '', dirname($asset['path'])) . '/';
     $filename = $info['filename'] . $ind . 'jpg';
     $writePath = WWW_ROOT . 'galleries' . DS . $uploadsDir . $filename;
     $ffmpeg = new FFmpegMovie($path, null, 'avconv');
     $frame = $ffmpeg->getFrame(null, 200, 150);
     imagejpeg($frame->toGDImage(), $writePath, 100);
     $fp = fopen($writePath, 'r');
     $stat = fstat($fp);
     fclose($fp);
     $adapter = $asset['adapter'];
     $data = $this->AssetsAsset->create(array('filename' => $filename, 'path' => dirname($asset['path']) . '/' . $filename, 'model' => $asset['model'], 'extension' => $asset['extension'], 'parent_asset_id' => $asset['id'], 'foreign_key' => $asset['foreign_key'], 'adapter' => $adapter, 'mime_type' => $asset['mime_type'], 'width' => $newWidth, 'height' => $newHeight, 'filesize' => $stat[7]));
     $asset = $this->AssetsAsset->save($data);
     return $asset;
 }
示例#3
0
 private function _getMovieInfo()
 {
     $movieinfo = NULL;
     if (extension_loaded('ffmpeg') && false) {
         $movie = new ffmpeg_movie($this->tmpfile);
         $duration = $movie->getDuration();
         $movieinfo = array('duration' => $duration);
     } else {
         require_once FS_ROOT . 'include/ffmpeg/FFmpegAutoloader.php';
         $ffmpegOutput = new FFmpegOutputProvider(Core::config('ffmpeg_binary'));
         $ffmpeMovie = new FFmpegMovie($this->tmpfile, $ffmpegOutput, Core::config('ffmpeg_binary'));
         $duration = $ffmpeMovie->getDuration();
         $artist = $ffmpeMovie->getArtist();
         $rotate = $ffmpeMovie->getRotate();
         $movieinfo = array('duration' => $duration, 'artist' => $artist, 'orientation' => $rotate);
     }
     return $movieinfo;
 }