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;
 }
Esempio n. 2
0
    $flavorParams = flavorParamsPeer::retrieveByPK($flavorParamsId);
    if (!$flavorParams instanceof SwfFlavorParams) {
        echo "Flavor params id [{$flavorParamsId}] is not SWF flavor params\n";
        exit;
    }
    $flavorParams->setVersion($flavorParams->getVersion() + 1);
} else {
    $flavorParams = new SwfFlavorParams();
    $flavorParams->setVersion(1);
    $flavorParams->setFormat(flavorParams::CONTAINER_FORMAT_SWF);
}
$swfOperator = new kOperator();
$swfOperator->id = kConvertJobData::CONVERSION_ENGINE_PDF2SWF;
$pdfOperator = new kOperator();
$pdfOperator->id = kConvertJobData::CONVERSION_ENGINE_PDF_CREATOR;
$operators = new kOperatorSets();
$operators->addSet(array($pdfOperator, $swfOperator));
$operators->addSet(array($swfOperator));
$flavorParams->setPartnerId($partnerId);
$flavorParams->setName($name);
$flavorParams->setTags($tags);
$flavorParams->setDescription($description);
$flavorParams->setReadyBehavior($readyBehavior);
$flavorParams->setIsDefault($isDefault);
$flavorParams->setWidth($width);
$flavorParams->setHeight($height);
$flavorParams->setOperators($operators->getSerialized());
$flavorParams->setEngineVersion(1);
$flavorParams->setVideoBitrate(1);
// specific for swf
$flavorParams->setFlashVersion($flashVersion);
Esempio n. 3
0
 private static function getNextConversionEngine(flavorParamsOutput $flavor, BatchJob $parentJob = null, $lastEngineType, kConvertJobData &$convertData)
 {
     KalturaLog::log("Conversion engines string: '" . $flavor->getConversionEngines() . "'");
     $currentConversionEngine = null;
     // TODO remove after all old version flavors migrated
     // parse supported engine types
     $conversionEngines = array();
     if (!$flavor->getEngineVersion()) {
         $conversionEngines = explode(',', $flavor->getConversionEngines());
         KalturaLog::log(count($conversionEngines) . " conversion engines found for the flavor");
         $currentConversionEngine = reset($conversionEngines);
         // gets the first engine type
     }
     // remove until here
     if (is_null($lastEngineType)) {
         KalturaLog::log("Last Engine Type is null, engine version [" . $flavor->getEngineVersion() . "]");
         if ($flavor->getEngineVersion()) {
             $operatorSet = new kOperatorSets();
             $operatorSet->setSerialized($flavor->getOperators());
             $nextOperator = $operatorSet->getOperator();
             if (!$nextOperator) {
                 KalturaLog::err("First operator is invalid");
                 return null;
             }
             KalturaLog::log("Set first operator in first set");
             $currentConversionEngine = $nextOperator->id;
         }
     } else {
         if ($parentJob && $flavor->getEngineVersion() && ($parentJob->getJobType() == BatchJobType::CONVERT || $parentJob->getJobType() == BatchJobType::POSTCONVERT)) {
             // using next oprator
             KalturaLog::log("Adding next conversion operator");
             $parentData = $parentJob->getData();
             if (!$parentData || !$parentData instanceof kConvartableJobData) {
                 KalturaLog::err("Parent job data is invalid");
                 return null;
             }
             $operatorSet = new kOperatorSets();
             $operatorSet->setSerialized($flavor->getOperators());
             $nextOperatorSet = $parentData->getCurrentOperationSet();
             $nextOperatorIndex = $parentData->getCurrentOperationIndex() + 1;
             $nextOperator = $operatorSet->getOperator($nextOperatorSet, $nextOperatorIndex);
             if (!$nextOperator) {
                 KalturaLog::err("Next operator is invalid");
                 return null;
             }
             KalturaLog::log("Moving to next operator [{$nextOperatorIndex}] in set [{$nextOperatorSet}]");
             $convertData->setCurrentOperationSet($nextOperatorSet);
             $convertData->setCurrentOperationIndex($nextOperatorIndex);
             $currentConversionEngine = $nextOperator->id;
         } else {
             // TODO remove after all old version flavors migrated
             KalturaLog::log("Last used conversion engine is [{$lastEngineType}]");
             // searching for $lastEngineType in the list
             while ($lastEngineType != $currentConversionEngine && next($conversionEngines)) {
                 $currentConversionEngine = current($conversionEngines);
             }
             // takes the next engine
             $currentConversionEngine = next($conversionEngines);
             if (!$currentConversionEngine) {
                 KalturaLog::err("There is no other conversion engine to use");
                 return null;
             }
         }
     }
     KalturaLog::log("Using conversion engine [{$currentConversionEngine}]");
     self::contributeToConvertJobData($currentConversionEngine, $convertData);
     $dbCurrentConversionEngine = kPluginableEnumsManager::apiToCore('conversionEngineType', $currentConversionEngine);
     return $dbCurrentConversionEngine;
 }
Esempio n. 4
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kConvertJobData $data
  * @param BatchJob $twinJob
  * @return BatchJob
  */
 public static function handleConvertFinished(BatchJob $dbBatchJob, kConvertJobData $data, BatchJob $twinJob = null)
 {
     KalturaLog::debug("Convert finished with destination file: " . $data->getDestFileSyncLocalPath());
     if ($dbBatchJob->getAbort()) {
         return $dbBatchJob;
     }
     // verifies that flavor asset created
     if (!$data->getFlavorAssetId()) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $data->getFlavorAssetId());
     }
     $flavorAsset = flavorAssetPeer::retrieveById($data->getFlavorAssetId());
     // verifies that flavor asset exists
     if (!$flavorAsset) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $data->getFlavorAssetId());
     }
     $flavorAsset->incrementVersion();
     $flavorAsset->save();
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($data->getDestFileSyncLocalPath(), $syncKey);
     // creats the file sync
     $logSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     try {
         kFileSyncUtils::moveFromFile($data->getDestFileSyncLocalPath() . '.log', $logSyncKey);
     } catch (Exception $e) {
         $err = 'Saving conversion log: ' . $e->getMessage();
         KalturaLog::err($err);
         $desc = $dbBatchJob->getDescription() . "\n" . $err;
         $dbBatchJob->getDescription($desc);
     }
     $data->setDestFileSyncLocalPath(kFileSyncUtils::getLocalFilePathForKey($syncKey));
     KalturaLog::debug("Convert archived file to: " . $data->getDestFileSyncLocalPath());
     // save the data changes to the db
     $dbBatchJob->setData($data);
     $dbBatchJob->save();
     $entry = $dbBatchJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $dbBatchJob, $dbBatchJob->getEntryId());
     }
     $entry->addFlavorParamsId($data->getFlavorParamsOutput()->getFlavorParamsId());
     $entry->save();
     $offset = $entry->getThumbOffset();
     // entry getThumbOffset now takes the partner DefThumbOffset into consideration
     $flavorParamsOutput = $data->getFlavorParamsOutput();
     $createThumb = true;
     $extractMedia = true;
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         // e.g. document
         $extractMedia = false;
     }
     $rootBatchJob = $dbBatchJob->getRootJob();
     if (!$rootBatchJob) {
         $createThumb = false;
     } else {
         if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
             $createThumb = false;
         } else {
             $rootBatchJobData = $rootBatchJob->getData();
             if ($rootBatchJobData instanceof kConvertProfileJobData) {
                 $createThumb = $rootBatchJobData->getCreateThumb();
                 $extractMedia = $rootBatchJobData->getExtractMedia();
             }
         }
     }
     // For apple http flavors do not attempt to get thumbs and media info,
     // It is up to the operator to provide that kind of data, rather than hardcoded check
     // To-fix
     if ($flavorParamsOutput->getFormat() == assetParams::CONTAINER_FORMAT_APPLEHTTP) {
         $createThumb = false;
         $extractMedia = false;
     }
     if ($createThumb) {
         $videoCodec = $flavorParamsOutput->getVideoCodec();
         if (in_array($videoCodec, self::$thumbUnSupportVideoCodecs)) {
             $createThumb = false;
         }
     }
     $operatorSet = new kOperatorSets();
     $operatorSet->setSerialized(stripslashes($flavorParamsOutput->getOperators()));
     //		KalturaLog::debug("Operators: ".$flavorParamsOutput->getOperators()
     //			."\ngetCurrentOperationSet:".$data->getCurrentOperationSet()
     //			."\ngetCurrentOperationIndex:".$data->getCurrentOperationIndex());
     //		KalturaLog::debug("Operators set: " . print_r($operatorSet, true));
     $nextOperator = $operatorSet->getOperator($data->getCurrentOperationSet(), $data->getCurrentOperationIndex() + 1);
     $nextJob = null;
     if ($nextOperator) {
         //			KalturaLog::debug("Found next operator");
         $nextJob = kJobsManager::addFlavorConvertJob($syncKey, $flavorParamsOutput, $data->getFlavorAssetId(), $data->getMediaInfoId(), $dbBatchJob, $dbBatchJob->getJobSubType());
     }
     if (!$nextJob) {
         if ($createThumb || $extractMedia) {
             $jobSubType = BatchJob::BATCHJOB_SUB_TYPE_POSTCONVERT_FLAVOR;
             if ($flavorAsset->getIsOriginal()) {
                 $jobSubType = BatchJob::BATCHJOB_SUB_TYPE_POSTCONVERT_SOURCE;
             }
             kJobsManager::addPostConvertJob($dbBatchJob, $jobSubType, $data->getDestFileSyncLocalPath(), $data->getFlavorAssetId(), $flavorParamsOutput->getId(), $createThumb, $offset);
         } else {
             $flavorAsset = kBusinessPostConvertDL::handleFlavorReady($dbBatchJob, $data->getFlavorAssetId());
             if ($flavorAsset) {
                 if ($flavorAsset->hasTag(flavorParams::TAG_SOURCE)) {
                     kBusinessPreConvertDL::continueProfileConvert($dbBatchJob);
                 }
                 if ($flavorAsset->getType() == assetType::FLAVOR) {
                     $flavorAsset->setBitrate($flavorParamsOutput->getVideoBitrate());
                     $flavorAsset->setWidth($flavorParamsOutput->getWidth());
                     $flavorAsset->setHeight($flavorParamsOutput->getHeight());
                     $flavorAsset->setFrameRate($flavorParamsOutput->getFrameRate());
                     $flavorAsset->setIsOriginal(0);
                     $flavorAsset->save();
                 }
                 kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $flavorAsset);
             }
         }
     }
     // this logic decide when a thumbnail should be created
     if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) {
         $localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
         $downloadUrl = $flavorAsset->getDownloadUrl();
         $notificationData = array("puserId" => $entry->getPuserId(), "entryId" => $entry->getId(), "entryIntId" => $entry->getIntId(), "entryVersion" => $entry->getVersion(), "fileFormat" => $flavorAsset->getFileExt(), "archivedFile" => $localPath, "downoladPath" => $localPath, "conversionQuality" => $entry->getConversionQuality(), "downloadUrl" => $downloadUrl);
         $extraData = array("data" => json_encode($notificationData), "partner_id" => $entry->getPartnerId(), "puser_id" => $entry->getPuserId(), "entry_id" => $entry->getId(), "entry_int_id" => $entry->getIntId(), "entry_version" => $entry->getVersion(), "file_format" => $flavorAsset->getFileExt(), "archived_file" => $localPath, "downolad_path" => $localPath, "target" => $localPath, "conversion_quality" => $entry->getConversionQuality(), "download_url" => $downloadUrl, "status" => $entry->getStatus(), "abort" => $dbBatchJob->getAbort(), "progress" => $dbBatchJob->getProgress(), "message" => $dbBatchJob->getMessage(), "description" => $dbBatchJob->getDescription(), "updates_count" => $dbBatchJob->getUpdatesCount(), "job_type" => BatchJobType::DOWNLOAD, "status" => BatchJob::BATCHJOB_STATUS_FINISHED, "progress" => 100, "debug" => __LINE__);
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_BATCH_JOB_SUCCEEDED, $dbBatchJob, $dbBatchJob->getPartnerId(), null, null, $extraData, $dbBatchJob->getEntryId());
     }
     return $dbBatchJob;
 }
Esempio n. 5
0
 protected function getOperator(KalturaConvartableJobData $data)
 {
     if (isset($data->flavorParamsOutput)) {
         $operatorsSet = new kOperatorSets();
         $operatorsSet->setSerialized($data->flavorParamsOutput->operators);
         return $operatorsSet->getOperator($data->currentOperationSet, $data->currentOperationIndex);
     } else {
         return null;
     }
 }
Esempio n. 6
0
require_once '../kOperatorSets.php';
$json = '
[
	[
		{
			"id":1,
			"extra":"A extra params 1 ",
			"command":"A command line data 1"
		},
		{
			"id":2,
			"extra":"A extra params 2",
			"command":"A command line data 2"
		}
	],
	[
		{
			"id":1,
			"extra":"B extra params 1 ",
			"command":"B command line data 1"
		},
		{
			"id":2,
			"extra":"B extra params 2",
			"command":"B command line data 2"
		}
	]
]';
$obj = new kOperatorSets();
$obj->setSerialized($json);
var_dump($obj);
Esempio n. 7
0
 private static function createNextJob(flavorParamsOutput $flavorParamsOutput, BatchJob $dbBatchJob, kConvertJobData $data, FileSyncKey $syncKey)
 {
     $operatorSet = new kOperatorSets();
     $operatorSet->setSerialized(stripslashes($flavorParamsOutput->getOperators()));
     $nextOperator = $operatorSet->getOperator($data->getCurrentOperationSet(), $data->getCurrentOperationIndex() + 1);
     $nextJob = null;
     if ($nextOperator) {
         //Note: consequent operators doesn't support at the moment conversion based on outputs of multiple sources
         $nextJob = kJobsManager::addFlavorConvertJob(array($syncKey), $flavorParamsOutput, $data->getFlavorAssetId(), null, $data->getMediaInfoId(), $dbBatchJob, $dbBatchJob->getJobSubType());
     }
     return $nextJob;
 }
 /**
  * addFlavorConvertJob adds a single flavor conversion 
  * 
  * @param FileSyncKey $srcSyncKey
  * @param flavorParamsOutput $flavor
  * @param int $flavorAssetId
  * @param int $mediaInfoId
  * @param BatchJob $parentJob
  * @param int $lastEngineType  
  * @param BatchJob $dbConvertFlavorJob
  * @return BatchJob 
  */
 public static function addFlavorConvertJob(FileSyncKey $srcSyncKey, flavorParamsOutput $flavor, $flavorAssetId, $mediaInfoId = null, BatchJob $parentJob = null, $lastEngineType = null, BatchJob $dbConvertFlavorJob = null)
 {
     $localPath = null;
     $remoteUrl = null;
     $flavorAsset = assetPeer::retrieveById($flavorAssetId);
     if (!$flavorAsset) {
         KalturaLog::err("No flavor asset found for id [{$flavorAssetId}]");
         return null;
     }
     if ($flavor->getSourceRemoteStorageProfileId() == StorageProfile::STORAGE_KALTURA_DC) {
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
         $partner = PartnerPeer::retrieveByPK($flavorAsset->getPartnerId());
         if (!$fileSync) {
             kBatchManager::updateEntry($flavorAsset->getEntryId(), entryStatus::ERROR_CONVERTING);
             $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $flavorAsset->setDescription("Source file sync not found: {$srcSyncKey}");
             $flavorAsset->save();
             KalturaLog::err("Source file sync not found: {$srcSyncKey}");
             return null;
         }
         if (!$local) {
             if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) {
                 KalturaLog::debug("Creates import job for remote file sync");
                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT);
                 $flavorAsset->setDescription("Source file sync is importing: {$srcSyncKey}");
                 $flavorAsset->save();
                 $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($flavorAsset->getEntryId());
                 $url = $fileSync->getExternalUrl($flavorAsset->getEntryId());
                 return kJobsManager::addImportJob($parentJob, $flavorAsset->getEntryId(), $partner->getId(), $url, $originalFlavorAsset, null, null, true);
             }
             throw new kCoreException("Source file not found for flavor conversion [{$flavorAssetId}]", kCoreException::SOURCE_FILE_NOT_FOUND);
         }
         if ($fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
             $localPath = $fileSync->getFullPath();
         }
         $remoteUrl = $fileSync->getExternalUrl($flavorAsset->getEntryId());
     } else {
         $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($srcSyncKey, $flavor->getSourceRemoteStorageProfileId());
         if (!$fileSync) {
             kBatchManager::updateEntry($flavorAsset->getEntryId(), entryStatus::ERROR_CONVERTING);
             $description = "Remote source file sync not found {$srcSyncKey}, storage profile id [" . $flavor->getSourceRemoteStorageProfileId() . "]";
             KalturaLog::err($description);
             $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $flavorAsset->setDescription($description);
             $flavorAsset->save();
             return null;
         }
         $localPath = $fileSync->getFilePath();
         $remoteUrl = $fileSync->getExternalUrl($flavorAsset->getEntryId());
     }
     $wamsAssetId = $fileSync->getWamsAssetId();
     // creates convert data
     $convertData = new kConvertJobData();
     $convertData->setSrcFileSyncLocalPath($localPath);
     $convertData->setSrcFileSyncRemoteUrl($remoteUrl);
     $convertData->setMediaInfoId($mediaInfoId);
     $convertData->setFlavorParamsOutputId($flavor->getId());
     $convertData->setFlavorAssetId($flavorAssetId);
     $convertData->setSrcFileSyncWamsAssetId($wamsAssetId);
     KalturaLog::log("Conversion engines string: '" . $flavor->getConversionEngines() . "'");
     $currentConversionEngine = null;
     // TODO remove after all old version flavors migrated
     // parse supported engine types
     $conversionEngines = array();
     if (!$flavor->getEngineVersion()) {
         $conversionEngines = explode(',', $flavor->getConversionEngines());
         KalturaLog::log(count($conversionEngines) . " conversion engines found for the flavor");
         $currentConversionEngine = reset($conversionEngines);
         // gets the first engine type
     }
     // remove until here
     if (is_null($lastEngineType)) {
         KalturaLog::log("Last Engine Type is null, engine version [" . $flavor->getEngineVersion() . "]");
         if ($flavor->getEngineVersion()) {
             $operatorSet = new kOperatorSets();
             $operatorSet->setSerialized($flavor->getOperators());
             $nextOperator = $operatorSet->getOperator();
             if (!$nextOperator) {
                 KalturaLog::err("First operator is invalid");
                 return null;
             }
             KalturaLog::log("Set first operator in first set");
             $currentConversionEngine = $nextOperator->id;
         }
     } else {
         if ($parentJob && $flavor->getEngineVersion() && ($parentJob->getJobType() == BatchJobType::CONVERT || $parentJob->getJobType() == BatchJobType::POSTCONVERT)) {
             // using next oprator
             KalturaLog::log("Adding next conversion operator");
             $parentData = $parentJob->getData();
             if (!$parentData || !$parentData instanceof kConvartableJobData) {
                 KalturaLog::err("Parent job data is invalid");
                 return null;
             }
             $operatorSet = new kOperatorSets();
             $operatorSet->setSerialized($flavor->getOperators());
             $nextOperatorSet = $parentData->getCurrentOperationSet();
             $nextOperatorIndex = $parentData->getCurrentOperationIndex() + 1;
             $nextOperator = $operatorSet->getOperator($nextOperatorSet, $nextOperatorIndex);
             if (!$nextOperator) {
                 KalturaLog::err("Next operator is invalid");
                 return null;
             }
             KalturaLog::log("Moving to next operator [{$nextOperatorIndex}] in set [{$nextOperatorSet}]");
             $convertData->setCurrentOperationSet($nextOperatorSet);
             $convertData->setCurrentOperationIndex($nextOperatorIndex);
             $currentConversionEngine = $nextOperator->id;
         } else {
             // TODO remove after all old version flavors migrated
             KalturaLog::log("Last used conversion engine is [{$lastEngineType}]");
             // searching for $lastEngineType in the list
             while ($lastEngineType != $currentConversionEngine && next($conversionEngines)) {
                 $currentConversionEngine = current($conversionEngines);
             }
             // takes the next engine
             $currentConversionEngine = next($conversionEngines);
             if (!$currentConversionEngine) {
                 KalturaLog::err("There is no other conversion engine to use");
                 return null;
             }
         }
     }
     if (!is_null($fileSync->getWamsAssetId())) {
         $currentConversionEngine = conversionEngineType::WAMS;
     }
     KalturaLog::log("Using conversion engine [{$currentConversionEngine}]");
     // creats a child convert job
     if (is_null($dbConvertFlavorJob)) {
         if ($parentJob) {
             $dbConvertFlavorJob = $parentJob->createChild();
             KalturaLog::log("Created from parent convert job with entry id [" . $dbConvertFlavorJob->getEntryId() . "]");
         } else {
             $dbConvertFlavorJob = new BatchJob();
             $dbConvertFlavorJob->setEntryId($flavor->getEntryId());
             $dbConvertFlavorJob->setPartnerId($flavor->getPartnerId());
             $dbConvertFlavorJob->save();
             KalturaLog::log("Created from flavor convert job with entry id [" . $dbConvertFlavorJob->getEntryId() . "]");
         }
     }
     if (!is_null($fileSync->getWamsAssetId())) {
         $srcFileSize = kWAMS::getInstance($flavor->getPartnerId())->getFileSizeForAssetId($fileSync->getWamsAssetId());
     } else {
         $srcFileSize = kFile::fileSize($convertData->getSrcFileSyncLocalPath());
     }
     $dbConvertFlavorJob->setFileSize($srcFileSize);
     // TODO remove after all old version flavors migrated
     if (in_array(conversionEngineType::ENCODING_COM, $conversionEngines)) {
         $dbConvertFlavorJob->setOnStressDivertTo(conversionEngineType::ENCODING_COM);
     }
     // remove until here
     /*
     	// Remarked by Dor until Tantan's return.
     	// Code is supposed to get a configuration file from the engine and attach it to the batch job.
     	// Was added for document conversion and is not used for now because of a bug of PDFCreator.
     
     KalturaLog::log("Calling CDLProceessFlavor with flavor params output[" . $flavor->getId() . "]");
     $config = KDLWrap::CDLProceessFlavor($flavor);
     if($config)
     {
     	$syncKey = $dbConvertFlavorJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG);
     	kFileSyncUtils::file_put_contents($syncKey, $config);
     	
     	$fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey);
     	$remoteUrl = $fileSync->getExternalUrl($flavor->getEntryId());
     	$localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     	
     	$convertData->setConfigLocalPath($localPath);
     	$convertData->setConfigRemoteUrl($remoteUrl);
     }
     */
     $dbCurrentConversionEngine = kPluginableEnumsManager::apiToCore('conversionEngineType', $currentConversionEngine);
     return kJobsManager::addJob($dbConvertFlavorJob, $convertData, BatchJobType::CONVERT, $dbCurrentConversionEngine);
 }
Esempio n. 9
0
<?php

/**
 * @package infra
 * @subpackage Conversion
 */
require_once '../kOperator.php';
require_once '../kOperatorSets.php';
$op_a1 = new kOperator();
$op_a1->id = 1;
$op_a1->extra = 'A extra params 1 ';
$op_a1->command = 'A command line data 1';
$op_a2 = new kOperator();
$op_a2->id = 2;
$op_a2->extra = 'A extra params 2';
$op_a2->command = 'A command line data 2';
$set_a = array($op_a1, $op_a2);
$op_b1 = new kOperator();
$op_b1->id = 1;
$op_b1->extra = 'B extra params 1 ';
$op_b1->command = 'B command line data 1';
$op_b2 = new kOperator();
$op_b2->id = 2;
$op_b2->extra = 'B extra params 2';
$op_b2->command = 'B command line data 2';
$set_b = array($op_b1, $op_b2);
$obj = new kOperatorSets();
$obj->addSet($set_a);
$obj->addSet($set_b);
echo $obj->getSerialized();
Esempio n. 10
0
 /**
  * addFlavorConvertJob adds a single flavor conversion 
  * 
  * @param FileSyncKey $srcSyncKey
  * @param flavorParamsOutput $flavor
  * @param int $flavorAssetId
  * @param int $mediaInfoId
  * @param BatchJob $parentJob
  * @param int $lastEngineType  
  * @param BatchJob $dbConvertFlavorJob
  * @return BatchJob 
  */
 public static function addFlavorConvertJob(FileSyncKey $srcSyncKey, flavorParamsOutput $flavor, $flavorAssetId, $mediaInfoId = null, BatchJob $parentJob = null, $lastEngineType = null, BatchJob $dbConvertFlavorJob = 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();
     }
     // creates convert data
     $convertData = new kConvertJobData();
     $convertData->setSrcFileSyncLocalPath($localPath);
     $convertData->setSrcFileSyncRemoteUrl($remoteUrl);
     $convertData->setMediaInfoId($mediaInfoId);
     $convertData->setFlavorParamsOutputId($flavor->getId());
     $convertData->setFlavorAssetId($flavorAssetId);
     KalturaLog::log("Conversion engines string: '" . $flavor->getConversionEngines() . "'");
     $currentConversionEngine = null;
     // TODO remove after all old version flavors migrated
     // parse supported engine types
     $conversionEngines = array();
     if (!$flavor->getEngineVersion()) {
         $conversionEngines = explode(',', $flavor->getConversionEngines());
         KalturaLog::log(count($conversionEngines) . " conversion engines found for the flavor");
         $currentConversionEngine = reset($conversionEngines);
         // gets the first engine type
     }
     // remove until here
     if (is_null($lastEngineType)) {
         KalturaLog::log("Last Engine Type is null, engine version [" . $flavor->getEngineVersion() . "]");
         if ($flavor->getEngineVersion()) {
             $operatorSet = new kOperatorSets();
             $operatorSet->setSerialized($flavor->getOperators());
             $nextOperator = $operatorSet->getOperator();
             if (!$nextOperator) {
                 KalturaLog::log("First operator is invalid");
                 return null;
             }
             KalturaLog::log("Set first operator in first set");
             $currentConversionEngine = $nextOperator->id;
         }
     } else {
         if ($parentJob && $flavor->getEngineVersion() && ($parentJob->getJobType() == BatchJobType::CONVERT || $parentJob->getJobType() == BatchJobType::POSTCONVERT)) {
             // using next oprator
             KalturaLog::log("Adding next conversion operator");
             $parentData = $parentJob->getData();
             if (!$parentData || !$parentData instanceof kConvartableJobData) {
                 KalturaLog::log("Parent job data is invalid");
                 return null;
             }
             $operatorSet = new kOperatorSets();
             $operatorSet->setSerialized($flavor->getOperators());
             $nextOperatorSet = $parentData->getCurrentOperationSet();
             $nextOperatorIndex = $parentData->getCurrentOperationIndex() + 1;
             $nextOperator = $operatorSet->getOperator($nextOperatorSet, $nextOperatorIndex);
             if (!$nextOperator) {
                 KalturaLog::log("Next operator is invalid");
                 return null;
             }
             KalturaLog::log("Moving to next operator [{$nextOperatorIndex}] in set [{$nextOperatorSet}]");
             $convertData->setCurrentOperationSet($nextOperatorSet);
             $convertData->setCurrentOperationIndex($nextOperatorIndex);
             $currentConversionEngine = $nextOperator->id;
         } else {
             // TODO remove after all old version flavors migrated
             KalturaLog::log("Last used conversion engine is [{$lastEngineType}]");
             // searching for $lastEngineType in the list
             while ($lastEngineType != $currentConversionEngine && next($conversionEngines)) {
                 $currentConversionEngine = current($conversionEngines);
             }
             // takes the next engine
             $currentConversionEngine = next($conversionEngines);
             if (!$currentConversionEngine) {
                 KalturaLog::log("There is no other conversion engine to use");
                 return null;
             }
         }
     }
     KalturaLog::log("Using conversion engine [{$currentConversionEngine}]");
     // creats a child convert job
     if (is_null($dbConvertFlavorJob)) {
         if ($parentJob) {
             $dbConvertFlavorJob = $parentJob->createChild();
             KalturaLog::log("Created from parent convert job with entry id [" . $dbConvertFlavorJob->getEntryId() . "]");
         } else {
             $dbConvertFlavorJob = new BatchJob();
             $dbConvertFlavorJob->setEntryId($flavor->getEntryId());
             $dbConvertFlavorJob->setPartnerId($flavor->getPartnerId());
             $dbConvertFlavorJob->save();
             KalturaLog::log("Created from flavor convert job with entry id [" . $dbConvertFlavorJob->getEntryId() . "]");
         }
     }
     $dbConvertFlavorJob->setFileSize(filesize($convertData->getSrcFileSyncLocalPath()));
     // TODO remove after all old version flavors migrated
     if (in_array(conversionEngineType::ENCODING_COM, $conversionEngines)) {
         $dbConvertFlavorJob->setOnStressDivertTo(conversionEngineType::ENCODING_COM);
     }
     // remove until here
     /*
     	// Remarked by Dor until Tantan's return.
     	// Code is supposed to get a configuration file from the engine and attach it to the batch job.
     	// Was added for document conversion and is not used for now because of a bug of PDFCreator.
     
     KalturaLog::log("Calling CDLProceessFlavor with flavor params output[" . $flavor->getId() . "]");
     $config = KDLWrap::CDLProceessFlavor($flavor);
     if($config)
     {
     	$syncKey = $dbConvertFlavorJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG);
     	kFileSyncUtils::file_put_contents($syncKey, $config);
     	
     	$fileSync = kFileSyncUtils::getLocalFileSyncForKey($syncKey);
     	$remoteUrl = $fileSync->getExternalUrl();
     	$localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     	
     	$convertData->setConfigLocalPath($localPath);
     	$convertData->setConfigRemoteUrl($remoteUrl);
     }
     */
     $dbCurrentConversionEngine = kPluginableEnumsManager::apiToCore('conversionEngineType', $currentConversionEngine);
     return kJobsManager::addJob($dbConvertFlavorJob, $convertData, BatchJobType::CONVERT, $dbCurrentConversionEngine);
 }
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;
}