/** * 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 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); }
public function testGetFirstUrlPic() { // SERIES SECTION $series = $this->factoryService->createSeries(); $absolute = false; $this->assertEquals($this->defaultSeriesPic, $this->picService->getFirstUrlPic($series, $absolute)); $absolute = true; $this->assertEquals($this->localhost . $this->defaultSeriesPic, $this->picService->getFirstUrlPic($series, $absolute)); $seriesUrl1 = '/uploads/series1.jpg'; $seriesPic1 = new Pic(); $seriesPic1->setUrl($seriesUrl1); $series->addPic($seriesPic1); $this->dm->persist($series); $this->dm->flush(); $this->assertEquals($seriesUrl1, $this->picService->getFirstUrlPic($series)); $seriesUrl2 = '/uploads/series2.jpg'; $seriesPic2 = new Pic(); $seriesPic2->setUrl($seriesUrl2); $series->addPic($seriesPic2); $this->dm->persist($series); $series->upPicById($seriesPic2->getId()); $this->dm->persist($series); $this->dm->flush(); $this->assertEquals($seriesUrl2, $this->picService->getFirstUrlPic($series)); // MULTIMEDIA OBJECT SECTION // Workaround for detached Series document $this->dm->clear(get_class($series)); $series = $this->dm->find('PumukitSchemaBundle:Series', $series->getId()); $mm = $this->factoryService->createMultimediaObject($series); $mm->setSeries($series); $this->dm->persist($mm); $this->dm->flush(); $track = new Track(); $track->setOnlyAudio(false); $mm->addTrack($track); $this->dm->persist($mm); $this->dm->flush(); $absolute = false; $this->assertEquals($this->defaultVideoPic, $this->picService->getFirstUrlPic($mm, $absolute)); $absolute = true; $this->assertEquals($this->localhost . $this->defaultVideoPic, $this->picService->getFirstUrlPic($mm, $absolute)); $track->setOnlyAudio(true); $this->dm->persist($mm); $this->dm->flush(); $absolute = false; $hd = true; $this->assertEquals($this->defaultAudioHDPic, $this->picService->getFirstUrlPic($mm, $absolute, $hd)); $hd = false; $this->assertEquals($this->defaultAudioSDPic, $this->picService->getFirstUrlPic($mm, $absolute, $hd)); $absolute = true; $hd = true; $this->assertEquals($this->localhost . $this->defaultAudioHDPic, $this->picService->getFirstUrlPic($mm, $absolute, $hd)); $hd = false; $this->assertEquals($this->localhost . $this->defaultAudioSDPic, $this->picService->getFirstUrlPic($mm, $absolute, $hd)); $mmUrl1 = '/uploads/video1.jpg'; $mmPic1 = new Pic(); $mmPic1->setUrl($mmUrl1); $mm->addPic($mmPic1); $this->dm->persist($mm); $this->dm->flush(); $this->assertEquals($mmUrl1, $this->picService->getFirstUrlPic($mm)); $absolute = true; $this->assertEquals($this->localhost . $mmUrl1, $this->picService->getFirstUrlPic($mm, $absolute)); $mmUrl2 = '/uploads/video2.jpg'; $mmPic2 = new Pic(); $mmPic2->setUrl($mmUrl2); $mm->addPic($mmPic2); $this->dm->persist($mm); $mm->upPicById($mmPic2->getId()); $this->dm->persist($mm); $this->dm->flush(); $this->assertEquals($mmUrl2, $this->picService->getFirstUrlPic($mm)); $absolute = true; $this->assertEquals($this->localhost . $mmUrl2, $this->picService->getFirstUrlPic($mm, $absolute)); }
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))); }
public function testGenerateJobsForAudio() { $track = new Track(); $track->addTag("master"); $track->setPath("path"); $track->setOnlyAudio(true); $mmobj = new MultimediaObject(); $mmobj->addTrack($track); $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGA')); $this->assertEquals(array('audio'), $jobs); $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGC')); $this->assertEquals(array('audio', 'audio2'), $jobs); $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGB')); $this->assertEquals(array('audio2'), $jobs); //generate a video2 from an audio has no sense. $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGP')); $this->assertEquals(array(), $jobs); //generate a video from an audio has no sense. $jobs = $this->invokeMethod($this->jobGeneratorListener, 'generateJobs', array($mmobj, 'TAGFP')); $this->assertEquals(array(), $jobs); //generate a video from an audio has no sense. }
public function testIsOnlyAudio() { $t1 = new Track(); $t1->setOnlyAudio(true); $this->assertTrue($t1->isOnlyAudio()); $t1->setOnlyAudio(false); $this->assertFalse($t1->isOnlyAudio()); }
public function importRecording($opencastId, $invert = false) { $mediaPackage = $this->opencastClient->getMediaPackage($opencastId); $seriesRepo = $this->dm->getRepository('PumukitSchemaBundle:Series'); if (isset($mediaPackage["series"])) { $series = $seriesRepo->findOneBy(array("properties.opencast" => $mediaPackage["series"])); } else { $series = $seriesRepo->findOneBy(array("properties.opencast" => "default")); } if (!$series) { $series = $this->importSeries($mediaPackage); } $multimediaobjectsRepo = $this->dm->getRepository('PumukitSchemaBundle:MultimediaObject'); $onemultimediaobjects = $multimediaobjectsRepo->findOneBy(array("properties.opencast" => $mediaPackage["id"])); if ($onemultimediaobjects == null) { $title = $mediaPackage["title"]; $properties = $mediaPackage["id"]; $recDate = $mediaPackage["start"]; $multimediaObject = $this->factoryService->createMultimediaObject($series); $multimediaObject->setSeries($series); $multimediaObject->setRecordDate($recDate); $multimediaObject->setProperty("opencast", $properties); $multimediaObject->setProperty("opencastinvert", boolval($invert)); $multimediaObject->setProperty("opencasturl", $this->opencastClient->getPlayerUrl() . "?id=" . $properties); $multimediaObject->setTitle($title); if (isset($mediaPackage["language"])) { $multimediaObject->setProperty("opencastlanguage", strtolower($mediaPackage["language"])); } else { $multimediaObject->setProperty("opencastlanguage", 'en'); } foreach ($this->otherLocales as $locale) { $multimediaObject->setTitle($title, $locale); } //Multiple tracks if (isset($mediaPackage["media"]["track"][0])) { for ($i = 0; $i < count($mediaPackage["media"]["track"]); $i++) { $tags = $mediaPackage["media"]["track"][$i]["tags"]; $url = $mediaPackage["media"]["track"][$i]["url"]; $mime = $mediaPackage["media"]["track"][$i]["mimetype"]; $duration = $mediaPackage["media"]["track"][$i]["duration"]; $track = new Track(); if (isset($mediapackage["media"]["track"][$i]["audio"])) { $acodec = $mediaPackage["media"]["track"][$i]["audio"]["encoder"]["type"]; $track->setAcodec($acodec); } if (isset($mediaPackage["language"])) { $track->setLanguage(strtolower($mediaPackage["language"])); } if (isset($mediaPackage["media"]["track"][$i]["video"])) { $vcodec = $mediaPackage["media"]["track"][$i]["video"]["encoder"]["type"]; $track->setVcodec($vcodec); $framerate = $mediaPackage["media"]["track"][$i]["video"]["framerate"]; $track->setFramerate($framerate); } if (!$track->getVcodec() && $track->getAcodec()) { $track->setOnlyAudio(true); } $track->addTag("opencast"); $track->addTag($mediaPackage["media"]["track"][$i]["type"]); $track->setUrl($url); $track->setPath($this->opencastService->getPath($url)); $track->setMimeType($mime); $track->setDuration($duration / 1000); $this->inspectionService->autocompleteTrack($track); $multimediaObject->setDuration($track->getDuration()); $multimediaObject->addTrack($track); } } else { $tags = $mediaPackage["media"]["track"]["tags"]; $url = $mediaPackage["media"]["track"]["url"]; $mime = $mediaPackage["media"]["track"]["mimetype"]; $duration = $mediaPackage["media"]["track"]["duration"]; $track = new Track(); if (isset($mediapackage["media"]["track"]["audio"])) { $acodec = $mediaPackage["media"]["track"]["audio"]["encoder"]["type"]; $track->setAcodec($acodec); } if (isset($mediaPackage["media"]["track"]["video"])) { $vcodec = $mediaPackage["media"]["track"]["video"]["encoder"]["type"]; $track->setVcodec($vcodec); $framerate = $mediaPackage["media"]["track"]["video"]["framerate"]; $track->setFramerate($framerate); } if (!$track->getVcodec() && $track->getAcodec()) { $track->setOnlyAudio(true); } $track->addTag("opencast"); $track->addTag($mediaPackage["media"]["track"]["type"]); $track->setUrl($url); $track->setPath($this->opencastService->getPath($url)); $track->setMimeType($mime); $track->setDuration($duration / 1000); $this->inspectionService->autocompleteTrack($track); $multimediaObject->setDuration($track->getDuration()); $multimediaObject->addTrack($track); } for ($j = 0; $j < count($mediaPackage["attachments"]["attachment"]); $j++) { if (isset($mediaPackage["attachments"]["attachment"][$j]["type"])) { if ($mediaPackage["attachments"]["attachment"][$j]["type"] == "presenter/search+preview") { $tags = $mediaPackage["attachments"]["attachment"][$j]["tags"]; $url = $mediaPackage["attachments"]["attachment"][$j]["url"]; $pic = new Pic(); $pic->setTags(array($tags)); $pic->setUrl($url); $multimediaObject->addPic($pic); } } } $tagRepo = $this->dm->getRepository('PumukitSchemaBundle:Tag'); $opencastTag = $tagRepo->findOneByCod('TECHOPENCAST'); if ($opencastTag) { $tagService = $this->tagService; $tagAdded = $tagService->addTagToMultimediaObject($multimediaObject, $opencastTag->getId()); } $this->dm->persist($multimediaObject); $this->dm->flush(); if ($track) { $opencastUrls = $this->getOpencastUrls($opencastId); $this->opencastService->genSbs($multimediaObject, $opencastUrls); } } }
public function testIsOnlyAudio() { $mm = new MultimediaObject(); $t1 = new Track(); $t1->setOnlyAudio(true); $t2 = new Track(); $t2->setOnlyAudio(true); $t3 = new Track(); $t3->setOnlyAudio(true); $t4 = new Track(); $t4->setOnlyAudio(true); $t5 = new Track(); $t5->setOnlyAudio(true); $mm->addTrack($t3); $mm->addTrack($t2); $mm->addTrack($t1); $mm->addTrack($t4); $mm->addTrack($t5); $this->assertTrue($mm->isOnlyAudio()); $t5->setOnlyAudio(false); $this->assertFalse($mm->isOnlyAudio()); }