public static function filterTagFlavors(array $flavors) { KalturaLog::log("Filter Tag Flavors, " . count($flavors) . " flavors supplied"); // check if there is a complete flavor $hasComplied = false; $hasForced = false; $originalFlavorParamsIds = array(); foreach ($flavors as $flavorParamsId => $flavor) { $originalFlavorParamsIds[] = $flavor->getFlavorParamsId(); if (!$flavor->_isNonComply) { $hasComplied = true; } if ($flavor->_force) { $hasForced = true; } } $originalFlavorParams = array(); $dbOriginalFlavorParams = flavorParamsPeer::retrieveByPKs($originalFlavorParamsIds); foreach ($dbOriginalFlavorParams as $dbFlavorParams) { $originalFlavorParams[$dbFlavorParams->getId()] = $dbFlavorParams; } // return only complete flavors if ($hasComplied) { KalturaLog::log("Has complied flavors"); } if ($hasForced) { KalturaLog::log("Has forced flavors"); } if ($hasComplied || $hasForced) { return $flavors; } // find the lowest flavor $lowestFlavorParamsId = null; foreach ($flavors as $flavorParamsId => $flavor) { if (!$flavor->IsValid()) { continue; } // is lower than the selected if (!isset($originalFlavorParams[$flavor->getFlavorParamsId()])) { continue; } $currentOriginalFlavor = $originalFlavorParams[$flavor->getFlavorParamsId()]; // is first flavor to check if (is_null($lowestFlavorParamsId)) { $lowestFlavorParamsId = $flavorParamsId; continue; } $lowestOriginalFlavor = $originalFlavorParams[$flavors[$lowestFlavorParamsId]->getFlavorParamsId()]; if (self::isFlavorLower($currentOriginalFlavor, $lowestOriginalFlavor)) { $lowestFlavorParamsId = $flavorParamsId; } } if ($lowestFlavorParamsId) { KalturaLog::log("Lowest flavor selected [{$lowestFlavorParamsId}]"); $flavors[$lowestFlavorParamsId]->_create_anyway = true; } return $flavors; }
public static function continueProfileConvert(BatchJob $parentJob) { $convertProfileJob = $parentJob->getRootJob(); if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) { throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion"); } KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]"); $convertProfileData = $convertProfileJob->getData(); $entryId = $convertProfileJob->getEntryId(); $entry = $convertProfileJob->getEntry(); if (!$entry) { throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId); } $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId); if (!$profile) { $errDescription = "Conversion profile for entryId [{$entryId}] not found"; $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE); kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING); KalturaLog::err("No flavors created: {$errDescription}"); throw new Exception($errDescription); } $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId); if (is_null($originalFlavorAsset)) { $errDescription = 'Original flavor asset not found'; KalturaLog::err($errDescription); $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE); kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING); throw new Exception($errDescription); } // gets the list of flavor params of the conversion profile $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId()); if (!count($list)) { $errDescription = "No flavors match the profile id [{$profile->getId()}]"; KalturaLog::err($errDescription); $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE); kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING); $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED); $originalFlavorAsset->setDeletedAt(time()); $originalFlavorAsset->save(); throw new Exception($errDescription); } // gets the ids of the flavor params $flavorsIds = array(); $conversionProfileFlavorParams = array(); foreach ($list as $flavorParamsConversionProfile) { $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId(); $flavorsIds[] = $flavorsId; $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile; } $dynamicFlavorAttributes = $entry->getDynamicFlavorAttributes(); // gets the flavor params by the id $flavors = flavorParamsPeer::retrieveByPKs($flavorsIds); foreach ($flavors as $index => $flavor) { if ($flavor->hasTag(flavorParams::TAG_SOURCE)) { unset($flavors[$index]); continue; } if (isset($dynamicFlavorAttributes[$flavor->getId()])) { foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) { $flavor->setDynamicAttribute($attributeName, $attributeValue); } } } KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]"); if (!count($flavors)) { return false; } $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId()); return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo); }
/** * @param BatchJob $parentJob * @param int $srcParamsId */ public static function generateThumbnailsFromFlavor($entryId, BatchJob $parentJob = null, $srcParamsId = null) { $profile = null; try { $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId); } catch (Exception $e) { KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage()); } if (!$profile) { KalturaLog::notice("Profile not found for entry id [{$entryId}]"); return; } $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { KalturaLog::notice("Entry id [{$entryId}] not found"); return; } $assetParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($profile->getId()); if (!count($assetParamsIds)) { KalturaLog::notice("No asset params objects found for profile id [" . $profile->getId() . "]"); return; } // the alternative is the source or the highest bitrate if source not defined $alternateFlavorParamsId = null; if (is_null($srcParamsId)) { $flavorParamsObjects = flavorParamsPeer::retrieveByPKs($assetParamsIds); foreach ($flavorParamsObjects as $flavorParams) { if ($flavorParams->hasTag(flavorParams::TAG_SOURCE)) { $alternateFlavorParamsId = $flavorParams->getId(); } } if (is_null($alternateFlavorParamsId)) { $srcFlavorAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entryId); $alternateFlavorParamsId = $srcFlavorAsset->getFlavorParamsId(); } if (is_null($alternateFlavorParamsId)) { KalturaLog::notice("No source flavor params object found for entry id [{$entryId}]"); return; } } // create list of created thumbnails $thumbAssetsList = array(); $thumbAssets = thumbAssetPeer::retrieveByEntryId($entryId); if (count($thumbAssets)) { foreach ($thumbAssets as $thumbAsset) { if (!is_null($thumbAsset->getFlavorParamsId())) { $thumbAssetsList[$thumbAsset->getFlavorParamsId()] = $thumbAsset; } } } $thumbParamsObjects = thumbParamsPeer::retrieveByPKs($assetParamsIds); foreach ($thumbParamsObjects as $thumbParams) { // check if this thumbnail already created if (isset($thumbAssetsList[$thumbParams->getId()])) { continue; } if (is_null($srcParamsId) && is_null($thumbParams->getSourceParamsId())) { // alternative should be used $thumbParams->setSourceParamsId($alternateFlavorParamsId); } elseif ($thumbParams->getSourceParamsId() != $srcParamsId) { // only thumbnails that uses srcParamsId should be generated for now continue; } kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams, $parentJob); } }