Пример #1
0
 /**
  * decideThumbGenerate is the decision layer for a single thumbnail generation
  *
  * @param entry $entry
  * @param thumbParams $destThumbParams
  * @param BatchJob $parentJob
  * @return thumbAsset
  */
 public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false, $srcAsset = null)
 {
     if (is_null($srcAsset)) {
         $srcAsset = self::getSourceAssetForGenerateThumbnail($sourceAssetId, $destThumbParams->getSourceParamsId(), $entry->getId());
         if (is_null($srcAsset)) {
             throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY);
         }
     }
     $errDescription = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
     $destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription, $srcAsset);
     if ($srcAsset->getType() == assetType::FLAVOR && is_null($destThumbParamsOutput->getVideoOffset())) {
         $destThumbParamsOutput->setVideoOffset($entry->getThumbOffset());
     }
     $destThumbParamsOutput->setVideoOffset(min($destThumbParamsOutput->getVideoOffset(), $entry->getDuration()));
     if (!$destThumbParamsOutput->getDensity()) {
         $partner = $entry->getPartner();
         if (!is_null($partner)) {
             $destThumbParamsOutput->setDensity($partner->getDefThumbDensity());
         }
     }
     $thumbAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId());
     if ($thumbAsset) {
         $description = $thumbAsset->getDescription() . "\n" . $errDescription;
         $thumbAsset->setDescription($description);
     } else {
         $thumbAsset = new thumbAsset();
         $thumbAsset->setPartnerId($entry->getPartnerId());
         $thumbAsset->setEntryId($entry->getId());
         $thumbAsset->setDescription($errDescription);
         $thumbAsset->setFlavorParamsId($destThumbParams->getId());
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setTags($destThumbParamsOutput->getTags());
     $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt());
     if ($thumbAsset->getStatus() != asset::ASSET_STATUS_READY) {
         $thumbAsset->setStatus(asset::ASSET_STATUS_CONVERTING);
     }
     //Sets the default thumb if this the only default thumb
     kBusinessPreConvertDL::setIsDefaultThumb($thumbAsset);
     if (!$destThumbParamsOutput) {
         $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
         $thumbAsset->save();
         return null;
     }
     $thumbAsset->save();
     // save flavor params
     $destThumbParamsOutput->setPartnerId($entry->getPartnerId());
     $destThumbParamsOutput->setEntryId($entry->getId());
     $destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId());
     $destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion());
     $destThumbParamsOutput->save();
     $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $srcAssetType = $srcAsset->getType();
     if (!$runSync) {
         $job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAsset->getId(), $srcAssetType, $destThumbParamsOutput);
         return $thumbAsset;
     }
     $errDescription = null;
     // Since this method is called when trying to crop an existing thumbnail, need to add this check - thumbAssets have no mediaInfo.
     $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription, $mediaInfo ? $mediaInfo->getVideoRotation() : null);
     // failed
     if (!$capturedPath) {
         $thumbAsset->incrementVersion();
         $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
         $thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}");
         $thumbAsset->save();
         return $thumbAsset;
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setStatus(thumbAsset::ASSET_STATUS_QUEUED);
     if (file_exists($capturedPath)) {
         list($width, $height, $type, $attr) = getimagesize($capturedPath);
         $thumbAsset->setWidth($width);
         $thumbAsset->setHeight($height);
         $thumbAsset->setSize(filesize($capturedPath));
     }
     $logPath = $capturedPath . '.log';
     if (file_exists($logPath)) {
         $thumbAsset->incLogFileVersion();
         $thumbAsset->save();
         // creats the file sync
         $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
         kFileSyncUtils::moveFromFile($logPath, $logSyncKey);
         KalturaLog::info("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey));
     } else {
         $thumbAsset->save();
     }
     $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($capturedPath, $syncKey);
     KalturaLog::info("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey));
     $thumbAsset->setStatus(thumbAsset::ASSET_STATUS_READY);
     $thumbAsset->save();
     if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
         // increment thumbnail version
         $entry->setThumbnail(".jpg");
         $entry->setCreateThumb(false);
         $entry->save();
         $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey);
         if ($syncFile) {
             // removes the DEFAULT_THUMB tag from all other thumb assets
             assetPeer::removeThumbAssetDeafultTags($entry->getId(), $thumbAsset->getId());
         }
     }
     if (!is_null($thumbAsset->getFlavorParamsId())) {
         kFlowHelper::generateThumbnailsFromFlavor($thumbAsset->getEntryId(), null, $thumbAsset->getFlavorParamsId());
     }
     return $thumbAsset;
 }
Пример #2
0
 public function setCreateThumb($v, thumbAsset $thumbAsset = null)
 {
     if (!$v) {
         assetPeer::removeThumbAssetDeafultTags($this->getId(), $thumbAsset ? $thumbAsset->getId() : null);
     }
     $this->putInCustomData("createThumb", (bool) $v);
 }
Пример #3
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kCaptureThumbJobData $data
  * @return BatchJob
  */
 public static function handleCaptureThumbFinished(BatchJob $dbBatchJob, kCaptureThumbJobData $data)
 {
     if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) {
         return $dbBatchJob;
     }
     // verifies that thumb asset created
     if (!$data->getThumbAssetId()) {
         throw new APIException(APIErrors::INVALID_THUMB_ASSET_ID, $data->getThumbAssetId());
     }
     $thumbAsset = assetPeer::retrieveById($data->getThumbAssetId());
     // verifies that thumb asset exists
     if (!$thumbAsset) {
         throw new APIException(APIErrors::INVALID_THUMB_ASSET_ID, $data->getThumbAssetId());
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
     if (file_exists($data->getThumbPath())) {
         list($width, $height, $type, $attr) = getimagesize($data->getThumbPath());
         $thumbAsset->setWidth($width);
         $thumbAsset->setHeight($height);
         $thumbAsset->setSize(filesize($data->getThumbPath()));
     }
     $logPath = $data->getThumbPath() . '.log';
     if (file_exists($logPath)) {
         $thumbAsset->incLogFileVersion();
         $thumbAsset->save();
         // creats the file sync
         $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
         try {
             kFileSyncUtils::moveFromFile($logPath, $logSyncKey);
         } catch (Exception $e) {
             $err = 'Saving conversion log: ' . $e->getMessage();
             KalturaLog::err($err);
             $desc = $dbBatchJob->getDescription() . "\n" . $err;
             $dbBatchJob->getDescription($desc);
         }
     } else {
         $thumbAsset->save();
     }
     $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($data->getThumbPath(), $syncKey);
     $data->setThumbPath(kFileSyncUtils::getLocalFilePathForKey($syncKey));
     KalturaLog::info("Thumbnail archived file to: " . $data->getThumbPath());
     // save the data changes to the db
     $dbBatchJob->setData($data);
     $dbBatchJob->save();
     $entry = $thumbAsset->getentry();
     if ($entry && $entry->getCreateThumb() && $thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
         $entry = $dbBatchJob->getEntry(false, false);
         if (!$entry) {
             throw new APIException(APIErrors::INVALID_ENTRY, $dbBatchJob, $dbBatchJob->getEntryId());
         }
         // increment thumbnail version
         $entry->setThumbnail(".jpg");
         $entry->setCreateThumb(false);
         $entry->save();
         $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey);
         if ($syncFile) {
             // removes the DEFAULT_THUMB tag from all other thumb assets
             assetPeer::removeThumbAssetDeafultTags($entry->getId(), $thumbAsset->getId());
         }
     }
     if (!is_null($thumbAsset->getFlavorParamsId())) {
         kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $thumbAsset->getFlavorParamsId());
     }
     self::handleLocalFileSyncDeletion($dbBatchJob->getEntryId(), $dbBatchJob->getPartner());
     return $dbBatchJob;
 }