/** * batch adjustToFramesize - verify that in the given set of target flvors, * there is at least one flavor that matches (or as close as possible) * to the source frame size. If there is no such flavor - set '_create_anyway' for the best matching. * The screencast sources are main cases for such adjustments, but there are other cases as well * * @param mediaInfo $source * @param array $targetFlavorArr is array of flavorOutputParams */ protected static function adjustToFramesize(mediaInfo $source, array $targetFlavorArr) { /* * Evaluate the 'adjusted' source height, to use as a for best matching flavor. */ $srcHgt = 0; if (isset($source)) { $srcHgt = $source->getVideoHeight(); $srcHgt = $srcHgt - $srcHgt % 16; } $matchSourceHeightIdx = null; // index of the smallest flavor that matches the source height $matchSourceOriginalFlavorBR = 0; $targetLargestHeight = 0; // To save the height of the largest target flavor and its key $targetLargestHeightKey = null; // and its key id. foreach ($targetFlavorArr as $key => $target) { /* * Ignore flavors that are smaller than the source - * they are not in the scope of 'adjustToFramesize'. * Track the largest target flavor, required for cases when the source height is larger than ALL flavors */ if ($target->getHeight() < $srcHgt) { KalturaLog::log("Source is larger than the target, skipping - key:{$key}, srcHgt:{$srcHgt}, trgHgt:" . $target->getHeight()); if ($targetLargestHeight < $target->getHeight()) { $targetLargestHeight = $target->getHeight(); $targetLargestHeightKey = $key; } continue; } /* * Stop searching if there is a flavor, in that set, that matches the source frame size - * no need to activate another flavor conversion */ if (!$target->_isNonComply || $target->_force || $target->_create_anyway) { $matchSourceHeightIdx = null; $targetLargestHeightKey = null; KalturaLog::log("Found COMPLY/forced/create_anyway, leaving - key:{$key}, srcHgt:{$srcHgt}, trgHgt:" . $target->getHeight()); break; } /* * If 'matching-target' is unset * - set it to the current target */ if (!isset($matchSourceHeightIdx)) { $matchSourceHeightIdx = $key; $flPrm = assetParamsPeer::retrieveByPKs(array($key)); $matchSourceOriginalFlavorBR = $flPrm[0]->getVideoBitrate(); KalturaLog::log("Set matchSourceHeightIdx:{$key}, matchSourceOriginalFlavorBR:{$matchSourceOriginalFlavorBR}, srcHgt:{$srcHgt}"); continue; } /* * If current target is smaller than 'matching-target' * - set it to the current target */ $flPrm = assetParamsPeer::retrieveByPKs(array($key)); $flPrmBR = $flPrm[0]->getVideoBitrate(); if ($matchSourceOriginalFlavorBR > $flPrmBR) { $matchSourceOriginalFlavorBR = $flPrmBR; $matchSourceHeightIdx = $key; KalturaLog::log("Switch to matchSourceHeightIdx:{$matchSourceHeightIdx}, matchSourceOriginalFlavorBR:{$matchSourceOriginalFlavorBR} srcHgt:{$srcHgt}"); } // if($target->getHeight()<$targetFlavorArr[$matchSourceHeightIdx]->getHeight()){ // } } /* * If no match was found, use the largest target flavor */ if (!isset($matchSourceHeightIdx) && isset($targetLargestHeightKey) && $targetFlavorArr[$targetLargestHeightKey]->getHeight() < $srcHgt) { $matchSourceHeightIdx = $targetLargestHeightKey; } /* * If smallest-source-height-matching is found and it is 'non-compliant' (therefore it will not be generated), * set '_create_anyway' flag for the 'matchSourceHeightIdx' flavor. */ if (isset($matchSourceHeightIdx) && $targetFlavorArr[$matchSourceHeightIdx]->_isNonComply) { $targetFlavorArr[$matchSourceHeightIdx]->_create_anyway = true; KalturaLog::log("Forcing (create anyway) target {$matchSourceHeightIdx}"); /* $first = reset($targetFlavorArr); if($first->_isNonComply) { $first->_force = true; // _create_anyway } */ } }
public static function ConvertMediainfoCdl2Mediadataset(mediaInfo $cdlMediaInfo, KDLMediaDataSet &$medSet) { // KalturaLog::log(__METHOD__."->".$cdlMediaInfo->getRawData()); $medSet->_container = new KDLContainerData(); $medSet->_streamsCollectionStr = $cdlMediaInfo->getMultiStreamInfo(); $medSet->_container->_id = $cdlMediaInfo->getContainerId(); $medSet->_container->_format = $cdlMediaInfo->getContainerFormat(); $medSet->_container->_duration = $cdlMediaInfo->getContainerDuration(); $medSet->_container->_bitRate = $cdlMediaInfo->getContainerBitRate(); $medSet->_container->_fileSize = $cdlMediaInfo->getFileSize(); if ($medSet->_container->IsDataSet() == false) { $medSet->_container = null; } $medSet->_video = new KDLVideoData(); $medSet->_video->_id = $cdlMediaInfo->getVideoCodecId(); $medSet->_video->_format = $cdlMediaInfo->getVideoFormat(); $medSet->_video->_duration = $cdlMediaInfo->getVideoDuration(); $medSet->_video->_bitRate = $cdlMediaInfo->getVideoBitRate(); $medSet->_video->_width = $cdlMediaInfo->getVideoWidth(); $medSet->_video->_height = $cdlMediaInfo->getVideoHeight(); $medSet->_video->_frameRate = $cdlMediaInfo->getVideoFrameRate(); $medSet->_video->_dar = $cdlMediaInfo->getVideoDar(); $medSet->_video->_rotation = $cdlMediaInfo->getVideoRotation(); $medSet->_video->_scanType = $cdlMediaInfo->getScanType(); /* { $medLoader = new KDLMediaInfoLoader($cdlMediaInfo->getRawData()); $md = new KDLMediadataset(); $medLoader->Load($md); if($md->_video) $medSet->_video->_scanType = $md->_video->_scanType; } */ if ($medSet->_video->IsDataSet() == false) { $medSet->_video = null; } $medSet->_audio = new KDLAudioData(); $medSet->_audio->_id = $cdlMediaInfo->getAudioCodecId(); $medSet->_audio->_format = $cdlMediaInfo->getAudioFormat(); $medSet->_audio->_duration = $cdlMediaInfo->getAudioDuration(); $medSet->_audio->_bitRate = $cdlMediaInfo->getAudioBitRate(); $medSet->_audio->_channels = $cdlMediaInfo->getAudioChannels(); $medSet->_audio->_sampleRate = $cdlMediaInfo->getAudioSamplingRate(); $medSet->_audio->_resolution = $cdlMediaInfo->getAudioResolution(); if ($medSet->_audio->IsDataSet() == false) { $medSet->_audio = null; } return $medSet; }
public static function ConvertMediainfoCdl2Mediadataset(mediaInfo $cdlMediaInfo, KDLMediaDataSet &$medSet) { $medSet->_container = new KDLContainerData(); /**/ $contentStreams = $cdlMediaInfo->getContentStreams(); if (isset($contentStreams)) { if (is_string($contentStreams)) { $fromJson = json_decode($contentStreams); $medSet->_contentStreams = isset($fromJson) ? $fromJson : null; } else { $medSet->_contentStreams = $contentStreams; } } $medSet->_container->_id = $cdlMediaInfo->getContainerId(); $medSet->_container->_format = $cdlMediaInfo->getContainerFormat(); $medSet->_container->_duration = $cdlMediaInfo->getContainerDuration(); $medSet->_container->_bitRate = $cdlMediaInfo->getContainerBitRate(); $medSet->_container->_fileSize = $cdlMediaInfo->getFileSize(); $medSet->_container->_isFastStart = $cdlMediaInfo->getIsFastStart(); if ($medSet->_container->IsDataSet() == false) { $medSet->_container = null; } $medSet->_video = new KDLVideoData(); $medSet->_video->_id = $cdlMediaInfo->getVideoCodecId(); $medSet->_video->_format = $cdlMediaInfo->getVideoFormat(); $medSet->_video->_duration = $cdlMediaInfo->getVideoDuration(); $medSet->_video->_bitRate = $cdlMediaInfo->getVideoBitRate(); $medSet->_video->_width = $cdlMediaInfo->getVideoWidth(); $medSet->_video->_height = $cdlMediaInfo->getVideoHeight(); $medSet->_video->_frameRate = $cdlMediaInfo->getVideoFrameRate(); $medSet->_video->_dar = $cdlMediaInfo->getVideoDar(); $medSet->_video->_rotation = $cdlMediaInfo->getVideoRotation(); $medSet->_video->_scanType = $cdlMediaInfo->getScanType(); /* { $medLoader = new KDLMediaInfoLoader($cdlMediaInfo->getRawData()); $md = new KDLMediadataset(); $medLoader->Load($md); if($md->_video) $medSet->_video->_scanType = $md->_video->_scanType; } */ if ($medSet->_video->IsDataSet() == false) { $medSet->_video = null; } $medSet->_audio = new KDLAudioData(); $medSet->_audio->_id = $cdlMediaInfo->getAudioCodecId(); $medSet->_audio->_format = $cdlMediaInfo->getAudioFormat(); $medSet->_audio->_duration = $cdlMediaInfo->getAudioDuration(); $medSet->_audio->_bitRate = $cdlMediaInfo->getAudioBitRate(); $medSet->_audio->_channels = $cdlMediaInfo->getAudioChannels(); $medSet->_audio->_sampleRate = $cdlMediaInfo->getAudioSamplingRate(); $medSet->_audio->_resolution = $cdlMediaInfo->getAudioResolution(); if ($medSet->_audio->IsDataSet() == false) { $medSet->_audio = null; } return $medSet; }