示例#1
0
 /**
  * Converts the video of one format to the other format. Tested for outfile --> "*.mp4"
  * @param  string $extension Extension of the final converted video
  * @param  string $inFile    Input File (Full path)
  * @param  string $outFile   Output File (full path)
  */
 public static function toVideo($extension, $inFile, $outFile)
 {
     if (in_array($extension, self::$_supportedFormats['video'])) {
         if (Video::getExtension($inFile) === $extension) {
             copy($inFile, $outFile);
             return true;
         }
         $cmd = 'ffmpeg -i ' . $inFile . ' -acodec libmp3lame -ar 44100 ' . $outFile;
         exec($cmd, $output, $return);
         if ($return !== 0) {
             throw new Core("Unable to convert the file!!");
         }
     } else {
         throw new Argument('Unsupported $extension argument');
     }
 }
示例#2
0
 /**
  * Converts the video to given format
  */
 public function convert($fmt = "mp3", $opts = [])
 {
     Regex::validate(array('extension' => $fmt));
     $filename = $this->_videoId . ".{$fmt}";
     $this->_converted = self::$_location . $filename;
     if (!file_exists($this->_converted)) {
         $type = isset($opts['type']) ? $opts['type'] : 'audio';
         switch ($type) {
             case 'audio':
                 if ($this->bestMp3 !== -1) {
                     $code = $this->bestMp3;
                     $ext = "mp4";
                 } else {
                     $code = 251;
                     $ext = "webm";
                 }
                 $this->_download($code, $ext);
                 Convert::toAudio($fmt, $this->_file, $this->_converted);
                 break;
             case 'video':
                 $quality = isset($opts['quality']) ? $opts['quality'] : '360p';
                 $qInfo = Video::getQualities();
                 if (!array_key_exists($quality, $qInfo)) {
                     var_dump($qInfo);
                     var_dump($quality);
                     throw new Argument('Invalid Video quality supplied');
                 }
                 $arr = $qInfo[$quality];
                 $this->_download($arr['code'], $arr['ext']);
                 Convert::toVideo($fmt, $this->_file, $this->_converted);
                 break;
         }
         unlink($this->_file);
         // remove the video used for converting
     }
     if (isset($opts['fullPath'])) {
         return $this->_converted;
     }
     return $filename;
 }