Esempio n. 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());
     }
 }
Esempio n. 2
0
 /**
  * rote pattern example:
  * GiiyModule::$pixUrl.'/resize/<id1:\d+>/<id2:\d+>/<width:\d+>x<height:\d+>.<type:\w+>' => 'giiy/giiyResize/resize'
  *
  * @param $id1
  * @param $id2
  * @param $width
  * @param $height
  * @param $type
  * @throws CHttpException
  */
 public function actionResize($id1, $id2, $width, $height, $type)
 {
     $id = $id1 * 1000 + $id2;
     /** @var GiiyPicture $picture */
     $picture = GiiyPicture::model()->findByPk($id);
     if (!$picture) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     if ($picture->resize($width, $height) !== null) {
         header("Content-type: " . $picture->getType()->getMime());
         echo file_get_contents($picture->getResizePath($width, $height));
         exit;
     }
     throw new CHttpException(404, 'The requested page does not exist.');
 }