public static function GenerateSmoothStreamingPresetFile($flavors)
 {
     $rootFlavor = null;
     $rootStreams = null;
     foreach ($flavors as $flavor) {
         $ee3Id = KDLOperationParams::SearchInArray(KDLTranscoders::EE3, $flavor->_transcoders);
         if (is_null($ee3Id)) {
             continue;
         }
         $transcoderParams = $flavor->_transcoders[$ee3Id];
         KalturaLog::log("transcoder==>\n" . print_r($transcoderParams, true) . "\n<--");
         if (is_null($transcoderParams->_cmd)) {
             KalturaLog::log("ee3 cmd is null");
             continue;
         }
         $ee3 = new SimpleXMLElement($transcoderParams->_cmd);
         if (isset($ee3->MediaFile->OutputFormat->WindowsMediaOutputFormat->VideoProfile)) {
             $videoProfile = $ee3->MediaFile->OutputFormat->WindowsMediaOutputFormat->VideoProfile;
         } else {
             if (isset($ee3->MediaFile->OutputFormat->MP4OutputFormat->VideoProfile)) {
                 $videoProfile = $ee3->MediaFile->OutputFormat->MP4OutputFormat->VideoProfile;
             }
         }
         if (!isset($videoProfile)) {
             continue;
         }
         switch ($flavor->_video->_id) {
             case KDLVideoTarget::WVC1A:
                 $videoCodec = $videoProfile->AdvancedVC1VideoProfile;
                 break;
             case KDLVideoTarget::H264:
             case KDLVideoTarget::H264M:
             case KDLVideoTarget::H264H:
                 $videoCodec = $videoProfile->MainH264VideoProfile;
                 break;
             case KDLVideoTarget::H264B:
                 //					$videoCodec = $videoProfile->BaselineH264VideoProfile;
                 $videoCodec = $videoProfile->MainH264VideoProfile;
                 break;
             default:
                 continue;
         }
         if (!isset($videoCodec) || !isset($videoCodec['SmoothStreaming']) || $videoCodec['SmoothStreaming'] != 'true' && $videoCodec['SmoothStreaming'] != 'True') {
             continue;
         }
         $streams = $videoCodec->Streams;
         if (!(isset($streams) && isset($streams->StreamInfo))) {
             continue;
         }
         $flavorVideoBr = $flavor->_video->_bitRate;
         $br = $streams->StreamInfo->Bitrate;
         if (isset($br->ConstantBitrate)) {
             if ($br->ConstantBitrate['Bitrate'] != $flavorVideoBr) {
                 KalturaLog::log("-->xmlBR=" . $br->ConstantBitrate['Bitrate'] . ", flavorBR=" . $flavorVideoBr);
                 $br->ConstantBitrate['Bitrate'] = $flavorVideoBr;
             }
         } else {
             if (isset($br->VariableConstrainedBitrate)) {
                 if ($br->VariableConstrainedBitrate['AverageBitrate'] != $flavorVideoBr) {
                     KalturaLog::log("-->xmlBR=" . $br->VariableConstrainedBitrate['AverageBitrate'] . ", flavorBR=" . $flavorVideoBr);
                     $br->VariableConstrainedBitrate['AverageBitrate'] = $flavorVideoBr;
                     $br->VariableConstrainedBitrate['PeakBitrate'] = round($flavorVideoBr * 1.3);
                 }
             }
         }
         if ($rootFlavor == null) {
             $rootFlavor = $ee3;
             $rootStreams = $streams;
         } else {
             if ($streams && isset($streams->StreamInfo) && $rootStreams) {
                 KDLUtils::AddXMLElement($rootStreams, $streams->StreamInfo);
             }
         }
         $br = null;
     }
     if ($rootFlavor) {
         $rootFlavor->Job['DefaultMediaOutputFileName'] = KDLCmdlinePlaceholders::OutFileName . ".{DefaultExtension}";
         return $rootFlavor->asXML();
     } else {
         return null;
     }
 }
 public static function GenerateSmoothStreamingPresetFile($flavors)
 {
     /*
      * Filter in the flavors with EE operator
      */
     $flavorInColl = array();
     foreach ($flavors as $flavor) {
         $eeId = KDLOperationParams::SearchInArray(KDLTranscoders::EE3, $flavor->_transcoders);
         if (is_null($eeId)) {
             continue;
         }
         $transcoderParams = $flavor->_transcoders[$eeId];
         KalturaLog::log("transcoder==>\n" . print_r($transcoderParams, true) . "\n<--");
         if (is_null($transcoderParams->_cmd)) {
             KalturaLog::log("ee3 cmd is null");
             continue;
         }
         /*
          * The key if this array will be combination of bitrate,hight and counter, 
          * in order to solve possible duplication issues and easy the flavor sorting from low to high - 
          * - vBr*100000+height*10+counter
          * The counter meant to solve cases (forced) were two (or more) flavors have both the same vr and height 
          */
         $k = $flavor->_video->_bitRate * 100000 + $flavor->_video->_height * 10;
         while (array_key_exists(strval($k), $flavorInColl)) {
             $k++;
         }
         $flavorInColl[$k] = $flavor;
     }
     /*
      * Sort the flavors that participate in collection 
      */
     $rv = ksort($flavorInColl);
     /*
      * Buidl a combined SmoothSteaming preset XML
      */
     $prevK = null;
     foreach ($flavorInColl as $k => $flavor) {
         /*
          * Check for IsmvMinimalFlavorRatio compliance,
          * fix if required.
          */
         if (isset($prevK)) {
             $ratio = $flavor->_video->_bitRate / $flavorInColl[$prevK]->_video->_bitRate;
             if ($ratio < KDLConstants::IsmvMinimalFlavorRatio) {
                 $flavor->_video->_bitRate = round($flavorInColl[$prevK]->_video->_bitRate * KDLConstants::IsmvMinimalFlavorRatio);
                 $flavor->_video->_peakBitRate = round($flavor->_video->_bitRate * KDLConstants::IsmvPeakBitrateRatio * 1.1);
             }
         }
         $prevK = $k;
     }
     /*
      * Sort the flavors that participate in collection - from high to low, to match EE4 constraints
      */
     $rv = krsort($flavorInColl);
     /*
      * Update the preset XML's and build combined XML
      */
     $rootFlavorXml = null;
     $rootStreamsXml = null;
     foreach ($flavorInColl as $k => $flavor) {
         $eeId = KDLOperationParams::SearchInArray(KDLTranscoders::EE3, $flavor->_transcoders);
         $transcoderParams = $flavor->_transcoders[$eeId];
         $presetXml = new SimpleXMLElement($transcoderParams->_cmd);
         $streamsXml = self::updateToCollectionPreset($flavor, $presetXml);
         if ($rootFlavorXml == null) {
             $rootFlavorXml = $presetXml;
             $rootStreamsXml = $streamsXml;
         } else {
             if ($streamsXml && isset($streamsXml->StreamInfo) && $rootStreamsXml) {
                 KDLUtils::AddXMLElement($rootStreamsXml, $streamsXml->StreamInfo);
             }
         }
     }
     if ($rootFlavorXml) {
         $rootFlavorXml->Job['DefaultMediaOutputFileName'] = KDLCmdlinePlaceholders::OutFileName . ".{DefaultExtension}";
         return $rootFlavorXml->asXML();
     } else {
         return null;
     }
 }
 public function GenerateConfigData(KDLFlavor $design, KDLFlavor $target, $extra = null)
 {
     /*		
     $tryXML = "<StreamInfo
                     Size=\"512, 384\">
                     <Bitrate>
                       <ConstantBitrate
                         Bitrate=\"1045\"
                         IsTwoPass=\"False\"
                         BufferWindow=\"00:00:05\" />
                     </Bitrate>
                   </StreamInfo>
     ";
     		$xml = new SimpleXMLElement($tryXML);
     */
     if ($target->_container) {
         $cont = $target->_container;
         $dir = dirname(__FILE__);
         //$dir = '.';
         switch ($cont->_id) {
             case KDLContainerTarget::ISMV:
                 $xmlTemplate = $dir . '/ismPresetTemplate.xml';
                 break;
             case KDLContainerTarget::MP4:
             case KDLContainerTarget::WMV:
             case KDLContainerTarget::WMA:
             default:
                 $xmlTemplate = $dir . '/wmvPresetTemplate.xml';
                 break;
         }
         $xml = simplexml_load_file(realpath($xmlTemplate));
         switch ($cont->_id) {
             case KDLContainerTarget::MP4:
                 $xObj = simplexml_load_string($xml->MediaFile->OutputFormat->WindowsMediaOutputFormat->asXML());
                 $xml->MediaFile->OutputFormat->addChild("MP4OutputFormat");
                 KDLUtils::AddXMLElement($xml->MediaFile->OutputFormat->MP4OutputFormat, $xObj->AudioProfile);
                 KDLUtils::AddXMLElement($xml->MediaFile->OutputFormat->MP4OutputFormat, $xObj->VideoProfile);
                 unset($xml->MediaFile->OutputFormat->WindowsMediaOutputFormat);
                 $fileFormat = $xml->MediaFile->OutputFormat->MP4OutputFormat;
                 break;
             case KDLContainerTarget::ISMV:
             case KDLContainerTarget::WMV:
             case KDLContainerTarget::WMA:
             default:
                 $fileFormat = $xml->MediaFile->OutputFormat->WindowsMediaOutputFormat;
                 break;
         }
     }
     $xml->Job['OutputDirectory'] = KDLCmdlinePlaceholders::OutDir;
     if ($target->_video) {
         $vid = $target->_video;
         $vidProfile = null;
         switch ($vid->_id) {
             case KDLVideoTarget::WMV2:
             case KDLVideoTarget::WMV3:
             case KDLVideoTarget::WVC1A:
             default:
                 $vidProfile = $fileFormat->VideoProfile->AdvancedVC1VideoProfile;
                 unset($fileFormat->VideoProfile->MainH264VideoProfile);
                 break;
             case KDLVideoTarget::H264:
             case KDLVideoTarget::H264B:
             case KDLVideoTarget::H264M:
             case KDLVideoTarget::H264H:
                 $vidProfile = $fileFormat->VideoProfile->MainH264VideoProfile;
                 unset($fileFormat->VideoProfile->AdvancedVC1VideoProfile);
                 break;
         }
         $vFr = 30;
         if ($vid->_frameRate !== null && $vid->_frameRate > 0) {
             $vFr = $vid->_frameRate;
             $vidProfile['FrameRate'] = $vFr;
         }
         if ($vid->_gop !== null && $vid->_gop > 0) {
             $kFr = round($vid->_gop / $vFr);
             $mi = round($kFr / 60);
             $se = $kFr % 60;
             $vidProfile['KeyFrameDistance'] = sprintf("00:%02d:%02d", $mi, $se);
         }
         if ($vid->_bitRate) {
             if ($target->_isTwoPass && !($vid->_id == KDLVideoTarget::H264 || $vid->_id == KDLVideoTarget::H264B || $vid->_id == KDLVideoTarget::H264M || $vid->_id == KDLVideoTarget::H264H)) {
                 unset($vidProfile->Streams->StreamInfo->Bitrate->VariableConstrainedBitrate);
                 $vidProfile->Streams->StreamInfo->Bitrate->ConstantBitrate['Bitrate'] = $vid->_bitRate;
             } else {
                 unset($vidProfile->Streams->StreamInfo->Bitrate->ConstantBitrate);
                 $vid->_bitRate = max(100, $vid->_bitRate);
                 // The minimum video br for the SL is 100
                 $vidProfile->Streams->StreamInfo->Bitrate->VariableConstrainedBitrate['PeakBitrate'] = round($vid->_bitRate * 1.3);
                 $vidProfile->Streams->StreamInfo->Bitrate->VariableConstrainedBitrate['AverageBitrate'] = $vid->_bitRate;
             }
         }
         if ($vid->_width != null && $vid->_height != null) {
             $vidProfile->Streams->StreamInfo['Size'] = $vid->_width . ", " . $vid->_height;
         }
         //			$strmInfo = clone ($vidProfile->Streams->StreamInfo[0]);
         //			KDLUtils::AddXMLElement($vidProfile->Streams, $vidProfile->Streams->StreamInfo[0]);
     } else {
         unset($fileFormat->VideoProfile);
     }
     if ($target->_audio) {
         $aud = $target->_audio;
         $audProfile = null;
         switch ($aud->_id) {
             case KDLAudioTarget::WMA:
             default:
                 $audProfile = $fileFormat->AudioProfile->WmaAudioProfile;
                 unset($fileFormat->AudioProfile->AacAudioProfile);
                 break;
             case KDLAudioTarget::AAC:
                 $audProfile = $fileFormat->AudioProfile->AacAudioProfile;
                 unset($fileFormat->AudioProfile->WmaAudioProfile);
                 break;
         }
         /*
         	Since there are certain constraints on those values for the EE3 presets, 
         	those values are set in the templates only
         	
         			if($this->_audBr!==null && $this->_audBr>0){
         				$audProfile->Bitrate->ConstantBitrate['Bitrate'] = $this->_audBr;
         			}
         			if($this->_audSr!==null && $this->_audSr>0){
         				$audProfile['SamplesPerSecond'] = $this->_audSr;
         			}
         			if($this->_audCh!==null && $this->_audCh>0){
         				$audProfile['Channels'] = $this->_audCh;
         			}
         */
     } else {
         unset($fileFormat->AudioProfile->WmaAudioProfile);
         unset($fileFormat->AudioProfile->AacAudioProfile);
         unset($fileFormat->AudioProfile);
     }
     //$stream = clone $streams->StreamInfo;
     //		$streams[1] = $stream;
     //		print_r($xml);
     return $xml->asXML();
 }
Beispiel #4
0
 public static function ProceessFlavorsForCollection($flavorList)
 {
     $rootFlavor = null;
     $rootStreams = null;
     foreach ($flavorList as $flavor) {
         $ee3Id = KDLOperationParams::SearchInArray(KDLTranscoders::EE3, $flavor->_transcoders);
         if (!is_null($ee3Id)) {
             //				if(array_key_exists(KDLTranscoders::EE3, $flavor->_transcoders)) {
             $tr = $flavor->_transcoders[$ee3Id];
             //KalturaLog::log(__METHOD__."transcoders==>\n".print_r($trnsStr,true));
             KalturaLog::log(__METHOD__ . "\n" . "transcoder==>\n" . print_r($tr, true) . "\n<--");
             if (is_null($tr->_cmd)) {
                 KalturaLog::log(__METHOD__ . " - ee3 cmd is null");
             }
             //					KalturaLog::log(__METHOD__."-->\n".$flavor->_transcoders[$ee3Id]->_id."\n<--");
             //					KalturaLog::log(__METHOD__."-->\n".$flavor->_transcoders[$ee3Id]->_cmd."\n<--");
             $ee3 = new SimpleXMLElement($flavor->_transcoders[$ee3Id]->_cmd);
             $ee3Streams = null;
             if (!is_null($ee3->MediaFile->OutputFormat->WindowsMediaOutputFormat->VideoProfile)) {
                 $ee3Streams = $ee3->MediaFile->OutputFormat->WindowsMediaOutputFormat->VideoProfile->AdvancedVC1VideoProfile->Streams;
                 if ($ee3Streams->StreamInfo->Bitrate->VariableConstrainedBitrate['AverageBitrate'] != $flavor->_video->_bitRate) {
                     KalturaLog::log(__METHOD__ . "-->xmlBR=" . $ee3Streams->StreamInfo->Bitrate->VariableConstrainedBitrate['AverageBitrate'] . ", flavorBR=" . $flavor->_video->_bitRate);
                     $ee3Streams->StreamInfo->Bitrate->VariableConstrainedBitrate['AverageBitrate'] = $flavor->_video->_bitRate;
                     $ee3Streams->StreamInfo->Bitrate->VariableConstrainedBitrate['PeakBitrate'] = round($flavor->_video->_bitRate * 1.3);
                 }
             }
             if ($rootFlavor == null) {
                 $rootFlavor = $ee3;
                 $rootStreams = $ee3Streams;
             } else {
                 $dest = $rootStreams;
                 if ($ee3Streams) {
                     $src = $ee3Streams->StreamInfo[0];
                     if ($dest && $src) {
                         KDLUtils::AddXMLElement($dest, $src);
                     }
                 }
             }
         }
     }
     if ($rootFlavor) {
         return $rootFlavor->asXML();
     } else {
         return null;
     }
 }