Ejemplo n.º 1
0
 private static function getExternalStorageUrl(Partner $partner, asset $asset, FileSyncKey $key, $servePlayManifest = false, $playManifestClientTag = null, $storageId = null)
 {
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     if (is_null($storageId) && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) {
             // check if having file sync on kaltura dcs
             return null;
         }
     }
     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId);
     if (!$fileSync) {
         return null;
     }
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return null;
     }
     if ($servePlayManifest) {
         // in case of an https request, if a delivery profile which supports https doesn't exist use an http cdn api host
         if (infraRequestUtils::getProtocol() == infraRequestUtils::PROTOCOL_HTTPS && DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId(), PlaybackProtocol::HTTP, "https"))) {
             $url = requestUtils::getApiCdnHost();
         } else {
             $url = infraRequestUtils::PROTOCOL_HTTP . "://" . kConf::get("cdn_api_host");
         }
         $url .= $asset->getPlayManifestUrl($playManifestClientTag, $storageId);
     } else {
         $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId()));
         if ($urlManager) {
             $dynamicAttrs = new DeliveryProfileDynamicAttributes();
             $dynamicAttrs->setFileExtension($asset->getFileExt());
             $dynamicAttrs->setStorageId($fileSync->getDc());
             $urlManager->setDynamicAttributes($dynamicAttrs);
             $url = ltrim($urlManager->getFileSyncUrl($fileSync), '/');
             if (strpos($url, "://") === false) {
                 $url = rtrim($urlManager->getUrl(), "/") . "/" . $url;
             }
         } else {
             KalturaLog::debug("Couldn't determine delivery profile for storage id");
             $url = null;
         }
     }
     return $url;
 }
Ejemplo n.º 2
0
 public function linkFromAsset(asset $fromAsset)
 {
     $this->setWidth($fromAsset->getWidth());
     $this->setHeight($fromAsset->getHeight());
     $this->setContainerFormat($fromAsset->getContainerFormat());
     $this->setSize($fromAsset->getSize());
     $this->setFileExt($fromAsset->getFileExt());
     $this->setTags($fromAsset->getTags());
     $this->setDescription($fromAsset->getDescription());
     $this->incrementVersion();
     $this->setStatusLocalReady();
 }
Ejemplo n.º 3
0
 private static function generateThumbnail(asset $srcAsset, thumbParamsOutput $destThumbParamsOutput, &$errDescription, $rotate = null)
 {
     $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     if (!$fileSync || $fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) {
         $errDescription = 'Source asset could has no valid file sync';
         return false;
     }
     $srcPath = $fileSync->getFullPath();
     $uniqid = uniqid('thumb_');
     $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb';
     if (!file_exists($tempDir)) {
         mkdir($tempDir, 0700, true);
     }
     $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . '.jpg';
     $logPath = $destPath . '.log';
     if (!file_exists($srcPath)) {
         $errDescription = "Source file [{$srcPath}] does not exist";
         return false;
     }
     if (!is_file($srcPath)) {
         $errDescription = "Source file [{$srcPath}] is not a file";
         return false;
     }
     try {
         if ($srcAsset->getType() == assetType::FLAVOR) {
             /* @var $srcAsset flavorAsset */
             $dar = null;
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
             if ($mediaInfo) {
                 $dar = $mediaInfo->getVideoDar();
             }
             // generates the thumbnail
             $thumbMaker = new KFFMpegThumbnailMaker($srcPath, $destPath, kConf::get('bin_path_ffmpeg'));
             $created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), null, null, $dar);
             if (!$created || !file_exists($destPath)) {
                 $errDescription = "Thumbnail not captured";
                 return false;
             }
             $srcPath = $destPath;
             $uniqid = uniqid('thumb_');
             $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb';
             if (!file_exists($tempDir)) {
                 mkdir($tempDir, 0700, true);
             }
             $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . '.jpg';
         }
         if ($srcAsset->getType() == assetType::THUMBNAIL) {
             $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb';
             if (!file_exists($tempDir)) {
                 mkdir($tempDir, 0700, true);
             }
             $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . "." . $srcAsset->getFileExt();
         }
         $quality = $destThumbParamsOutput->getQuality();
         $cropType = $destThumbParamsOutput->getCropType();
         $cropX = $destThumbParamsOutput->getCropX();
         $cropY = $destThumbParamsOutput->getCropY();
         $cropWidth = $destThumbParamsOutput->getCropWidth();
         $cropHeight = $destThumbParamsOutput->getCropHeight();
         $bgcolor = $destThumbParamsOutput->getBackgroundColor();
         $width = $destThumbParamsOutput->getWidth();
         $height = $destThumbParamsOutput->getHeight();
         $scaleWidth = $destThumbParamsOutput->getScaleWidth();
         $scaleHeight = $destThumbParamsOutput->getScaleHeight();
         $density = $destThumbParamsOutput->getDensity();
         $stripProfiles = $destThumbParamsOutput->getStripProfiles();
         $cropper = new KImageMagickCropper($srcPath, $destPath, kConf::get('bin_path_imagemagick'), true);
         $cropped = $cropper->crop($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor, $density, $rotate, $stripProfiles);
         if (!$cropped || !file_exists($destPath)) {
             $errDescription = "Crop failed";
             return false;
         }
         return $destPath;
     } catch (Exception $ex) {
         $errDescription = $ex->getMessage();
         return false;
     }
 }
 private static function getExternalStorageUrl(Partner $partner, asset $asset, FileSyncKey $key, $storageId = null)
 {
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     if (is_null($storageId) && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) {
             // check if having file sync on kaltura dcs
             return null;
         }
     }
     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId);
     if (!$fileSync) {
         return null;
     }
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return null;
     }
     $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc(), $asset->getEntryId());
     $urlManager->setFileExtension($asset->getFileExt());
     $url = $storage->getDeliveryHttpBaseUrl() . '/' . $urlManager->getFileSyncUrl($fileSync);
     return $url;
 }