public static function handleFlavorReady(BatchJob $dbBatchJob, $flavorAssetId)
 {
     // verifies that flavor asset created
     if (!$flavorAssetId) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     $currentFlavorAsset = assetPeer::retrieveById($flavorAssetId);
     // verifies that flavor asset exists
     if (!$currentFlavorAsset) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     // if the flavor deleted then it shouldn't be taken into ready calculations
     if ($currentFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
         return $currentFlavorAsset;
     }
     //		Remarked because we want the original flavor ready behavior to work the same as other flavors
     //
     //		$rootBatchJob = $dbBatchJob->getRootJob();
     //
     //		// happens in case of post convert on the original (in case of bypass)
     //		if($rootBatchJob && $currentFlavorAsset->getIsOriginal())
     //		{
     //			kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
     //			return $dbBatchJob;
     //		}
     $sourceMediaInfo = mediaInfoPeer::retrieveOriginalByEntryId($dbBatchJob->getEntryId());
     $productMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
     $targetFlavor = assetParamsOutputPeer::retrieveByAssetId($currentFlavorAsset->getId());
     $postConvertData = $dbBatchJob->getData();
     $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR;
     if ($postConvertData instanceof kPostConvertJobData) {
         $postConvertAssetType = $postConvertData->getPostConvertAssetType();
     }
     // don't validate in case of bypass, in case target flavor or media info are null
     if ($postConvertAssetType != BatchJob::POSTCONVERT_ASSET_TYPE_BYPASS && $targetFlavor && $productMediaInfo) {
         try {
             $productFlavor = KDLWrap::CDLValidateProduct($sourceMediaInfo, $targetFlavor, $productMediaInfo);
         } catch (Exception $e) {
             KalturaLog::err('KDL Error: ' . print_r($e, true));
         }
         $err = kBusinessConvertDL::parseFlavorDescription($productFlavor);
         KalturaLog::debug("BCDL: job id [" . $dbBatchJob->getId() . "] flavor params output id [" . $targetFlavor->getId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "] desc: {$err}");
         if (!$productFlavor->IsValid()) {
             $description = $currentFlavorAsset->getDescription() . "\n{$err}";
             // mark the asset as ready
             $currentFlavorAsset->setDescription($description);
             $currentFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $currentFlavorAsset->save();
             if (!kConf::get('ignore_cdl_failure')) {
                 kJobsManager::failBatchJob($dbBatchJob, $err);
                 return null;
             }
         }
     }
     // mark the asset as ready
     $currentFlavorAsset->setStatusLocalReady();
     $currentFlavorAsset->save();
     kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $currentFlavorAsset->getFlavorParamsId());
     return $currentFlavorAsset;
 }
 public function entryHandled(entry $dbEntry)
 {
     parent::entryHandled($dbEntry);
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($dbEntry->getId());
     $syncKey = $originalFlavorAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $sourceFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     // call mediaInfo for file
     $dbMediaInfo = new mediaInfo();
     try {
         $mediaInfoParser = new KMediaInfoMediaParser($sourceFilePath, kConf::get('bin_path_mediainfo'));
         $mediaInfo = $mediaInfoParser->getMediaInfo();
         $dbMediaInfo = $mediaInfo->toInsertableObject($dbMediaInfo);
         $dbMediaInfo->setFlavorAssetId($originalFlavorAsset->getId());
         $dbMediaInfo->save();
     } catch (Exception $e) {
         KalturaLog::err("Getting media info: " . $e->getMessage());
         $dbMediaInfo = null;
     }
     // fix flavor asset according to mediainfo
     if ($dbMediaInfo) {
         KDLWrap::ConvertMediainfoCdl2FlavorAsset($dbMediaInfo, $originalFlavorAsset);
         $flavorTags = KDLWrap::CDLMediaInfo2Tags($dbMediaInfo, array(flavorParams::TAG_WEB, flavorParams::TAG_MBR));
         $originalFlavorAsset->setTags(implode(',', array_unique($flavorTags)));
     }
     $originalFlavorAsset->setStatusLocalReady();
     $originalFlavorAsset->save();
     $dbEntry->setStatus(entryStatus::READY);
     $dbEntry->save();
 }
コード例 #3
0
 /**
  * batch decideProfileConvert is the decision layer for a conversion profile
  * 
  * @param BatchJob $parentJob
  * @param BatchJob $convertProfileJob
  * @param int $mediaInfoId  
  * @return bool true if created all required conversions
  */
 public static function decideProfileConvert(BatchJob $parentJob, BatchJob $convertProfileJob, $mediaInfoId = null)
 {
     KalturaLog::log("Conversion decision layer used 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}");
         return false;
     }
     $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);
         return false;
     }
     $shouldConvert = true;
     // 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();
         return false;
     }
     $mediaInfo = null;
     if ($mediaInfoId) {
         $mediaInfo = mediaInfoPeer::retrieveByPK($mediaInfoId);
     }
     if ($profile->getCreationMode() == ConversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) {
         KalturaLog::log("The profile created from old conversion profile with bypass flv");
         $isFlv = false;
         if ($mediaInfo) {
             $isFlv = KDLWrap::CDLIsFLV($mediaInfo);
         }
         if ($isFlv && $originalFlavorAsset->hasTag(flavorParams::TAG_MBR)) {
             KalturaLog::log("The source is mbr and flv, conversion will be bypassed");
             $shouldConvert = false;
         } else {
             KalturaLog::log("The source is NOT mbr or flv, conversion will NOT be bypassed");
         }
     }
     // 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();
     $sourceFlavor = null;
     $flavors = flavorParamsPeer::retrieveByPKs($flavorsIds);
     foreach ($flavors as $index => $flavor) {
         if (isset($dynamicFlavorAttributes[$flavor->getId()])) {
             foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
         if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
             $sourceFlavor = $flavor;
             unset($flavors[$index]);
         }
     }
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!$sourceFlavor) {
         KalturaLog::log("Source flavor params not found");
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_TEMP);
         $originalFlavorAsset->save();
     } elseif ($shouldConvert) {
         KalturaLog::log("Source flavor params [" . $sourceFlavor->getId() . "] found");
         $originalFlavorAsset->setFlavorParamsId($sourceFlavor->getId());
         if ($sourceFlavor->getOperators() || $sourceFlavor->getConversionEngines()) {
             KalturaLog::log("Source flavor asset requires conversion");
             $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             $errDescription = null;
             $sourceFlavorOutput = self::validateFlavorAndMediaInfo($sourceFlavor, $mediaInfo, $errDescription);
             // save flavor params
             $sourceFlavorOutput->setPartnerId($sourceFlavorOutput->getPartnerId());
             $sourceFlavorOutput->setEntryId($entryId);
             $sourceFlavorOutput->setFlavorAssetId($originalFlavorAsset->getId());
             $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion());
             $sourceFlavorOutput->save();
             if ($errDescription) {
                 $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}");
             }
             $errDescription = kBusinessConvertDL::parseFlavorDescription($sourceFlavorOutput);
             if ($errDescription) {
                 $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}");
             }
             // decided by the business logic layer
             if ($sourceFlavorOutput->_create_anyway) {
                 KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] selected to be created anyway");
             } else {
                 if (!$sourceFlavorOutput->IsValid()) {
                     KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is invalid");
                     $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                     $originalFlavorAsset->save();
                     $errDescription = "Source flavor could not be converted";
                     KalturaLog::err($errDescription);
                     $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
                     kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
                     return false;
                 }
                 if ($sourceFlavorOutput->_force) {
                     KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is forced");
                 } elseif ($sourceFlavorOutput->_isNonComply) {
                     KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is none-comply");
                 } else {
                     KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is valid");
                 }
             }
             $originalFlavorAsset->incrementVersion();
             $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED);
             $originalFlavorAsset->addTags($sourceFlavor->getTagsArray());
             $originalFlavorAsset->setFileExt($sourceFlavorOutput->getFileExt());
             $originalFlavorAsset->save();
             // save flavor params
             $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion());
             $sourceFlavorOutput->save();
             kJobsManager::addFlavorConvertJob($srcSyncKey, $sourceFlavorOutput, $originalFlavorAsset->getId(), $mediaInfoId, $parentJob);
             return false;
         }
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_READY);
         $originalFlavorAsset->save();
         $entry->addFlavorParamsId($sourceFlavor->getId());
         $entry->save();
         kFlowHelper::generateThumbnailsFromFlavor($parentJob->getEntryId(), $parentJob);
     }
     if (!count($flavors)) {
         $shouldConvert = false;
     }
     if (!$shouldConvert) {
         self::bypassConversion($originalFlavorAsset, $entry, $convertProfileJob);
         return true;
     }
     return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo);
 }
コード例 #4
0
 public static function convertOperatorsKdl2Cdl($kdlOperators)
 {
     $cdlOprSets = new kOperatorSets();
     foreach ($kdlOperators as $transObj) {
         $auxArr = array();
         if (is_array($transObj)) {
             foreach ($transObj as $tr) {
                 $key = array_search($tr->_id, self::$TranscodersCdl2Kdl);
                 //					$opr = new kOperator();
                 //					if($key===false)
                 //						$opr->id = $tr->_id;
                 //					else
                 //						$opr->id = $key;
                 //					$opr->extra = $tr->_extra;
                 //					$opr->command = $tr->_cmd;
                 //					$opr->config = $tr->_cfg;
                 //					$auxArr[] = $opr;
                 $auxArr[] = KDLWrap::convertOperatorKdl2Cdl($tr, $key);
             }
         } else {
             $key = array_search($transObj->_id, self::$TranscodersCdl2Kdl);
             //				$opr = new kOperator();
             //				if($key===false)
             //					$opr->id = $transObj->_id;
             //				else
             //					$opr->id = $key;
             //				$opr->extra = $transObj->_extra;
             //				$opr->command = $transObj->_cmd;
             //				$opr->config = $transObj->_cfg;
             //				$auxArr[] = $opr;
             $auxArr[] = KDLWrap::convertOperatorKdl2Cdl($transObj, $key);
         }
         $cdlOprSets->addSet($auxArr);
     }
     return $cdlOprSets;
 }
 private function handleEntry($onlyExtractThumb, $prefix, $type, $entry_id, $name = null, $tags = null, $entry = null)
 {
     KalturaLog::debug("handleEntry({$type}, {$entry_id}, {$name})");
     $this->clear($prefix, $entry_id);
     $kuser_id = $this->kuser_id;
     $entry_data_prefix = $kuser_id . '_' . ($prefix == '' ? 'data' : rtrim($prefix, '_'));
     $uploads = myContentStorage::getFSUploadsPath();
     $content = myContentStorage::getFSContentRootPath();
     $media_source = $this->getParam('entry_media_source');
     $media_type = $this->getParam('entry_media_type');
     $entry_url = $this->getParam('entry_url');
     $entry_source_link = $this->getParam('entry_source_link');
     $entry_fileName = $this->getParam('entry_data');
     $entry_thumbNum = $this->getParam('entry_thumb_num', 0);
     $entry_thumbUrl = $this->getParam('entry_thumb_url', '');
     $should_copy = $this->getParam('should_copy', false);
     $skip_conversion = $this->getParam('skip_conversion', false);
     $webcam_suffix = $this->getParam('webcam_suffix', '');
     $duration = $this->getParam('duration', null);
     $entry_fullPath = "";
     $ext = null;
     $entry = null;
     if ($entry_id) {
         $entry = entryPeer::retrieveByPK($entry_id);
     } else {
         $entry = new entry();
     }
     $this->entry = $entry;
     $entry_status = $entry->getStatus();
     if (is_null($entry_status)) {
         $entry_status = entryStatus::READY;
     }
     // by the end of this block of code $entry_fullPath will point to the location of the entry
     // the entry status will be set (IMPORT / PRECONVERT / READY)
     // a background image is always previewed by the user no matter what source he used
     // so the entry is already in the /uploads directory
     // continue tracking the file upload
     $te = new TrackEntry();
     $te->setEntryId($entry_id);
     $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY);
     KalturaLog::debug("handleEntry: media_source: {$media_source}, prefix: {$prefix}");
     if ($media_source == entry::ENTRY_MEDIA_SOURCE_FILE || $prefix == 'bg_') {
         $full_path = $this->getParam('entry_full_path');
         if ($full_path) {
             $entry_fullPath = $full_path;
         } else {
             $entry_fullPath = $uploads . $entry_data_prefix . strrchr($entry_fileName, '.');
         }
         if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $entry_status = entryStatus::PRECONVERT;
         }
         $te->setParam3Str($entry_fullPath);
         $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_FILE");
     } else {
         if ($media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
             // set $entry_fileName to webcam output file and flag that conversion is not needed
             $webcam_basePath = $content . '/content/webcam/' . ($webcam_suffix ? $webcam_suffix : 'my_recorded_stream_' . $kuser_id);
             $entry_fullPath = $webcam_basePath . '.' . kWAMSWebcam::OUTPUT_FILE_EXT;
             $ext = kWAMSWebcam::OUTPUT_FILE_EXT;
             if (file_exists($entry_fullPath)) {
                 // continue tracking the webcam
                 $te->setParam3Str($entry_fullPath);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_WEBCAM");
             } else {
                 KalturaLog::err("File [{$entry_fullPath}] does not exist");
                 $entry_status = entryStatus::ERROR_IMPORTING;
             }
         } else {
             // if the url ends with .ext, we'll extract it this way
             $urlext = strrchr($entry_url, '.');
             // TODO: fix this patch
             if (strlen($urlext) > 4) {
                 $urlext = '.jpg';
             }
             // if we got something wierd, assume we're downloading a jpg
             $entry_fileName = $entry_data_prefix . $urlext;
             KalturaLog::debug("handleEntry: media_type: {$media_type}");
             if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
                 $duration = 0;
                 $entry_fullPath = $uploads . $entry_fileName;
                 if (!kFile::downloadUrlToFile($entry_url, $entry_fullPath)) {
                     KalturaLog::debug("Failed downloading file[{$entry_url}]");
                     $entry_status = entryStatus::ERROR_IMPORTING;
                 }
                 // track images
                 $te->setParam3Str($entry_fullPath);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_URL:ENTRY_MEDIA_TYPE_IMAGE");
             } else {
                 if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
                     //fixme - we can extract during import
                     $ext = "flv";
                 } else {
                     $ext = "mp3";
                 }
                 $entry_status = entryStatus::IMPORT;
                 // track images
                 $te->setParam3Str($ext);
                 $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_URL:ENTRY_MEDIA_TYPE_VIDEO");
             }
         }
     }
     if ($ext == null) {
         $entry_fullPathTmp = $entry_fullPath;
         $qpos = strpos($entry_fullPathTmp, "?");
         if ($qpos !== false) {
             $entry_fullPathTmp = substr($entry_fullPathTmp, 0, $qpos);
         }
         $ext = strtolower(pathinfo($entry_fullPathTmp, PATHINFO_EXTENSION));
     }
     // save the Trackentry
     TrackEntry::addTrackEntry($te);
     KalturaLog::debug("handleEntry: ext: {$ext}");
     //		We don't want to reject entries based on file extentions anumore
     //		Remarked by Tan-Tan
     //
     //		if ($entry_status == entryStatus::PRECONVERT && !myContentStorage::fileExtNeedConversion($ext))
     //		{
     //
     //			$this->errorMsg = "insertEntryAction Error - PRECONVERT file type not acceptable ($ext)";
     //			KalturaLog::debug("handleEntry: err: $this->errorMsg");
     //			if(is_null($entry) && $this->entry_id)
     //			{
     //				$entry = entryPeer::retrieveByPK($this->entry_id);
     //			}
     //			if($entry)
     //			{
     //				$entry->setStatus(entryStatus::ERROR_CONVERTING);
     //				$entry->save();
     //			}
     //			return false;
     //		}
     $media_date = null;
     //		We don't want to reject entries based on file extentions anumore
     //		Remarked by Tan-Tan
     //
     //		// if entry is ready, validate file type (webcam is an exception since we control the file type - flv)
     //		if ($entry_status == entryStatus::READY &&
     //			$media_source != entry::ENTRY_MEDIA_SOURCE_WEBCAM && !myContentStorage::fileExtAccepted($ext))
     //		{
     //			$this->errorMsg = "insertEntryAction Error - READY file type not acceptable ($ext)";
     //			KalturaLog::debug("handleEntry: err: $this->errorMsg");
     //			if(is_null($entry) && $this->entry_id)
     //			{
     //				$entry = entryPeer::retrieveByPK($this->entry_id);
     //			}
     //			if($entry)
     //			{
     //				$entry->setStatus(entryStatus::ERROR_CONVERTING);
     //				$entry->save();
     //			}
     //			return false;
     //		}
     if ($entry_status == entryStatus::ERROR_IMPORTING) {
         $need_thumb = false;
         // we wont be needing a thumb for an errornous entry
         KalturaLog::debug("handleEntry: error importing, thumb not needed");
     } else {
         // thumbs are created by one of the following ways:
         // 1. Image - images are already on disk for every selection method, so we can just create a thumb
         // 2. Audio - no thumb is needed
         // 3. Video -
         //		a. uploaded (file / webcam) - file is on disk and the user already selected a thumb
         //		b. imported - the source site had a thumbnail and we'll use it
         $thumbTempPrefix = $uploads . $entry_data_prefix . '_thumbnail_';
         $thumbBigFullPath = null;
         $need_thumb = $type == entryType::MEDIA_CLIP;
         KalturaLog::debug("handleEntry: handling media {$media_type}");
         if ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) {
             // fetch media creation date
             $exif_image_type = @exif_imagetype($entry_fullPath);
             if ($exif_image_type == IMAGETYPE_JPEG || $exif_image_type == IMAGETYPE_TIFF_II || $exif_image_type == IMAGETYPE_TIFF_MM || $exif_image_type == IMAGETYPE_IFF || $exif_image_type == IMAGETYPE_PNG) {
                 $exif_data = @exif_read_data($entry_fullPath);
                 if ($exif_data && isset($exif_data["DateTimeOriginal"]) && $exif_data["DateTimeOriginal"]) {
                     $media_date = $exif_data["DateTimeOriginal"];
                     $ts = strtotime($media_date);
                     // handle invalid dates either due to bad format or out of range
                     if ($ts === -1 || $ts === false || $ts < strtotime('2000-01-01') || $ts > strtotime('2015-01-01')) {
                         $media_date = null;
                     }
                 }
             }
             // create thumb
             $thumbFullPath = $thumbTempPrefix . '1.jpg';
             $entry_thumbNum = 1;
             $need_thumb = true;
             //copy($entry_fullPath, $thumbFullPath);
             myFileConverter::createImageThumbnail($entry_fullPath, $thumbFullPath, "image2");
             //$thumbBigFullPath = $thumbFullPath; // no filesync for thumbnail of image
         } else {
             if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO) {
                 if ($entry_status == entryStatus::IMPORT || $media_source == entry::ENTRY_MEDIA_SOURCE_URL) {
                     // import thumb and convert to our size
                     $thumbFullPath = $thumbTempPrefix . '1.jpg';
                     $entry_thumbNum = 1;
                     $importedThumbPath = $uploads . $entry_data_prefix . '_temp_thumb' . strrchr($entry_thumbUrl, '.');
                     if (kFile::downloadUrlToFile($entry_thumbUrl, $importedThumbPath)) {
                         myFileConverter::createImageThumbnail($importedThumbPath, $thumbFullPath, "image2");
                         // set thumb as big thumb so fileSync will be created.
                         $thumbBigFullPath = $thumbFullPath;
                     } else {
                         $need_thumb = false;
                     }
                 } else {
                     if ($entry_thumbNum == 0) {
                         $entry_thumbNum = 1;
                         $thumbTime = 3;
                         if ($duration && $duration < $thumbTime * 1000) {
                             $thumbTime = floor($duration / 1000);
                         }
                         // for videos - thumbail should be created in post convert
                         // otherwise this code will fail if the thumbanil wasn't created successfully (roman)
                         //myFileConverter::autoCaptureFrame($entry_fullPath, $thumbTempPrefix."big_", $thumbTime, -1, -1);
                         $need_thumb = false;
                         $thumbBigFullPath = $thumbTempPrefix . "big_" . $entry_thumbNum . '.jpg';
                     }
                 }
                 //else select existing thumb ($entry_thumbNum already points to the right thumbnail)
             }
         }
         $thumbFullPath = $thumbTempPrefix . $entry_thumbNum . '.jpg';
         // if we arrived here both entry and thumbnail are valid we can now update the db
         // in order to have the final entry_id and move its data to its final destination
         if ($onlyExtractThumb) {
             return $thumbFullPath;
         }
     }
     $entry->setkshowId($this->kshow_id);
     $entry->setKuserId($kuser_id);
     $entry->setCreatorKuserId($kuser_id);
     if ($this->partner_id != null) {
         $entry->setPartnerId($this->partner_id);
         $entry->setSubpId($this->subp_id);
     }
     $entry->setName($name ? $name : $this->getParam('entry_name'));
     //		$entry->setDescription('');//$this->getParam('entry_description'));
     $entry->setType($type);
     $entry->setMediaType($media_type);
     $entry->setTags($tags ? $tags : $this->getParam('entry_tags'));
     $entry->setSource($media_source);
     $entry->setSourceId($this->getParam('entry_media_id'));
     if ($media_date) {
         $entry->setMediaDate($media_date);
     }
     // if source_link wasnt given use the entry_url HOWEVER, use it only if id doesnt contain @ which suggests the use of a password
     $entry->setSourceLink($entry_source_link ? $entry_source_link : (strstr($entry_url, '@') ? "" : $entry_url));
     if ($media_source == entry::ENTRY_MEDIA_SOURCE_FILE) {
         $entry->setSourceLink("file:{$entry_fullPath}");
     }
     $entry->setLicenseType($this->getParam('entry_license'));
     $entry->setCredit($this->getParam('entry_credit'));
     $entry->setStatus($entry_status);
     if ($duration !== null) {
         $entry->setLengthInMsecs($duration);
     }
     if ($this->entry_id == 0) {
         $entry->save();
         $this->entry_id = $entry->getId();
     }
     // move thumb to final destination and set db entry
     if ($media_type != entry::ENTRY_MEDIA_TYPE_AUDIO && $entry_thumbNum && $need_thumb) {
         KalturaLog::debug("handleEntry: saving none audio thumb [{$thumbBigFullPath}]");
         $entry->setThumbnail('.jpg');
         if ($thumbBigFullPath) {
             if ($media_type != entry::ENTRY_MEDIA_TYPE_IMAGE) {
                 myFileConverter::convertImage($thumbBigFullPath, $thumbFullPath);
             }
             /*$thumbBigFinalPath = $content.$entry->getBigThumbnailPath();
             		myContentStorage::moveFile($thumbBigFullPath, $thumbBigFinalPath, true , $should_copy );
             		*/
             $entryThumbKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             try {
                 if (!$should_copy) {
                     kFileSyncUtils::moveFromFile($thumbBigFullPath, $entryThumbKey);
                 } else {
                     kFileSyncUtils::copyFromFile($thumbBigFullPath, $entryThumbKey);
                 }
             } catch (Exception $e) {
                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                 $entry->save();
                 throw $e;
             }
         }
     }
     // after extracting the thumb we can move the entry to its next destination
     KalturaLog::debug("handleEntry: current status [" . $entry->getStatus() . "]");
     // if needed a job will be submitted for importing external media sources
     if ($entry->getStatus() == entryStatus::IMPORT) {
         KalturaLog::debug("handleEntry: creating import job");
         // changed by Tan-Tan, Nov 09 to support the new batch mechanism
         kJobsManager::addImportJob(null, $this->entry_id, $this->partner_id, $entry_url);
         // remarked by Tan-Tan
         //			$entry_fullPath = $content.'/content/imports/data/'.$this->entry_id.".".$ext;
         //			myContentStorage::fullMkdir($entry_fullPath);
         //
         //			$batchClient = new myBatchUrlImportClient();
         // 			$batchClient->addJob($this->entry_id, $entry_url, $entry_fullPath);
     } else {
         if ($entry->getStatus() == entryStatus::PRECONVERT) {
             if (!$skip_conversion) {
                 // changed by Tan-Tan, Dec 09 to support the new batch mechanism
                 KalturaLog::debug("handleEntry: creating original flavor asset for pre convert");
                 $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                 if ($flavorAsset) {
                     $flavorAsset->setFileExt($ext);
                     $flavorAsset->save();
                     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     try {
                         kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                     } catch (Exception $e) {
                         $entry->setStatus(entryStatus::ERROR_CONVERTING);
                         $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                         $entry->save();
                         $flavorAsset->save();
                         throw $e;
                     }
                     kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                 } else {
                     $entry->setStatus(entryStatus::ERROR_CONVERTING);
                 }
                 //				Remarked by Tan-Tan
                 //				$targetFileName = $this->entry_id.".".$ext;
                 //				if ( false /* old conversion */)
                 //				{
                 //								// if we need to convert move entry to conversion directory
                 //								$preConvPath = $content.'/content/preconvert/';
                 //								myContentStorage::moveFile($entry_fullPath, $preConvPath."data/".$targetFileName, true , $should_copy );
                 //
                 //								$signalFilePath = $preConvPath."files/".$targetFileName;
                 //								myContentStorage::fullMkdir($signalFilePath);
                 //								touch($signalFilePath);
                 //				}
                 //				else
                 //				{
                 //								$preConvPath = myContentStorage::getFSContentRootPath (). "/content/new_preconvert";
                 //								$to_data = $preConvPath . "/$targetFileName" ;
                 //								myContentStorage::moveFile($entry_fullPath, $to_data , true);
                 //								touch ( $to_data . ".indicator" );
                 //				}
             }
         } else {
             if ($entry->getStatus() == entryStatus::PENDING || $media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
                 $entry->setData($entry_fullPath);
                 $entry->save();
                 if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO || $media_type == entry::ENTRY_MEDIA_TYPE_AUDIO) {
                     KalturaLog::debug("handleEntry: creating original flavor asset for ready entry");
                     $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                     if ($flavorAsset) {
                         $ext = pathinfo($entry_fullPath, PATHINFO_EXTENSION);
                         $flavorAsset->setFileExt($ext);
                         $flavorAsset->save();
                         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                         try {
                             if (!$should_copy) {
                                 kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                             } else {
                                 // copy & create file sync from $entry_fullPath
                                 kFileSyncUtils::copyFromFile($entry_fullPath, $syncKey);
                             }
                         } catch (Exception $e) {
                             $entry->setStatus(entryStatus::ERROR_CONVERTING);
                             $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                             $entry->save();
                             $flavorAsset->save();
                             throw $e;
                         }
                         //					// bypass to conversion
                         //					kBusinessPreConvertDL::bypassConversion($flavorAsset, $entry);
                         /**
                          * if this is webcam entry, create mediaInfo for the source flavor asset synchronously
                          * since entry is ready right at the beginning
                          */
                         if ($media_source == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
                             require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "api_v3" . DIRECTORY_SEPARATOR . "bootstrap.php";
                             // extract file path
                             $sourceFileKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             $sourceFilePath = kFileSyncUtils::getLocalFilePathForKey($sourceFileKey);
                             // call mediaInfo for file
                             $mediaInfo = new mediaInfo();
                             try {
                                 $mediaInfoParser = new KMediaInfoMediaParser($sourceFilePath, kConf::get('bin_path_mediainfo'));
                                 $KalturaMediaInfo = new KalturaMediaInfo();
                                 $KalturaMediaInfo = $mediaInfoParser->getMediaInfo();
                                 $mediaInfo = $KalturaMediaInfo->toInsertableObject($mediaInfo);
                                 $mediaInfo->setFlavorAssetId($flavorAsset->getId());
                                 $mediaInfo->save();
                             } catch (Exception $e) {
                                 KalturaLog::err("Getting media info: " . $e->getMessage());
                                 $mediaInfo = null;
                             }
                             // fix flavor asset according to mediainfo
                             if ($mediaInfo) {
                                 KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfo, $flavorAsset);
                                 $flavorTags = KDLWrap::CDLMediaInfo2Tags($mediaInfo, array(flavorParams::TAG_WEB, flavorParams::TAG_MBR));
                                 $flavorAsset->setTags(implode(',', $flavorTags));
                             }
                             $flavorAsset->save();
                         }
                         kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                         $flavorAsset->setStatusLocalReady();
                         $flavorAsset->save();
                     } else {
                         $entry->setStatus(entryStatus::ERROR_IMPORTING);
                     }
                 } else {
                     if ($entry->getType() == entryType::DOCUMENT) {
                         //TODO: document should be handled by the plugin manager)
                         KalturaLog::debug("handleEntry: creating original flavor asset for ready entry");
                         $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->partner_id, $this->entry_id);
                         if ($flavorAsset) {
                             $ext = pathinfo($entry_fullPath, PATHINFO_EXTENSION);
                             $flavorAsset->setFileExt($ext);
                             $flavorAsset->save();
                             $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             try {
                                 if (!$should_copy) {
                                     kFileSyncUtils::moveFromFile($entry_fullPath, $syncKey);
                                 } else {
                                     // copy & create file sync from $entry_fullPath
                                     kFileSyncUtils::copyFromFile($entry_fullPath, $syncKey);
                                 }
                             } catch (Exception $e) {
                                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                                 $entry->save();
                                 $flavorAsset->save();
                                 throw $e;
                             }
                             kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset));
                         }
                     } else {
                         KalturaLog::debug("handleEntry: creating data file sync for file [{$entry_fullPath}]");
                         $entryDataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
                         if (!kFileSyncUtils::file_exists($entryDataKey)) {
                             try {
                                 if (!$should_copy) {
                                     kFileSyncUtils::moveFromFile($entry_fullPath, $entryDataKey);
                                 } else {
                                     // copy & create file sync from $entry_fullPath
                                     kFileSyncUtils::copyFromFile($entry_fullPath, $entryDataKey);
                                 }
                             } catch (Exception $e) {
                                 $entry->setStatus(entryStatus::ERROR_CONVERTING);
                                 $entry->save();
                                 throw $e;
                             }
                         }
                         $entry->setStatus(entryStatus::READY);
                         $entry->save();
                     }
                 }
                 //			Remarked by Tan-Tan, the flavor asset should be synced instead of the entry
                 //
                 //			$entryDataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
                 //			if(!$should_copy)
                 //			{
                 //				kFileSyncUtils::moveFromFile($entry_fullPath, $entryDataKey);
                 //			}
                 //			else
                 //			{
                 //				// copy & create file sync from $entry_fullPath
                 //				kFileSyncUtils::copyFromFile($entry_fullPath, $entryDataKey);
                 //			}
             }
         }
     }
     if ($entry->getStatus() == entryStatus::READY) {
         $entry->updateDimensions();
     }
     $entry->save();
     return true;
 }
コード例 #6
0
 private static function shouldConvertProfileFlavors(conversionProfile2 $profile, mediaInfo $mediaInfo = null, flavorAsset $originalFlavorAsset)
 {
     $shouldConvert = true;
     if ($profile->getCreationMode() == conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) {
         KalturaLog::log("The profile created from old conversion profile with bypass flv");
         $isFlv = false;
         if ($mediaInfo) {
             $isFlv = KDLWrap::CDLIsFLV($mediaInfo);
         }
         if ($isFlv && $originalFlavorAsset->hasTag(flavorParams::TAG_MBR)) {
             KalturaLog::log("The source is mbr and flv, conversion will be bypassed");
             $shouldConvert = false;
         } else {
             KalturaLog::log("The source is NOT mbr or flv, conversion will NOT be bypassed");
         }
     }
     return $shouldConvert;
 }
コード例 #7
0
ファイル: kJobsManager.php プロジェクト: ace3535/server
 /**
  * addConvertIsmCollectionJob creates a convert collection job 
  * 
  * @param string $tag 
  * @param FileSyncKey $srcSyncKey
  * @param entry $entry
  * @param BatchJob $parentJob
  * @param array<flavorParamsOutput> $flavorParamsOutputs
  * @return BatchJob
  */
 public static function addConvertIsmCollectionJob($tag, FileSyncKey $srcSyncKey, entry $entry, BatchJob $parentJob = null, array $flavorParamsOutputs, $sameRoot = null)
 {
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     $srcFileSyncDescriptor = new kSourceFileSyncDescriptor();
     if ($fileSync) {
         if ($fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
             $srcFileSyncDescriptor->setFileSyncLocalPath($fileSync->getFullPath());
         }
         $srcFileSyncDescriptor->setFileSyncRemoteUrl($fileSync->getExternalUrl($entry->getId()));
         $srcFileSyncDescriptor->setAssetId($fileSync->getObjectId());
         $srcFileSyncDescriptor->setFileSyncObjectSubType($srcSyncKey->getObjectSubType());
     }
     // increment entry version
     $ismVersion = $entry->incrementIsmVersion();
     $entry->save();
     $fileName = $entry->generateFileName(0, $ismVersion);
     // creates convert data
     $convertCollectionData = new kConvertCollectionJobData();
     $convertCollectionData->setSrcFileSyncs(array($srcFileSyncDescriptor));
     $convertCollectionData->setDestFileName($fileName);
     $clipOffset = null;
     $clipDuration = null;
     // look for clipping params
     foreach ($flavorParamsOutputs as $flavorParamsOutput) {
         $clipOffset = $flavorParamsOutput->getClipOffset();
         $clipDuration = $flavorParamsOutput->getClipDuration();
         if (isset($clipOffset) || isset($clipDuration)) {
             KalturaLog::log("Found clipping params: clipOffset({$clipOffset}),clipDuration({$clipDuration})");
             break;
         }
     }
     // check bitrates duplications & update clipping params
     foreach ($flavorParamsOutputs as $flavorParamsOutputIndex => $flavorParamsOutput) {
         // if one of clip params exsits - update the object and db
         if (isset($clipOffset)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->setClipOffset($clipOffset);
         }
         if (isset($clipDuration)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->setClipDuration($clipDuration);
         }
         if (isset($clipOffset) || isset($clipDuration)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->save();
         }
     }
     /*
      * Put together all separted flavor XML's into a single Smooth Streaming preset file
      */
     KalturaLog::log("Calling CDLProceessFlavorsForCollection with [" . count($flavorParamsOutputs) . "] flavor params");
     $presetXml = KDLWrap::CDLProceessFlavorsForCollection($flavorParamsOutputs);
     $presetXml = str_replace(KDLCmdlinePlaceholders::OutFileName, $fileName, $presetXml);
     foreach ($flavorParamsOutputs as $flavorParamsOutput) {
         /*
          * Save in case that videoBitrate was changed by the FlavorsForCollection (see above)
          */
         $flavorParamsOutput->save();
         $convertCollectionFlavorData = new kConvertCollectionFlavorData();
         $convertCollectionFlavorData->setFlavorAssetId($flavorParamsOutput->getFlavorAssetId());
         $convertCollectionFlavorData->setFlavorParamsOutputId($flavorParamsOutput->getId());
         $convertCollectionFlavorData->setReadyBehavior($flavorParamsOutput->getReadyBehavior());
         $convertCollectionFlavorData->setVideoBitrate($flavorParamsOutput->getVideoBitrate());
         $convertCollectionFlavorData->setAudioBitrate($flavorParamsOutput->getAudioBitrate());
         $convertCollectionFlavorData->setAudioBitrate($flavorParamsOutput->getAudioBitrate());
         $convertCollectionData->addFlavor($convertCollectionFlavorData);
     }
     $currentConversionEngine = conversionEngineType::EXPRESSION_ENCODER3;
     KalturaLog::log("Using conversion engine [{$currentConversionEngine}]");
     if ($sameRoot == null) {
         // creats a child convert job
         if ($parentJob) {
             $dbConvertCollectionJob = $parentJob->createChild(BatchJobType::CONVERT_COLLECTION, $currentConversionEngine);
             KalturaLog::log("Created from parent convert job with entry id [" . $dbConvertCollectionJob->getEntryId() . "]");
         } else {
             $dbConvertCollectionJob = new BatchJob();
             $dbConvertCollectionJob->setEntryId($entry->getId());
             $dbConvertCollectionJob->setPartnerId($entry->getPartnerId());
             $dbConvertCollectionJob->setJobType(BatchJobType::CONVERT_COLLECTION);
             $dbConvertCollectionJob->setJobSubType($currentConversionEngine);
         }
     } else {
         $dbConvertCollectionJob = $parentJob->createChild(BatchJobType::CONVERT_COLLECTION, $currentConversionEngine, false);
     }
     $dbConvertCollectionJob->setObjectId($entry->getId());
     $dbConvertCollectionJob->setObjectType(BatchJobObjectType::ENTRY);
     $dbConvertCollectionJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     $dbConvertCollectionJob = kJobsManager::addJob($dbConvertCollectionJob, $convertCollectionData, BatchJobType::CONVERT_COLLECTION, $currentConversionEngine);
     $syncKey = $dbConvertCollectionJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG);
     kFileSyncUtils::file_put_contents($syncKey, $presetXml);
     $fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey);
     $remoteUrl = $fileSync->getExternalUrl($entry->getId());
     $localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     $commandLines = array(conversionEngineType::EXPRESSION_ENCODER3 => KDLCmdlinePlaceholders::InFileName . ' ' . KDLCmdlinePlaceholders::ConfigFileName);
     $commandLinesStr = flavorParamsOutput::buildCommandLinesStr($commandLines);
     $convertCollectionData->setInputXmlLocalPath($localPath);
     $convertCollectionData->setInputXmlRemoteUrl($remoteUrl);
     $convertCollectionData->setCommandLinesStr($commandLinesStr);
     $dbConvertCollectionJob->setData($convertCollectionData);
     return kJobsManager::updateBatchJob($dbConvertCollectionJob, BatchJob::BATCHJOB_STATUS_PENDING);
 }
コード例 #8
0
 public static function handleFlavorReady(BatchJob $dbBatchJob, $flavorAssetId)
 {
     // verifies that flavor asset created
     if (!$flavorAssetId) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     $currentFlavorAsset = assetPeer::retrieveById($flavorAssetId);
     // verifies that flavor asset exists
     if (!$currentFlavorAsset) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     // if the flavor deleted then it shouldn't be taken into ready calculations
     if ($currentFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
         return $currentFlavorAsset;
     }
     //		Remarked because we want the original flavor ready behavior to work the same as other flavors
     //
     //		$rootBatchJob = $dbBatchJob->getRootJob();
     //
     //		// happens in case of post convert on the original (in case of bypass)
     //		if($rootBatchJob && $currentFlavorAsset->getIsOriginal())
     //		{
     //			kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
     //			return $dbBatchJob;
     //		}
     $sourceMediaInfo = mediaInfoPeer::retrieveOriginalByEntryId($dbBatchJob->getEntryId());
     /*
      * For intermediate source generation, both the source and the asset have the same asset id.
      * In this case sourceMediaInfo should be retrieved as the first version of source asset mediaInfo 
      */
     if (isset($sourceMediaInfo) && $sourceMediaInfo->getFlavorAssetId() == $flavorAssetId) {
         $productMediaInfo = $sourceMediaInfo;
         $entry = $dbBatchJob->getEntry();
         $operationAttributes = $entry->getOperationAttributes();
         // if in clipping operation - take the latest created mediainfo object
         $ascending = empty($operationAttributes) ? 1 : 0;
         $sourceMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAssetId, $ascending);
         KalturaLog::log("Intermediate source generation - assetId(" . $flavorAssetId . "),src MdInf id(" . $sourceMediaInfo->getId() . "),product MdInf id(" . $productMediaInfo->getId()) . ")";
     } else {
         $productMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
     }
     $targetFlavor = assetParamsOutputPeer::retrieveByAssetId($currentFlavorAsset->getId());
     //Retrieve convert job executing engien
     $convertEngineType = null;
     if ($dbBatchJob->getParentJob()) {
         $dbParentBatchJob = $dbBatchJob->getParentJob();
         if ($dbParentBatchJob->getJobType() == BatchJobType::CONVERT) {
             $convertEngineType = $dbParentBatchJob->getJobSubType();
         }
     }
     $postConvertData = $dbBatchJob->getData();
     $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR;
     if ($postConvertData instanceof kPostConvertJobData) {
         $postConvertAssetType = $postConvertData->getPostConvertAssetType();
     }
     // don't validate in case of bypass, in case target flavor or media info are null
     // or ISM/ISMC manifest assets
     if ($postConvertAssetType != BatchJob::POSTCONVERT_ASSET_TYPE_BYPASS && $targetFlavor && $productMediaInfo && !$targetFlavor->hasTag(assetParams::TAG_ISM_MANIFEST)) {
         try {
             $productFlavor = KDLWrap::CDLValidateProduct($sourceMediaInfo, $targetFlavor, $productMediaInfo, $convertEngineType);
         } catch (Exception $e) {
             KalturaLog::err('KDL Error: ' . print_r($e, true));
         }
         $err = kBusinessConvertDL::parseFlavorDescription($productFlavor);
         KalturaLog::debug("BCDL: job id [" . $dbBatchJob->getId() . "] flavor params output id [" . $targetFlavor->getId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "] desc: {$err}");
         if (!$productFlavor->IsValid()) {
             $description = $currentFlavorAsset->getDescription() . "\n{$err}";
             // mark the asset as ready
             $currentFlavorAsset->setDescription($description);
             $currentFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $currentFlavorAsset->save();
             if (!kConf::get('ignore_cdl_failure')) {
                 kJobsManager::failBatchJob($dbBatchJob, $err);
                 return null;
             }
         }
     }
     // mark the asset as ready
     $currentFlavorAsset->setStatusLocalReady();
     $currentFlavorAsset->save();
     $waitingFlavorAssets = assetPeer::retrieveByEntryIdAndStatus($currentFlavorAsset->getEntryId(), flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT);
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($currentFlavorAsset->getEntryId());
     foreach ($waitingFlavorAssets as $waitingFlavorAsset) {
         $flavor = assetParamsOutputPeer::retrieveByAsset($waitingFlavorAsset);
         KalturaLog::debug('Check waiting flavor asset [' . $waitingFlavorAsset->getId() . ']');
         if ($dbBatchJob->getParentJob()) {
             $parentJob = $dbBatchJob->getParentJob();
         } else {
             $parentJob = $dbBatchJob;
         }
         kBusinessPreConvertDL::decideFlavorConvert($waitingFlavorAsset, $flavor, $originalFlavorAsset, null, null, $parentJob);
     }
     kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $currentFlavorAsset->getFlavorParamsId());
     if ($currentFlavorAsset->getIsOriginal()) {
         $entry = $currentFlavorAsset->getentry();
         if ($entry) {
             kBusinessConvertDL::checkForPendingLiveClips($entry);
         }
     }
     return $currentFlavorAsset;
 }
コード例 #9
0
ファイル: kBatchManager.php プロジェクト: DBezemer/server
 /**
  * batch addMediaInfo adds a media info and updates the flavor asset 
  * 
  * @param mediaInfo $mediaInfoDb  
  * @return mediaInfo 
  */
 public static function addMediaInfo(mediaInfo $mediaInfoDb)
 {
     $mediaInfoDb->save();
     KalturaLog::log("Added media info [" . $mediaInfoDb->getId() . "] for flavor asset [" . $mediaInfoDb->getFlavorAssetId() . "]");
     if (!$mediaInfoDb->getFlavorAssetId()) {
         return $mediaInfoDb;
     }
     $flavorAsset = assetPeer::retrieveById($mediaInfoDb->getFlavorAssetId());
     if (!$flavorAsset) {
         return $mediaInfoDb;
     }
     if ($flavorAsset->getIsOriginal()) {
         KalturaLog::log("Media info is for the original flavor asset");
         $tags = null;
         $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId());
         if ($profile) {
             $tags = $profile->getInputTagsMap();
         }
         KalturaLog::log("Flavor asset tags from profile [{$tags}]");
         if (!is_null($tags)) {
             $tagsArray = explode(',', $tags);
             // support for old migrated profiles
             if ($profile->getCreationMode() == conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) {
                 if (!KDLWrap::CDLIsFLV($mediaInfoDb)) {
                     $key = array_search(flavorParams::TAG_MBR, $tagsArray);
                     if ($key !== false) {
                         unset($tagsArray[$key]);
                     }
                 }
             }
             $finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', array_unique($finalTagsArray));
             KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]");
             //KalturaLog::log("Flavor asset tags [".print_r($flavorAsset->setTags(),1)."]");
             $flavorAsset->addTags($finalTagsArray);
         }
     } else {
         KalturaLog::log("Media info is for the destination flavor asset");
         $tags = null;
         $flavorParams = assetParamsPeer::retrieveByPK($flavorAsset->getFlavorParamsId());
         if ($flavorParams) {
             $tags = $flavorParams->getTags();
         }
         KalturaLog::log("Flavor asset tags from flavor params [{$tags}]");
         if (!is_null($tags)) {
             $tagsArray = explode(',', $tags);
             $assetTagsArray = $flavorAsset->getTagsArray();
             foreach ($assetTagsArray as $tag) {
                 $tagsArray[] = $tag;
             }
             $maxMbrBitrate = 8000;
             if (kConf::hasParam('max_mbr_flavor_bitrate')) {
                 $maxMbrBitrate = kConf::get('max_mbr_flavor_bitrate');
             }
             if ($mediaInfoDb->getContainerBitRate() >= $maxMbrBitrate) {
                 $tagsArray = array_unique($tagsArray);
                 $key = array_search(flavorParams::TAG_MBR, $tagsArray);
                 if ($key !== false) {
                     unset($tagsArray[$key]);
                 }
             }
             $finalTagsArray = $tagsArray;
             //				bypass, KDLWrap::CDLMediaInfo2Tags doesn't support destination flavors and mobile tags
             //				$finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', array_unique($finalTagsArray));
             KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]");
             $flavorAsset->setTags($finalTags);
         }
     }
     KalturaLog::log("KDLWrap::ConvertMediainfoCdl2FlavorAsset(" . $mediaInfoDb->getId() . ", " . $flavorAsset->getId() . ");");
     KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfoDb, $flavorAsset);
     $flavorAsset->save();
     //		if(!$flavorAsset->hasTag(flavorParams::TAG_MBR))
     //			return $mediaInfoDb;
     $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId());
     if (!$entry) {
         return $mediaInfoDb;
     }
     $contentDuration = $mediaInfoDb->getContainerDuration();
     if (!$contentDuration) {
         $contentDuration = $mediaInfoDb->getVideoDuration();
         if (!$contentDuration) {
             $contentDuration = $mediaInfoDb->getAudioDuration();
         }
     }
     if ($contentDuration && $entry->getCalculateDuration()) {
         $entry->setLengthInMsecs($contentDuration);
     }
     if ($mediaInfoDb->getVideoWidth() && $mediaInfoDb->getVideoHeight()) {
         $entry->setDimensionsIfBigger($mediaInfoDb->getVideoWidth(), $mediaInfoDb->getVideoHeight());
     }
     $entry->save();
     return $mediaInfoDb;
 }
コード例 #10
0
 /**
  * 
  * Tests the KDLWrapCDLValidateProduct method
  * @param mediaInfo $cdlSourceMediaInfo
  * @param flavorParamsOutput $cdlTarget
  * @param mediaInfo $cdlProductMediaInfo
  * @dataProvider provideData
  */
 public function testKDLWrapCDLValidateProduct(mediaInfo $cdlSourceMediaInfo, flavorParamsOutput $cdlTarget, mediaInfo $cdlProductMediaInfo)
 {
     $result = KDLWrap::CDLValidateProduct($cdlSourceMediaInfo, $cdlTarget, $cdlProductMediaInfo);
     //assert that 0 errors were generated
     $this->assertEquals(0, count($result->_errors));
 }
コード例 #11
0
 /**
  * addConvertIsmCollectionJob creates a convert collection job 
  * 
  * @param string $tag 
  * @param FileSyncKey $srcSyncKey
  * @param entry $entry
  * @param BatchJob $parentJob
  * @param array<flavorParamsOutput> $flavorParamsOutputs
  * @return BatchJob
  */
 public static function addConvertIsmCollectionJob($tag, FileSyncKey $srcSyncKey, entry $entry, BatchJob $parentJob = null, array $flavorParamsOutputs, $dbConvertCollectionJob = null)
 {
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     $localPath = null;
     $remoteUrl = null;
     if ($fileSync) {
         if ($fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
             $localPath = $fileSync->getFullPath();
         }
         $remoteUrl = $fileSync->getExternalUrl($entry->getId());
     }
     // increment entry version
     $ismVersion = $entry->incrementIsmVersion();
     $entry->save();
     $fileName = $entry->generateFileName(0, $ismVersion);
     // creates convert data
     $convertCollectionData = new kConvertCollectionJobData();
     $convertCollectionData->setSrcFileSyncLocalPath($localPath);
     $convertCollectionData->setSrcFileSyncRemoteUrl($remoteUrl);
     $convertCollectionData->setDestFileName($fileName);
     $clipOffset = null;
     $clipDuration = null;
     // look for clipping params
     foreach ($flavorParamsOutputs as $flavorParamsOutput) {
         $clipOffset = $flavorParamsOutput->getClipOffset();
         $clipDuration = $flavorParamsOutput->getClipDuration();
         if (isset($clipOffset) || isset($clipDuration)) {
             KalturaLog::log("Found clipping params: clipOffset({$clipOffset}),clipDuration({$clipDuration})");
             break;
         }
     }
     $bitrates = array();
     $finalFlavorParamsOutputs = array();
     // check bitrates duplications & update clipping params
     foreach ($flavorParamsOutputs as $flavorParamsOutputIndex => $flavorParamsOutput) {
         if (!isset($bitrates[$flavorParamsOutput->getVideoBitrate()])) {
             $bitrates[$flavorParamsOutput->getVideoBitrate()] = array();
         }
         // if one of clip params exsits - update the object and db
         if (isset($clipOffset)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->setClipOffset($clipOffset);
         }
         if (isset($clipDuration)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->setClipDuration($clipDuration);
         }
         if (isset($clipOffset) || isset($clipDuration)) {
             $flavorParamsOutputs[$flavorParamsOutputIndex]->save();
         }
         $bitrates[$flavorParamsOutput->getVideoBitrate()][] = $flavorParamsOutput->getId();
         $finalFlavorParamsOutputs[$flavorParamsOutput->getId()] = $flavorParamsOutput;
     }
     foreach ($bitrates as $bitrate => $flavorParamsOutputIds) {
         if (count($flavorParamsOutputIds) == 1) {
             // no bitrate dupliaction
             continue;
         }
         $tempFlavorParamsOutputs = array();
         foreach ($flavorParamsOutputIds as $index => $flavorParamsOutputId) {
             $tempFlavorParamsOutputs[] = $finalFlavorParamsOutputs[$flavorParamsOutputId];
         }
         // sort the flavors by height
         usort($tempFlavorParamsOutputs, array('kBusinessConvertDL', 'compareFlavorsByHeight'));
         // increment the bitrate so it will be a bit different for each flavor
         $index = 0;
         foreach ($tempFlavorParamsOutputs as $flavorParamsOutput) {
             $finalFlavorParamsOutputs[$flavorParamsOutput->getId()]->setVideoBitrate($bitrate + $index++);
         }
     }
     foreach ($finalFlavorParamsOutputs as $flavorParamsOutput) {
         $convertCollectionFlavorData = new kConvertCollectionFlavorData();
         $convertCollectionFlavorData->setFlavorAssetId($flavorParamsOutput->getFlavorAssetId());
         $convertCollectionFlavorData->setFlavorParamsOutputId($flavorParamsOutput->getId());
         $convertCollectionFlavorData->setReadyBehavior($flavorParamsOutput->getReadyBehavior());
         $convertCollectionFlavorData->setVideoBitrate($flavorParamsOutput->getVideoBitrate());
         $convertCollectionFlavorData->setAudioBitrate($flavorParamsOutput->getAudioBitrate());
         $convertCollectionFlavorData->setAudioBitrate($flavorParamsOutput->getAudioBitrate());
         $convertCollectionData->addFlavor($convertCollectionFlavorData);
     }
     $currentConversionEngine = conversionEngineType::EXPRESSION_ENCODER3;
     KalturaLog::log("Using conversion engine [{$currentConversionEngine}]");
     if (!$dbConvertCollectionJob) {
         // creats a child convert job
         if ($parentJob) {
             $dbConvertCollectionJob = $parentJob->createChild();
             KalturaLog::log("Created from parent convert job with entry id [" . $dbConvertCollectionJob->getEntryId() . "]");
         } else {
             $dbConvertCollectionJob = new BatchJob();
             $dbConvertCollectionJob->setEntryId($entry->getId());
             $dbConvertCollectionJob->setPartnerId($entry->getPartnerId());
             $dbConvertCollectionJob->save();
             KalturaLog::log("Created from convert collection job with entry id [" . $dbConvertCollectionJob->getEntryId() . "]");
         }
     }
     KalturaLog::log("Calling CDLProceessFlavorsForCollection with [" . count($finalFlavorParamsOutputs) . "] flavor params");
     $xml = KDLWrap::CDLProceessFlavorsForCollection($finalFlavorParamsOutputs);
     $xml = str_replace(KDLCmdlinePlaceholders::OutFileName, $fileName, $xml);
     $syncKey = $dbConvertCollectionJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG);
     kFileSyncUtils::file_put_contents($syncKey, $xml);
     $fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey);
     $remoteUrl = $fileSync->getExternalUrl($entry->getId());
     $localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     $commandLines = array(conversionEngineType::EXPRESSION_ENCODER3 => KDLCmdlinePlaceholders::InFileName . ' ' . KDLCmdlinePlaceholders::ConfigFileName);
     $commandLinesStr = flavorParamsOutput::buildCommandLinesStr($commandLines);
     $convertCollectionData->setInputXmlLocalPath($localPath);
     $convertCollectionData->setInputXmlRemoteUrl($remoteUrl);
     $convertCollectionData->setCommandLinesStr($commandLinesStr);
     $dbConvertCollectionJob->setFileSize(kFile::fileSize($convertCollectionData->getSrcFileSyncLocalPath()));
     return kJobsManager::addJob($dbConvertCollectionJob, $convertCollectionData, BatchJobType::CONVERT_COLLECTION, $currentConversionEngine);
 }
コード例 #12
0
ファイル: kBatchManager.php プロジェクト: richhl/kalturaCE
 /**
  * batch addMediaInfo adds a media info and updates the flavor asset 
  * 
  * @param mediaInfo $mediaInfoDb  
  * @return mediaInfo 
  */
 public static function addMediaInfo(mediaInfo $mediaInfoDb)
 {
     $mediaInfoDb->save();
     KalturaLog::log("Added media info [" . $mediaInfoDb->getId() . "] for flavor asset [" . $mediaInfoDb->getFlavorAssetId() . "]");
     if (!$mediaInfoDb->getFlavorAssetId()) {
         return $mediaInfoDb;
     }
     $flavorAsset = flavorAssetPeer::retrieveById($mediaInfoDb->getFlavorAssetId());
     if (!$flavorAsset) {
         return $mediaInfoDb;
     }
     if ($flavorAsset->getIsOriginal()) {
         KalturaLog::log("Media info is for the original flavor asset");
         $tags = null;
         $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId());
         if ($profile) {
             $tags = $profile->getInputTagsMap();
         }
         KalturaLog::log("Flavor asset tags from profile [{$tags}]");
         if (!is_null($tags)) {
             $tagsArray = explode(',', $tags);
             // support for old migrated profiles
             if ($profile->getCreationMode() == conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) {
                 if (!KDLWrap::CDLIsFLV($mediaInfoDb)) {
                     $key = array_search(flavorParams::TAG_MBR, $tagsArray);
                     unset($tagsArray[$key]);
                 }
             }
             $finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', $finalTagsArray);
             KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]");
             $flavorAsset->setTags($finalTags);
         }
     }
     KalturaLog::log("KDLWrap::ConvertMediainfoCdl2FlavorAsset(" . $mediaInfoDb->getId() . ", " . $flavorAsset->getId() . ");");
     KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfoDb, $flavorAsset);
     $flavorAsset->save();
     //		if(!$flavorAsset->hasTag(flavorParams::TAG_MBR))
     //			return $mediaInfoDb;
     $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId());
     if (!$entry) {
         return $mediaInfoDb;
     }
     $contentDuration = $mediaInfoDb->getContainerDuration();
     if (!$contentDuration) {
         $contentDuration = $mediaInfoDb->getVideoDuration();
         if (!$contentDuration) {
             $contentDuration = $mediaInfoDb->getAudioDuration();
         }
     }
     $entry->setLengthInMsecs($contentDuration);
     if ($mediaInfoDb->getVideoWidth() && $mediaInfoDb->getVideoHeight()) {
         $entry->setDimensions($mediaInfoDb->getVideoWidth(), $mediaInfoDb->getVideoHeight());
     }
     $entry->save();
     return $mediaInfoDb;
 }
コード例 #13
0
function runWrapperTest($contentDir, $patern)
{
    echo "<br>\n";
    $kdlSrcMedSet = getMediasetFromFile("{$contentDir}\\{$patern}");
    $cdlSrcMedInf = new mediaInfo();
    $cdlSrcMedInf->LoadFromMediaset($kdlSrcMedSet);
    $cdlFlavors[] = new flavorParams();
    $cdlFlavors[0]->simulate(KDLContainerTarget::MP4, KDLVideoTarget::H264B, 0, 352, 2500, KDLAudioTarget::AAC, 96, 22050, "2,3");
    $cdlTargets;
    $cdlTargets = KDLWrap::CDLGenerateTargetFlavors($cdlSrcMedInf, $cdlFlavors);
    $cmdLine = KDLWrap::CDLProceessFlavorsForCollection($cdlTargets->_targetList);
    if ($cdlTargets->_targetList[0]->engine_version == 0) {
        $cmdLine = $cdlTargets->_targetList[0]->command_lines;
    } else {
        $cmdLine = $cdlTargets->_targetList[0]->operators;
        $oprSets = new kOperatorSets();
        //		$operators = stripslashes($operators);
        //kLog::log(__METHOD__."\ncdlOperators(stripslsh)==>\n".print_r($operators,true));
        $oprSets->setSerialized($cdlTargets->_targetList[0]->operators);
        $oprArr = $oprSets->getSets();
        $cmdLine = $oprArr[0][0]->command;
    }
    $outFile = "aaa111.mpg";
    $exec_cmd = str_replace(array(KDLCmdlinePlaceholders::InFileName, KDLCmdlinePlaceholders::OutFileName, KDLCmdlinePlaceholders::ConfigFileName), array("{$contentDir}\\{$patern}", $outFile, "mko"), $cmdLine);
    /*
    $xmlFileName = "k:\\pre.xml";
    		$fHd = fopen($xmlFileName, "w");
    		fwrite($fHd,$exec_cmd);
    		fclose($fHd);
    		//c:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -file C:\opt\kaltura\app\batch\batches\Convert\scripts\runee3.ps1 C:\expressionencoder\ExpressionEncoder.dll W:\/content/entry/data/29/399/0_0bybp8ez_0_t75dk08i_1.mov C:\opt\kaltura\tmp\convert\convert_0_0bybp8ez_4c24801bbb92f.xml >> "C:\opt\kaltura\tmp\convert\0_0bybp8ez_0_2.log" 2>&1
    		$fHd = fopen("k:\\run.bat", "w");
    		fwrite($fHd,"c:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe -file K:\\opt\\kaltura\\app\\batch\\batches\\Convert\\scripts\\runee3.ps1 C:\\expressionencoder\\ExpressionEncoder.dll $contentDir\\$patern $xmlFileName\npause");
    		fclose($fHd);
    */
    echo "1<br>\n";
    echo $exec_cmd;
    //		exec("ffmpeg ".$exec_cmd);
    if (!file_exists($outFile) || kFile::fileSize($outFile) == 0) {
        kLog::log("\nFailed");
    } else {
        kLog::log("\nSucceeded, Filesize:" . kFile::fileSize($outFile));
    }
    //		$cdlAsset = new flavorAsset;
    //		KDLWrap::ConvertMediainfoCdl2FlavorAsset($cdlMedInf, $cdlAsset);
    $cdlMedInf = new mediaInfo();
    $kdlMedSet = getMediasetFromFile("{$outFile}");
    $cdlMedInf->LoadFromMediaset($kdlMedSet);
    kLog::log("\npre CDLValidateProduct\n");
    KDLWrap::CDLValidateProduct($cdlSrclMedInf, $cdlTargets->_targetList[0], $cdlMedInf);
    //		print_r($kdlFlavor);
    return;
}