/**
  * Completes track information from a given path using mediainfo.
  * @param Track $track
  */
 public function autocompleteTrack(Track $track)
 {
     $only_audio = true;
     //initialized true until video track is found.
     if (!$track->getPath()) {
         throw new \BadMethodCallException('Input track has no path defined');
     }
     $xml = simplexml_load_string($this->getMediaInfo($track->getPath()));
     if (!$this->xmlHasMediaContent($xml)) {
         throw new \InvalidArgumentException("This file has no accesible video " . "nor audio tracks\n" . $track->getPath());
     }
     foreach ($xml->File->track as $xml_track) {
         switch ((string) $xml_track['type']) {
             case "General":
                 $track->setMimetype($xml_track->Internet_media_type);
                 $track->setBitrate(intval($xml_track->Overall_bit_rate[0]));
                 $aux = intval((string) $xml_track->Duration[0]);
                 $track->setDuration(ceil($aux / 1000));
                 $track->setSize((string) $xml_track->File_size[0]);
                 break;
             case "Video":
                 $track->setVcodec((string) $xml_track->Format[0]);
                 $track->setFramerate((string) $xml_track->Frame_rate[0]);
                 $track->setWidth(intval($xml_track->Width));
                 $track->setHeight(intval($xml_track->Height));
                 $only_audio = false;
                 break;
             case "Audio":
                 $track->setAcodec((string) $xml_track->Format[0]);
                 $track->setChannels(intval($xml_track->Channel_s_));
                 break;
         }
         $track->setOnlyAudio($only_audio);
     }
 }
 /**
  * Completes track information from a given path using ffmpeg.
  * @param Track $track
  */
 public function autocompleteTrack(Track $track)
 {
     if (!$track->getPath()) {
         throw new \BadMethodCallException('Input track has no path defined');
     }
     $file = $track->getPath();
     $movie = new \ffmpeg_movie($file, false);
     $finfo = new \finfo();
     if (!$this->fileHasMediaContent($finfo, $file)) {
         throw new \InvalidArgumentException("This file has no video nor audio tracks");
     }
     $only_audio = true;
     // General
     $track->setMimetype($finfo->file($file, FILEINFO_MIME_TYPE));
     $track->setBitrate($movie->getBitRate());
     $track->setDuration(ceil($movie->getDuration()));
     $track->setSize(filesize($file));
     if ($movie->hasVideo()) {
         $only_audio = false;
         $track->setVcodec($movie->getVideoCodec());
         $track->setFramerate($movie->getFrameRate());
         $track->setWidth($movie->getFrameWidth());
         $track->setHeight($movie->getFrameHeight());
     }
     if ($movie->hasAudio()) {
         $track->setAcodec($movie->getAudioCodec());
         $track->setChannels($movie->getAudioChannels());
     }
     $track->setOnlyAudio($only_audio);
 }
 /**
  * Completes track information from a given path using mediainfo.
  * @param Track $track
  */
 public function autocompleteTrack(Track $track)
 {
     $only_audio = true;
     //initialized true until video track is found.
     if (!$track->getPath()) {
         throw new \BadMethodCallException('Input track has no path defined');
     }
     $json = json_decode($this->getMediaInfo($track->getPath()));
     if (!$this->jsonHasMediaContent($json)) {
         throw new \InvalidArgumentException("This file has no accesible video " . "nor audio tracks\n" . $track->getPath());
     }
     $track->setMimetype(mime_content_type($track->getPath()));
     $track->setBitrate(intval($json->format->bit_rate));
     $aux = intval((string) $json->format->duration);
     $track->setDuration(ceil($aux));
     $track->setSize((string) $json->format->size);
     foreach ($json->streams as $stream) {
         switch ((string) $stream->codec_type) {
             case "video":
                 $track->setVcodec((string) $stream->codec_name);
                 $track->setFramerate((string) $stream->avg_frame_rate);
                 $track->setWidth(intval($stream->width));
                 $track->setHeight(intval($stream->height));
                 $only_audio = false;
                 break;
             case "audio":
                 $track->setAcodec((string) $stream->codec_name);
                 $track->setChannels(intval($stream->channels));
                 break;
         }
         $track->setOnlyAudio($only_audio);
     }
 }
Пример #4
0
 public function testMaxSize()
 {
     $size = 5368709120;
     // 5GB, integer types in 32 bits machines only admit 2GB
     $track = new Track();
     $track->setSize($size);
     $this->assertEquals($size, $track->getSize());
 }