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()); } }
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; }