/** * @param BatchJob $dbBatchJob * @param kPostConvertJobData $data * @param BatchJob $twinJob * @return BatchJob|BatchJob */ public static function handlePostConvertFinished(BatchJob $dbBatchJob, kPostConvertJobData $data, BatchJob $twinJob = null) { if ($dbBatchJob->getAbort()) { return $dbBatchJob; } if ($data->getCreateThumb()) { try { self::createThumbnail($dbBatchJob, $data); } catch (Exception $e) { KalturaLog::err($e->getMessage()); // sometimes, because of disc IO load, it takes long time for the thumb to be moved. // in such cases, the entry thumb version may be increased by other process. // retry the job, it solves the issue. kJobsManager::retryJob($dbBatchJob->getId(), $dbBatchJob->getJobType(), true); $dbBatchJob->reload(); return $dbBatchJob; } } $currentFlavorAsset = kBusinessPostConvertDL::handleFlavorReady($dbBatchJob, $data->getFlavorAssetId()); if ($dbBatchJob->getJobSubType() == BatchJob::BATCHJOB_SUB_TYPE_POSTCONVERT_SOURCE) { try { kBusinessPreConvertDL::continueProfileConvert($dbBatchJob); } catch (Exception $e) { KalturaLog::err($e->getMessage()); kBatchManager::updateEntry($dbBatchJob, entryStatus::ERROR_CONVERTING); return $dbBatchJob; } } if ($currentFlavorAsset) { kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset); } return $dbBatchJob; }
/** * @param BatchJob $parentJob * @param int $postConvertAssetType * @param string $srcFileSyncLocalPath * @param int $flavorAssetId * @param int $flavorParamsOutputId * @param bool $createThumb * @param int $thumbOffset * @param string $customData * @return BatchJob */ public static function addPostConvertJob(BatchJob $parentJob = null, $postConvertAssetType, $srcFileSyncLocalPath, $flavorAssetId, $flavorParamsOutputId, $createThumb = false, $thumbOffset = 3) { $postConvertData = new kPostConvertJobData(); $postConvertData->setPostConvertAssetType($postConvertAssetType); $postConvertData->setSrcFileSyncLocalPath($srcFileSyncLocalPath); $postConvertData->setFlavorParamsOutputId($flavorParamsOutputId); $postConvertData->setFlavorAssetId($flavorAssetId); $postConvertData->setThumbOffset($thumbOffset); $postConvertData->setCreateThumb($createThumb); if ($parentJob) { $parentData = $parentJob->getData(); if ($parentData instanceof kConvartableJobData) { $postConvertData->setCurrentOperationSet($parentData->getCurrentOperationSet()); $postConvertData->setCurrentOperationIndex($parentData->getCurrentOperationIndex()); } } $flavorAsset = assetPeer::retrieveById($flavorAssetId); $flavorParamsOutput = null; if ($createThumb) { $flavorParamsOutput = assetParamsOutputPeer::retrieveByPK($flavorParamsOutputId); if (!$flavorParamsOutput) { if ($flavorAsset) { $postConvertData->setThumbHeight($flavorAsset->getHeight()); $postConvertData->setThumbBitrate($flavorAsset->getBitrate()); } else { $postConvertData->setCreateThumb(false); } } elseif (!$flavorParamsOutput->getVideoBitrate()) { $postConvertData->setCreateThumb(false); } elseif ($flavorParamsOutput->getSourceRemoteStorageProfileId() != StorageProfile::STORAGE_KALTURA_DC) { $postConvertData->setCreateThumb(false); } elseif ($flavorAsset) { $entry = $flavorAsset->getentry(); if ($entry) { $thisFlavorHeight = $flavorParamsOutput->getHeight(); $thisFlavorBitrate = $flavorParamsOutput->getVideoBitrate(); $createThumb = false; if ($entry->getThumbBitrate() < $thisFlavorBitrate) { $createThumb = true; } elseif ($entry->getThumbBitrate() == $thisFlavorBitrate && $entry->getThumbHeight() < $thisFlavorHeight) { $createThumb = true; } if ($createThumb) { $postConvertData->setCreateThumb(true); $postConvertData->setThumbHeight($thisFlavorHeight); $postConvertData->setThumbBitrate($thisFlavorBitrate); } } } } $batchJob = null; $mediaParserType = $flavorParamsOutput ? $flavorParamsOutput->getMediaParserType() : mediaParserType::MEDIAINFO; if ($parentJob) { //Job will be created with parent job as his root job $useSameRoot = true; if ($parentJob->getJobType() == BatchJobType::CONVERT_PROFILE) { $useSameRoot = false; } $batchJob = $parentJob->createChild(BatchJobType::POSTCONVERT, $mediaParserType, $useSameRoot); } else { $batchJob = new BatchJob(); $batchJob->setEntryId($flavorAsset->getEntryId()); $batchJob->setPartnerId($flavorAsset->getPartnerId()); } $batchJob->setObjectId($flavorAsset->getId()); $batchJob->setObjectType(BatchJobObjectType::ASSET); KalturaLog::log("Post Convert created with file: " . $postConvertData->getSrcFileSyncLocalPath()); return kJobsManager::addJob($batchJob, $postConvertData, BatchJobType::POSTCONVERT, $mediaParserType); }
/** * @param BatchJob $parentJob * @param int $jobSubType * @param string $srcFileSyncLocalPath * @param int $flavorAssetId * @param int $flavorParamsOutputId * @param bool $createThumb * @param int $thumbOffset * @return BatchJob */ public static function addPostConvertJob(BatchJob $parentJob, $jobSubType, $srcFileSyncLocalPath, $flavorAssetId, $flavorParamsOutputId, $createThumb = false, $thumbOffset = 3) { $postConvertData = new kPostConvertJobData(); $postConvertData->setSrcFileSyncLocalPath($srcFileSyncLocalPath); $postConvertData->setFlavorParamsOutputId($flavorParamsOutputId); $postConvertData->setFlavorAssetId($flavorAssetId); $postConvertData->setThumbOffset($thumbOffset); $postConvertData->setCreateThumb($createThumb); $parentData = $parentJob->getData(); if ($parentData instanceof kConvartableJobData) { $postConvertData->setCurrentOperationSet($parentData->getCurrentOperationSet()); $postConvertData->setCurrentOperationIndex($parentData->getCurrentOperationIndex()); } if ($createThumb) { $flavorParamsOutput = flavorParamsOutputPeer::retrieveByPK($flavorParamsOutputId); if (!$flavorParamsOutput) { $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId); if ($flavorAsset) { $postConvertData->setThumbHeight($flavorAsset->getHeight()); $postConvertData->setThumbBitrate($flavorAsset->getBitrate()); } else { $postConvertData->setCreateThumb(false); } } elseif (!$flavorParamsOutput->getVideoBitrate()) { $postConvertData->setCreateThumb(false); } else { $entry = $parentJob->getEntry(); $rootBatchJob = $parentJob->getRootJob(); if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) { $thisFlavorHeight = $flavorParamsOutput->getHeight(); $thisFlavorBitrate = $flavorParamsOutput->getVideoBitrate(); $rootBatchJobData = $rootBatchJob->getData(); $createThumb = false; if ($rootBatchJobData->getThumbBitrate() < $thisFlavorBitrate) { $createThumb = true; } elseif ($rootBatchJobData->getThumbBitrate() == $thisFlavorBitrate && $rootBatchJobData->getThumbHeight() < $thisFlavorHeight) { $createThumb = true; } if ($createThumb) { $postConvertData->setCreateThumb(true); $postConvertData->setThumbHeight($thisFlavorHeight); $postConvertData->setThumbBitrate($thisFlavorBitrate); } } elseif (!$entry->getThumbnailVersion()) { $thisFlavorHeight = $flavorParamsOutput->getHeight(); $thisFlavorBitrate = $flavorParamsOutput->getVideoBitrate(); $postConvertData->setCreateThumb(true); $postConvertData->setThumbHeight($thisFlavorHeight); $postConvertData->setThumbBitrate($thisFlavorBitrate); } } } KalturaLog::log("Post Convert created with file: " . $postConvertData->getSrcFileSyncLocalPath()); return kJobsManager::addJob($parentJob->createChild(), $postConvertData, BatchJobType::POSTCONVERT, $jobSubType); }
/** * @param BatchJob $dbBatchJob * @param kPostConvertJobData $data * @return BatchJob|BatchJob */ public static function handlePostConvertFinished(BatchJob $dbBatchJob, kPostConvertJobData $data) { if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) { return $dbBatchJob; } if ($data->getCreateThumb()) { try { self::createThumbnail($dbBatchJob, $data); } catch (Exception $e) { KalturaLog::err($e->getMessage()); // sometimes, because of disc IO load, it takes long time for the thumb to be moved. // in such cases, the entry thumb version may be increased by other process. // retry the job, it solves the issue. kJobsManager::retryJob($dbBatchJob->getId(), $dbBatchJob->getJobType(), true); $dbBatchJob->reload(); return $dbBatchJob; } } $currentFlavorAsset = kBusinessPostConvertDL::handleFlavorReady($dbBatchJob, $data->getFlavorAssetId()); if ($data->getPostConvertAssetType() == BatchJob::POSTCONVERT_ASSET_TYPE_SOURCE) { $convertProfileJob = $dbBatchJob->getRootJob(); if ($convertProfileJob->getJobType() == BatchJobType::CONVERT_PROFILE) { try { $currFlavorAsset = assetPeer::retrieveById($data->getFlavorAssetId()); //In cases we are returning from intermediate flow need to check maybe if another round is needed //This comes to support the creation of silent audio tracks on source assets such as .arf that require initial inter flow for the source and only than the addition //of the silent audio track if ($currFlavorAsset instanceof flavorAsset && $currFlavorAsset->getIsOriginal() && $currFlavorAsset->getInterFlowCount() != null) { //check if the inter flow count is larger than 2. //In this cases probably something went wrong so we will continue with the original flow and will not check if any additioanl inter flow nneds to be done. if ($currentFlavorAsset && $currFlavorAsset->getInterFlowCount() < self::MAX_INTER_FLOW_ITERATIONS_ALLOWED_ON_SOURCE) { $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId()); kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $convertProfileJob, $mediaInfo->getId()); } else { kBusinessPreConvertDL::continueProfileConvert($dbBatchJob); } } else { kBusinessPreConvertDL::continueProfileConvert($dbBatchJob); } } catch (Exception $e) { KalturaLog::err($e->getMessage()); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return $dbBatchJob; } } elseif ($currentFlavorAsset) { KalturaLog::log("Root job [" . $convertProfileJob->getId() . "] is not profile conversion"); $syncKey = $currentFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::fileSync_exists($syncKey)) { $path = kFileSyncUtils::getLocalFilePathForKey($syncKey); $entry = $dbBatchJob->getEntry(); if ($entry) { kJobsManager::addConvertProfileJob(null, $entry, $currentFlavorAsset->getId(), $path); } } $currentFlavorAsset = null; } } if ($currentFlavorAsset) { kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset); } return $dbBatchJob; }
/** * @param BatchJob $dbBatchJob * @param kPostConvertJobData $data * @param BatchJob $twinJob * @return BatchJob|BatchJob */ public static function handlePostConvertFinished(BatchJob $dbBatchJob, kPostConvertJobData $data, BatchJob $twinJob = null) { if ($dbBatchJob->getAbort()) { return $dbBatchJob; } if ($data->getCreateThumb()) { try { self::createThumbnail($dbBatchJob, $data); } catch (Exception $e) { KalturaLog::err($e->getMessage()); // sometimes, because of disc IO load, it takes long time for the thumb to be moved. // in such cases, the entry thumb version may be increased by other process. // retry the job, it solves the issue. kJobsManager::retryJob($dbBatchJob->getId(), $dbBatchJob->getJobType(), true); $dbBatchJob->reload(); return $dbBatchJob; } } $currentFlavorAsset = kBusinessPostConvertDL::handleFlavorReady($dbBatchJob, $data->getFlavorAssetId()); if ($data->getPostConvertAssetType() == BatchJob::POSTCONVERT_ASSET_TYPE_SOURCE) { $convertProfileJob = $dbBatchJob->getRootJob(); if ($convertProfileJob->getJobType() == BatchJobType::CONVERT_PROFILE) { try { kBusinessPreConvertDL::continueProfileConvert($dbBatchJob); } catch (Exception $e) { KalturaLog::err($e->getMessage()); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return $dbBatchJob; } } elseif ($currentFlavorAsset) { KalturaLog::log("Root job [" . $convertProfileJob->getId() . "] is not profile conversion"); $syncKey = $currentFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::fileSync_exists($syncKey)) { KalturaLog::debug("Start conversion"); $path = kFileSyncUtils::getLocalFilePathForKey($syncKey); $wamsAssetId = kFileSyncUtils::getWamsAssetIdForKey($syncKey); kJobsManager::addConvertProfileJob(null, $dbBatchJob->getEntry(), $currentFlavorAsset->getId(), $path, $wamsAssetId); } else { KalturaLog::debug("File sync not created yet"); } $currentFlavorAsset = null; } } if ($currentFlavorAsset) { kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset); } return $dbBatchJob; }