/**
  * 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 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);
     }
 }
 /**
  * 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);
 }
Esempio n. 4
0
 public function testGetterAndSetter()
 {
     $tags = array('tag_a', 'tag_b');
     $language = 'portuñol';
     $url = '/mnt/video/123/23435.mp4';
     $path = '/mnt/video/123/23435.mp4';
     $mime = 'video/mpeg4';
     $duration = 3456;
     $acodec = 'aac';
     $vcodec = 'mpeg4-HP';
     $bitrate = 10000;
     $framerate = '25/1';
     $only_audio = false;
     $channels = 1;
     $duration = 66666;
     $width = 1920;
     $height = 1080;
     $hide = false;
     $numview = 3;
     $resolution = array('width' => $width, 'height' => $height);
     $track = new Track();
     $track->setTags($tags);
     $track->setLanguage($language);
     $track->setUrl($url);
     $track->setPath($path);
     $track->setMimeType($mime);
     $track->setDuration($duration);
     $track->setAcodec($acodec);
     $track->setVcodec($vcodec);
     $track->setBitrate($bitrate);
     $track->setFramerate($framerate);
     $track->setOnlyAudio($only_audio);
     $track->setChannels($channels);
     $track->setDuration($duration);
     $track->setWidth($width);
     $track->setHeight($height);
     $track->setHide($hide);
     $track->setNumview($numview);
     $track->setResolution($resolution);
     $this->assertEquals($tags, $track->getTags());
     $this->assertEquals($language, $track->getLanguage());
     $this->assertEquals($url, $track->getUrl());
     $this->assertEquals($path, $track->getPath());
     $this->assertEquals($mime, $track->getMimeType());
     $this->assertEquals($duration, $track->getDuration());
     $this->assertEquals($acodec, $track->getAcodec());
     $this->assertEquals($vcodec, $track->getVcodec());
     $this->assertEquals($bitrate, $track->getBitrate());
     $this->assertEquals($framerate, $track->getFramerate());
     $this->assertFalse($only_audio, $track->getOnlyAudio());
     $this->assertEquals($channels, $track->getChannels());
     $this->assertEquals($duration, $track->getDuration());
     $this->assertEquals($width, $track->getWidth());
     $this->assertEquals($height, $track->getHeight());
     $this->assertFalse($hide, $track->getHide());
     $this->assertEquals($numview, $track->getNumview());
     $this->assertEquals($resolution, $track->getResolution());
 }
 public function testGenerateJobsForHDVideo()
 {
     $track = new Track();
     $track->addTag("master");
     $track->setPath("path");
     $track->setOnlyAudio(false);
     $track->setWidth(1280);
     $track->setHeight(720);
     $mmobj = new MultimediaObject();
     $mmobj->addTrack($track);
     $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGA'));
     $this->assertEquals(array('video'), $jobs);
     $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGC'));
     $this->assertEquals(array('video', 'video2'), $jobs);
     $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGB'));
     $this->assertEquals(array('video2', 'audio2'), $jobs);
     $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGP'));
     $this->assertEquals(array('videoHD'), $jobs);
     $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGFP'));
     $this->assertEquals(array('videoSD', 'videoHD'), $jobs);
 }
 public function testPicExtractorAudioError()
 {
     // TODO: Remove this line when adding final default audio image
     $this->markTestSkipped('S');
     $mmsPicService = $this->getMockBuilder('Pumukit\\SchemaBundle\\Services\\MultimediaObjectPicService')->disableOriginalConstructor()->getMock();
     $mmsPicService->expects($this->any())->method('addPicFile')->will($this->returnValue(null));
     $picExtractorService = $this->getMockBuilder('Pumukit\\EncoderBundle\\Services\\PicExtractorService')->disableOriginalConstructor()->getMock();
     $picExtractorService->expects($this->any())->method('extractPic')->will($this->returnValue('success'));
     $picExtractorListener = new PicExtractorListener($this->dm, $mmsPicService, $picExtractorService, $this->logger, $this->autoExtractPic);
     $series = $this->factoryService->createSeries();
     $mm = $this->factoryService->createMultimediaObject($series);
     $track = new Track();
     $track->addTag("master");
     $track->setPath($this->videoPath);
     $track->setOnlyAudio(true);
     $track->setWidth(640);
     $track->setHeight(480);
     $mm->addTrack($track);
     $this->dm->persist($mm);
     $this->dm->flush();
     $this->assertTrue($mm->getPics()->isEmpty());
     $this->assertEquals(0, count($mm->getPics()->toArray()));
     $this->assertFalse($this->invokeMethod($picExtractorListener, 'generatePic', array($mm, $track)));
 }