public function GenerateCommandLine(KDLFlavor $design, KDLFlavor $target, $extra = null)
 {
     $action = "hint";
     $paramsMap = KDLUtils::parseParamStr2Map($extra);
     if (isset($paramsMap)) {
         if (array_key_exists('action', $paramsMap)) {
             $action = $paramsMap['action'];
         }
     }
     $cmdStr = null;
     switch ($action) {
         case self::ACTION_EMBED_SUBTITLES:
             $cmdStr = $this->generateEmbedSubtitlesCommandLine($design, $target, $paramsMap);
             break;
         case self::ACTION_HINT:
         default:
             $cmdStr = $this->generateHintCommandLine($design, $target, $paramsMap);
             break;
     }
     return $cmdStr;
 }
 public function GenerateCommandLine(KDLFlavor $design, KDLFlavor $target, $extra = null)
 {
     //segmenter 0_3eq4pxgw_0_j5b7ubqa_1.mpeg 2 zzz/segment zzz/playlist.m3u8 ./
     // out_dummyk:/opt/kaltura/tmp/convert/convert_0_6olnx72l_4a32a//out_dummy-1.ts
     /*
      * The segment duration can be evaluated from the 'segmentDuration' field in the operator->extra
      * or set to the gop value if such values are available.
      * Otherwise set to 10.
      */
     $segmentDur = 10;
     $paramsMap = KDLUtils::parseParamStr2Map($extra);
     if (isset($paramsMap) && array_key_exists('segmentDuration', $paramsMap)) {
         $auxDur = $paramsMap['segmentDuration'];
         if ($auxDur > 0) {
             $segmentDur = $auxDur;
         }
     }
     /*		else
     		if(isset($target->_video) 
     		&&(isset($target->_video->_gop) && $target->_video->_gop>0)
     		&&(isset($target->_video->_frameRate) && $target->_video->_frameRate>0)){
     			$auxDur = round($target->_video->_gop/$target->_video->_frameRate);
     			if($auxDur>0)
     				$segmentDur=$auxDur;
     		}
     */
     $cmdStr = " " . KDLCmdlinePlaceholders::InFileName;
     $cmdStr .= " {$segmentDur}";
     //		$cmdStr .= " ".KDLCmdlinePlaceholders::OutFileName."/segment"; // output MPEG-TS file prefix
     //		$cmdStr .= " ".KDLCmdlinePlaceholders::OutFileName."/playlist.m3u8"; // output m3u8 index file
     //		$cmdStr .= "zzzz"; // http prefix
     $cmdStr .= " " . KDLCmdlinePlaceholders::OutFileName . "//segment";
     // output MPEG-TS file prefix
     $cmdStr .= " " . KDLCmdlinePlaceholders::OutFileName . "//playlist.m3u8";
     // output m3u8 index file
     $cmdStr .= " ---";
     // http prefix
     return $cmdStr;
 }
 public function operate(kOperator $operator = null, $inFilePath, $configFilePath = null)
 {
     KalturaLog::debug("operator==>" . print_r($operator, 1));
     $encodingTemplateId = null;
     $encodingTemplateName = null;
     $cloneAndUpadate = false;
     $srcPrefixWindows = null;
     $srcPrefixLinux = null;
     $trgPrefixWindows = null;
     // ---------------------------------
     // Evaluate and set various Inlet Armada session params
     if (KBatchBase::$taskConfig->params->InletStorageRootWindows) {
         $srcPrefixWindows = KBatchBase::$taskConfig->params->InletStorageRootWindows;
     }
     if (KBatchBase::$taskConfig->params->InletStorageRootLinux) {
         $srcPrefixLinux = KBatchBase::$taskConfig->params->InletStorageRootLinux;
     }
     if (KBatchBase::$taskConfig->params->InletTmpStorageWindows) {
         $trgPrefixWindows = KBatchBase::$taskConfig->params->InletTmpStorageWindows;
     }
     $url = KBatchBase::$taskConfig->params->InletArmadaUrl;
     $login = KBatchBase::$taskConfig->params->InletArmadaLogin;
     $passw = KBatchBase::$taskConfig->params->InletArmadaPassword;
     if (KBatchBase::$taskConfig->params->InletArmadaPriority) {
         $priority = KBatchBase::$taskConfig->params->InletArmadaPriority;
     } else {
         $priority = 5;
     }
     // ----------------------------------
     $inlet = new InletAPIWrap($url);
     KalturaLog::debug(print_r($inlet, 1));
     $rvObj = new XmlRpcData();
     $rv = $inlet->userLogon($login, $passw, $rvObj);
     if (!$rv) {
         throw new KOperationEngineException("Inlet failure: login, rv(" . print_r($rvObj, true) . ")");
     }
     KalturaLog::debug("userLogon - " . print_r($rvObj, 1));
     $paramsMap = KDLUtils::parseParamStr2Map($operator->extra);
     foreach ($paramsMap as $key => $param) {
         switch ($key) {
             case 'encodingTemplate':
             case 'encodingTemplateId':
                 $encodingTemplateId = $param;
                 break;
             case 'encodingTemplateName':
                 $encodingTemplateId = $this->lookForJobTemplateId($inlet, $param);
                 $encodingTemplateName = $param;
                 break;
             case 'priority':
                 $priority = $param;
                 break;
             case 'cloneAndUpadate':
                 $cloneAndUpadate = $param;
                 break;
             default:
                 break;
         }
     }
     // Adjust linux file path to Inlet Armada Windows path
     if (isset($srcPrefixWindows) && isset($srcPrefixLinux)) {
         $srcPrefixLinux = $this->addLastSlashInFolderPath($srcPrefixLinux, "/");
         $srcPrefixWindows = $this->addLastSlashInFolderPath($srcPrefixWindows, "\\");
         $srcFileWindows = str_replace($srcPrefixLinux, $srcPrefixWindows, $inFilePath);
     } else {
         $srcFileWindows = $inFilePath;
     }
     if (isset($trgPrefixWindows)) {
         $trgPrefixLinux = $this->addLastSlashInFolderPath(KBatchBase::$taskConfig->params->localTempPath, "/");
         $trgPrefixWindows = $this->addLastSlashInFolderPath($trgPrefixWindows, "\\");
         $outFileWindows = str_replace($trgPrefixLinux, $trgPrefixWindows, $this->outFilePath);
     } else {
         $outFileWindows = $this->outFilePath;
     }
     $rv = $inlet->jobAdd($encodingTemplateId, $srcFileWindows, $outFileWindows, $priority, $srcFileWindows, array(), "", $rvObj);
     if (!$rv) {
         throw new KOperationEngineException("Inlet failure: add job, rv(" . print_r($rvObj, 1) . ")");
     }
     KalturaLog::debug("jobAdd - encodingTemplate({$encodingTemplateId}), inFile({$srcFileWindows}), outFile({$outFileWindows}),rv-" . print_r($rvObj, 1));
     $jobId = $rvObj->job_id;
     $attemptCnt = 0;
     while ($jobId) {
         sleep(60);
         $rv = $inlet->jobList(array($jobId), $rvObj);
         if (!$rv) {
             throw new KOperationEngineException("Inlet failure: job list, rv(" . print_r($rvObj, 1) . ")");
         }
         switch ($rvObj->job_list[0]->job_state) {
             case InletArmadaJobStatus::CompletedSuccess:
                 $jobId = null;
                 break;
             case InletArmadaJobStatus::CompletedUnknown:
             case InletArmadaJobStatus::CompletedFailure:
                 throw new KOperationEngineException("Inlet failure: job, rv(" . print_r($rvObj, 1) . ")");
                 break;
         }
         if ($attemptCnt % 10 == 0) {
             KalturaLog::debug("waiting for job completion - " . print_r($rvObj, 1));
         }
         $attemptCnt++;
     }
     //KalturaLog::debug("XXX taskConfig=>".print_r(KBatchBase::$taskConfig,1));
     KalturaLog::debug("Job completed successfully - " . print_r($rvObj, 1));
     if ($trgPrefixWindows) {
         $trgPrefixLinux = $this->addLastSlashInFolderPath(KBatchBase::$taskConfig->params->sharedTempPath, "/");
         $outFileLinux = str_replace($trgPrefixWindows, $trgPrefixLinux, $rvObj->job_list[0]->job_output_file);
         //KalturaLog::debug("XXX str_replace($trgPrefixWindows, ".$trgPrefixLinux.", ".$rvObj->job_list[0]->job_output_file.")==>$outFileLinux");
     } else {
         $outFileLinux = $rvObj->job_list[0]->job_output_file;
     }
     if ($outFileLinux != $this->outFilePath) {
         KalturaLog::debug("copy({$outFileLinux}, " . $this->outFilePath . ")");
         kFile::moveFile($outFileLinux, $this->outFilePath, true);
         //copy($outFileLinux, $this->outFilePath);
     }
     return true;
 }
 public function UpdateTarget(KDLFlavor $target)
 {
     /*
      * Following code block is a 'dirty' short cut to overload the qt_tools 
      * target params to H264/AAC.
      * Other engines will not be effected.
      * The correct solution is to add additional param fields to engin's JSOn record 
      */
     $paramsMap = KDLUtils::parseParamStr2Map($this->_params);
     if (!isset($paramsMap)) {
         return;
     }
     foreach ($paramsMap as $key => $param) {
         if ($target->_video) {
             $mdObj = $target->_video;
             switch ($key) {
                 case 'video_codec':
                     $mdObj->_id = $param;
                     break;
                 case 'video_bitrate':
                     $mdObj->_bitRate = $param;
                     break;
                 case 'gop':
                     $mdObj->_gop = $param;
                     break;
                 case 'frame_rate':
                     $mdObj->_frameRate = $param;
                     break;
                 case 'width':
                     $mdObj->_width = $param;
                     break;
                 case 'height':
                     $mdObj->_height = $param;
                     break;
                 default:
                     break;
             }
         }
         if ($target->_audio) {
             $mdObj = $target->_audio;
             switch ($key) {
                 case 'audio_codec':
                     $mdObj->_id = $param;
                     break;
                 case 'audio_bitrate':
                     $mdObj->_bitRate = $param;
                     break;
                 case 'sample_rate':
                     $mdObj->_sampleRate = $param;
                     break;
                 case 'channels':
                     $mdObj->_channels = $param;
                     break;
                 default:
                     break;
             }
         }
         if ($target->_container) {
             $mdObj = $target->_container;
             switch ($key) {
                 case 'container_format':
                     $mdObj->_id = $param;
                     break;
                 default:
                     break;
             }
         }
     }
 }