Exemple #1
0
 public function mp4_to_ogv($VideoTask)
 {
     $this->create();
     $this->id = $VideoTask['VideoTask']['id'];
     $this->save(array("task_status" => "working"));
     //import objects
     $MediaFile = ClassRegistry::init("MediaFile");
     App::import("Vendor", "LLFTP", array("LLFTP.php"));
     $video = $MediaFile->find("first", array("conditions" => array("MediaFile.id" => $VideoTask['VideoTask']['foreign_key']), "contain" => array()));
     $llftp = new LLFTP();
     //let's download the video to tmp
     $tmp_file = $MediaFile->downloadVideoToTmp($VideoTask['VideoTask']['foreign_key']);
     $this->query("SET SESSION wait_timeout = 28800");
     $newFileName = str_replace(".mp4", ".ogv", $video['MediaFile']['limelight_file']);
     $newFilePath = "/home/sites/tmpfiles/" . $newFileName;
     $cmd = "/usr/bin/ffmpeg2theora {$tmp_file} -o {$newFilePath} --audioquality 5";
     SysMsg::add(array("category" => "Mp4ToOgv", "from" => "VideoTask", "crontab" => 1, "title" => $cmd));
     $this->getDatasource()->disconnect();
     $MediaFile->getDatasource()->disconnect();
     $output = `{$cmd}`;
     $this->getDatasource()->connect();
     $MediaFile->getDatasource()->connect();
     //ftp the file
     $llftp->ftpFile($newFileName, $newFilePath);
     //update the video file
     $MediaFile->create();
     $MediaFile->id = $video['MediaFile']['id'];
     $MediaFile->save(array("limelight_file_ogv" => $newFileName));
     $this->create();
     $this->id = $VideoTask['VideoTask']['id'];
     $this->save(array("task_status" => "completed"));
 }
 public function handle_upload_video_modal()
 {
     if (!is_uploaded_file($this->request->data['MediaFile']['video_file']['tmp_name'])) {
         throw new BadRequestException("Nothing posting in!");
     }
     $file = $this->request->data['MediaFile']['video_file'];
     $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
     $tmp_name = md5(time()) . "." . $ext;
     if (move_uploaded_file($file['tmp_name'], TMP . "uploads/" . $tmp_name)) {
         $udata = array();
         $this->MediaFile->create();
         if (isset($this->request->data['MediaFile']['id'])) {
             $this->MediaFile->id = $this->request->data['MediaFile']['id'];
         } else {
             $udata['media_type'] = "bcove";
             $udata['preroll_label'] = "VPRE001";
             $this->MediaFile->save($udata);
         }
         $id = $this->MediaFile->id;
         $file_name = $id . "." . $ext;
         //run qt fast start
         $full_tmp_path = TMP . "uploads/" . $tmp_name;
         `qtfaststart {$full_tmp_path}`;
         App::import("Vendor", "LLFTP", array("file" => "LLFTP.php"));
         $ll = new LLFTP();
         //transfer file to limelight
         $result = $ll->ftpFile($file_name, TMP . "uploads/" . $tmp_name);
         unlink(TMP . "uploads/" . $tmp_name);
         $udata['limelight_file'] = $file_name;
         if ($this->request->data['MediaFile']['name']) {
             $udata['name'] = $this->request->data['MediaFile']['name'];
         }
         $udata['website_id'] = $this->request->data['MediaFile']['website_id'];
         $this->MediaFile->create();
         $this->MediaFile->id = $id;
         $this->MediaFile->save($udata);
         $this->encode_ogv($id);
         //$this->queue_mobile($id);
         $this->Session->setFlash('File uploaded successfully');
         die(json_encode($this->MediaFile->read()));
     }
 }