Ejemplo n.º 1
0
 public static function ConvertFlavorCdl2Kdl($cdlFlavor)
 {
     $kdlFlavor = new KDLFlavor();
     $kdlFlavor->_name = $cdlFlavor->getName();
     $kdlFlavor->_id = $cdlFlavor->getId();
     $kdlFlavor->_type = $cdlFlavor->getType();
     $kdlFlavor->_tags = $cdlFlavor->getTags();
     if ($cdlFlavor instanceof flavorParams) {
         $kdlFlavor->_clipStart = $cdlFlavor->getClipOffset();
         $kdlFlavor->_clipDur = $cdlFlavor->getClipDuration();
         /**/
         $multiStream = $cdlFlavor->getMultiStream();
         if (isset($multiStream)) {
             //Sample json string: {"detect":"auto","audio":{"mapping":[1,2]}}
             $fromJson = json_decode($multiStream);
             $kdlFlavor->_multiStream = isset($fromJson) ? $fromJson : null;
         }
         $kdlFlavor->_optimizationPolicy = $cdlFlavor->getOptimizationPolicy();
     } else {
         if ($cdlFlavor instanceof flavorParamsOutput) {
             $kdlFlavor->_clipStart = $cdlFlavor->getClipOffset();
             $kdlFlavor->_clipDur = $cdlFlavor->getClipDuration();
         }
     }
     $kdlFlavor->_cdlObject = $cdlFlavor;
     $kdlFlavor->_container = new KDLContainerData();
     $kdlFlavor->_container->_id = $cdlFlavor->getFormat();
     //		$kdlFlavor->_container->_duration=$api->getContainerDuration();
     //		$kdlFlavor->_container->_bitRate=$api->getContainerBitRate();
     //		$kdlFlavor->_container->_fileSize=$api->getFileSize();
     if ($kdlFlavor->_container->IsDataSet() == false) {
         $kdlFlavor->_container = null;
     }
     $kdlFlavor->_video = new KDLVideoData();
     $kdlFlavor->_video->_id = $cdlFlavor->getVideoCodec();
     //		$kdlFlavor->_video->_format = $api->getVideoFormat();
     //		$kdlFlavor->_video->_duration = $api->getVideoDuration();
     $kdlFlavor->_video->_bitRate = $cdlFlavor->getVideoBitRate();
     $kdlFlavor->_video->_width = $cdlFlavor->getWidth();
     $kdlFlavor->_video->_height = $cdlFlavor->getHeight();
     $kdlFlavor->_video->_frameRate = $cdlFlavor->getFrameRate();
     $kdlFlavor->_video->_gop = $cdlFlavor->getGopSize();
     $kdlFlavor->_isTwoPass = $cdlFlavor->getTwoPass();
     $kdlFlavor->_video->_arProcessingMode = $cdlFlavor->getAspectRatioProcessingMode();
     $kdlFlavor->_video->_forceMult16 = $cdlFlavor->getForceFrameToMultiplication16();
     if ($cdlFlavor instanceof flavorParams) {
         $kdlFlavor->_video->_cbr = $cdlFlavor->getVideoConstantBitrate();
         $kdlFlavor->_video->_bt = $cdlFlavor->getVideoBitrateTolerance();
         $kdlFlavor->_video->_isGopInSec = $cdlFlavor->getIsGopInSec();
         $kdlFlavor->_video->_isShrinkFramesizeToSource = !$cdlFlavor->getIsAvoidVideoShrinkFramesizeToSource();
         $kdlFlavor->_video->_isShrinkBitrateToSource = !$cdlFlavor->getIsAvoidVideoShrinkBitrateToSource();
         $kdlFlavor->_video->_isFrameRateForLowBrAppleHls = $cdlFlavor->getIsVideoFrameRateForLowBrAppleHls();
         $kdlFlavor->_video->_anamorphic = $cdlFlavor->getAnamorphicPixels();
         $kdlFlavor->_video->_maxFrameRate = $cdlFlavor->getMaxFrameRate();
         $kdlFlavor->_video->_isForcedKeyFrames = !$cdlFlavor->getIsAvoidForcedKeyFrames();
         $kdlFlavor->_video->_isCropIMX = $cdlFlavor->getIsCropIMX();
         $watermarkData = $cdlFlavor->getWatermarkData();
         if (isset($watermarkData)) {
             $fromJson = json_decode($watermarkData);
             $kdlFlavor->_video->_watermarkData = isset($fromJson) ? $fromJson : null;
         }
     }
     //		$flavor->_video->_dar = $api->getVideoDar();
     if ($kdlFlavor->_video->IsDataSet() == false) {
         $kdlFlavor->_video = null;
     }
     $kdlFlavor->_audio = new KDLAudioData();
     $kdlFlavor->_audio->_id = $cdlFlavor->getAudioCodec();
     //		$flavor->_audio->_format = $cdlFlavor->getAudioFormat();
     //		$flavor->_audio->_duration = $cdlFlavor->getAudioDuration();
     $kdlFlavor->_audio->_bitRate = $cdlFlavor->getAudioBitRate();
     $kdlFlavor->_audio->_channels = $cdlFlavor->getAudioChannels();
     $kdlFlavor->_audio->_sampleRate = $cdlFlavor->getAudioSampleRate();
     $kdlFlavor->_audio->_resolution = $cdlFlavor->getAudioResolution();
     if ($kdlFlavor->_audio->IsDataSet() == false) {
         $kdlFlavor->_audio = null;
     }
     $operators = $cdlFlavor->getOperators();
     $transObjArr = array();
     //KalturaLog::log(__METHOD__."\nCDL Flavor==>\n".print_r($cdlFlavor,true));
     if (!empty($operators) || $cdlFlavor->getEngineVersion() == 1) {
         $transObjArr = KDLWrap::convertOperatorsCdl2Kdl($operators);
         $kdlFlavor->_engineVersion = 1;
     } else {
         $kdlFlavor->_engineVersion = 0;
         $trnsStr = $cdlFlavor->getConversionEngines();
         $extraStr = $cdlFlavor->getConversionEnginesExtraParams();
         $transObjArr = KDLUtils::parseTranscoderList($trnsStr, $extraStr);
         if ($cdlFlavor instanceof flavorParamsOutputWrap || $cdlFlavor instanceof flavorParamsOutput) {
             $cmdLines = $cdlFlavor->getCommandLines();
             foreach ($transObjArr as $transObj) {
                 $transObj->_cmd = $cmdLines[$transObj->_id];
             }
         }
         KalturaLog::log("\ntranscoders==>\n" . print_r($transObjArr, true));
     }
     KDLUtils::RecursiveScan($transObjArr, "transcoderSetFuncWrap", self::$TranscodersCdl2Kdl, "");
     $kdlFlavor->_transcoders = $transObjArr;
     if ($cdlFlavor instanceof flavorParamsOutputWrap) {
         if ($cdlFlavor->_isRedundant) {
             $kdlFlavor->_flags = $kdlFlavor->_flags | KDLFlavor::RedundantFlagBit;
         }
         if ($cdlFlavor->_isNonComply) {
             $kdlFlavor->_flags = $kdlFlavor->_flags | KDLFlavor::BitrateNonComplyFlagBit;
         }
         $kdlFlavor->_errors = $kdlFlavor->_errors + $cdlFlavor->_errors;
         $kdlFlavor->_warnings = $kdlFlavor->_warnings + $cdlFlavor->_warnings;
     }
     if ($cdlFlavor instanceof SwfFlavorParams || $cdlFlavor instanceof SwfFlavorParamsOutput) {
         $kdlFlavor->_swf = new KDLSwfData();
         $kdlFlavor->_swf->_flashVersion = $cdlFlavor->getFlashVersion();
         $kdlFlavor->_swf->_zoom = $cdlFlavor->getZoom();
         $kdlFlavor->_swf->_zlib = $cdlFlavor->getZlib();
         $kdlFlavor->_swf->_jpegQuality = $cdlFlavor->getJpegQuality();
         $kdlFlavor->_swf->_sameWindow = $cdlFlavor->getSameWindow();
         $kdlFlavor->_swf->_insertStop = $cdlFlavor->getInsertStop();
         $kdlFlavor->_swf->_useShapes = $cdlFlavor->getUseShapes();
         $kdlFlavor->_swf->_storeFonts = $cdlFlavor->getStoreFonts();
         $kdlFlavor->_swf->_flatten = $cdlFlavor->getFlatten();
         $kdlFlavor->_swf->_poly2Bitmap = $cdlFlavor->getPoly2bitmap();
     }
     if ($cdlFlavor instanceof PdfFlavorParams || $cdlFlavor instanceof PdfFlavorParamsOutput) {
         $kdlFlavor->_pdf = new KDLPdfData();
         $kdlFlavor->_pdf->_resolution = $cdlFlavor->getResolution();
         $kdlFlavor->_pdf->_paperHeight = $cdlFlavor->getPaperHeight();
         $kdlFlavor->_pdf->_paperWidth = $cdlFlavor->getPaperWidth();
         $kdlFlavor->_pdf->_readonly = $cdlFlavor->getReadonly();
     }
     if ($cdlFlavor instanceof ImageFlavorParams || $cdlFlavor instanceof ImageFlavorParamsOutput) {
         $kdlFlavor->_image = new KDLImageData();
         $kdlFlavor->_image->_densityWidth = $cdlFlavor->getDensityWidth();
         $kdlFlavor->_image->_densityHeight = $cdlFlavor->getDensityHeight();
         $kdlFlavor->_image->_sizeWidth = $cdlFlavor->getSizeWidth();
         $kdlFlavor->_image->_sizeHeight = $cdlFlavor->getSizeHeight();
         $kdlFlavor->_image->_depth = $cdlFlavor->getDepth();
         $kdlFlavor->_image->_format = $cdlFlavor->getFormat();
     }
     //KalturaLog::log(__METHOD__."\nKDL Flavor==>\n".print_r($kdlFlavor,true));
     if (is_null($kdlFlavor->_container)) {
         KalturaLog::log("No Container Found On Flavor Convert Will Fail");
         $kdlFlavor->_errors[KDLConstants::ContainerIndex][] = KDLErrors::ToString(KDLErrors::InvalidFlavorParamConfiguration);
     }
     return $kdlFlavor;
 }
 public static function ConvertFlavorCdl2Kdl($cdlFlavor)
 {
     $kdlFlavor = new KDLFlavor();
     $kdlFlavor->_name = $cdlFlavor->getName();
     $kdlFlavor->_id = $cdlFlavor->getId();
     $kdlFlavor->_type = $cdlFlavor->getType();
     $kdlFlavor->_tags = $cdlFlavor->getTags();
     if ($cdlFlavor instanceof flavorParams || $cdlFlavor instanceof flavorParamsOutput) {
         $kdlFlavor->_clipStart = $cdlFlavor->getClipOffset();
         $kdlFlavor->_clipDur = $cdlFlavor->getClipDuration();
     }
     $kdlFlavor->_cdlObject = $cdlFlavor;
     $kdlFlavor->_container = new KDLContainerData();
     $kdlFlavor->_container->_id = $cdlFlavor->getFormat();
     //		$kdlFlavor->_container->_duration=$api->getContainerDuration();
     //		$kdlFlavor->_container->_bitRate=$api->getContainerBitRate();
     //		$kdlFlavor->_container->_fileSize=$api->getFileSize();
     if ($kdlFlavor->_container->IsDataSet() == false) {
         $kdlFlavor->_container = null;
     }
     $kdlFlavor->_video = new KDLVideoData();
     $kdlFlavor->_video->_id = $cdlFlavor->getVideoCodec();
     //		$kdlFlavor->_video->_format = $api->getVideoFormat();
     //		$kdlFlavor->_video->_duration = $api->getVideoDuration();
     $kdlFlavor->_video->_bitRate = $cdlFlavor->getVideoBitRate();
     $kdlFlavor->_video->_width = $cdlFlavor->getWidth();
     $kdlFlavor->_video->_height = $cdlFlavor->getHeight();
     $kdlFlavor->_video->_frameRate = $cdlFlavor->getFrameRate();
     $kdlFlavor->_video->_gop = $cdlFlavor->getGopSize();
     $kdlFlavor->_isTwoPass = $cdlFlavor->getTwoPass();
     $kdlFlavor->_video->_arProcessingMode = $cdlFlavor->getAspectRatioProcessingMode();
     $kdlFlavor->_video->_forceMult16 = $cdlFlavor->getForceFrameToMultiplication16();
     if ($cdlFlavor instanceof flavorParams) {
         $kdlFlavor->_video->_cbr = $cdlFlavor->getVideoConstantBitrate();
         $kdlFlavor->_video->_bt = $cdlFlavor->getVideoBitrateTolerance();
         $kdlFlavor->_video->_isGopInSec = $cdlFlavor->getIsGopInSec();
         $kdlFlavor->_video->_isShrinkFramesizeToSource = !$cdlFlavor->getIsAvoidVideoShrinkFramesizeToSource();
         $kdlFlavor->_video->_isShrinkBitrateToSource = !$cdlFlavor->getIsAvoidVideoShrinkBitrateToSource();
         $kdlFlavor->_video->_isFrameRateForLowBrAppleHls = $cdlFlavor->getIsVideoFrameRateForLowBrAppleHls();
     }
     //		$flavor->_video->_dar = $api->getVideoDar();
     if ($kdlFlavor->_video->IsDataSet() == false) {
         $kdlFlavor->_video = null;
     }
     $kdlFlavor->_audio = new KDLAudioData();
     $kdlFlavor->_audio->_id = $cdlFlavor->getAudioCodec();
     //		$flavor->_audio->_format = $cdlFlavor->getAudioFormat();
     //		$flavor->_audio->_duration = $cdlFlavor->getAudioDuration();
     $kdlFlavor->_audio->_bitRate = $cdlFlavor->getAudioBitRate();
     $kdlFlavor->_audio->_channels = $cdlFlavor->getAudioChannels();
     $kdlFlavor->_audio->_sampleRate = $cdlFlavor->getAudioSampleRate();
     $kdlFlavor->_audio->_resolution = $cdlFlavor->getAudioResolution();
     if ($kdlFlavor->_audio->IsDataSet() == false) {
         $kdlFlavor->_audio = null;
     }
     $operators = $cdlFlavor->getOperators();
     $transObjArr = array();
     //KalturaLog::log(__METHOD__."\nCDL Flavor==>\n".print_r($cdlFlavor,true));
     if (!empty($operators) || $cdlFlavor->getEngineVersion() == 1) {
         $transObjArr = KDLWrap::convertOperatorsCdl2Kdl($operators);
         $kdlFlavor->_engineVersion = 1;
     } else {
         $kdlFlavor->_engineVersion = 0;
         $trnsStr = $cdlFlavor->getConversionEngines();
         $extraStr = $cdlFlavor->getConversionEnginesExtraParams();
         $transObjArr = KDLUtils::parseTranscoderList($trnsStr, $extraStr);
         if ($cdlFlavor instanceof flavorParamsOutputWrap || $cdlFlavor instanceof flavorParamsOutput) {
             $cmdLines = $cdlFlavor->getCommandLines();
             foreach ($transObjArr as $transObj) {
                 $transObj->_cmd = $cmdLines[$transObj->_id];
             }
         }
         KalturaLog::log("\ntranscoders==>\n" . print_r($transObjArr, true));
     }
     KDLUtils::RecursiveScan($transObjArr, "transcoderSetFuncWrap", self::$TranscodersCdl2Kdl, "");
     $kdlFlavor->_transcoders = $transObjArr;
     if ($cdlFlavor instanceof flavorParamsOutputWrap) {
         if ($cdlFlavor->_isRedundant) {
             $kdlFlavor->_flags = $kdlFlavor->_flags | KDLFlavor::RedundantFlagBit;
         }
         if ($cdlFlavor->_isNonComply) {
             $kdlFlavor->_flags = $kdlFlavor->_flags | KDLFlavor::BitrateNonComplyFlagBit;
         }
         $kdlFlavor->_errors = $kdlFlavor->_errors + $cdlFlavor->_errors;
         $kdlFlavor->_warnings = $kdlFlavor->_warnings + $cdlFlavor->_warnings;
     }
     if ($cdlFlavor instanceof SwfFlavorParams || $cdlFlavor instanceof SwfFlavorParamsOutput) {
         $kdlFlavor->_swf = new KDLSWFData();
         $kdlFlavor->_swf->_flashVersion = $cdlFlavor->getFlashVersion();
         $kdlFlavor->_swf->_zoom = $cdlFlavor->getZoom();
         $kdlFlavor->_swf->_zlib = $cdlFlavor->getZlib();
         $kdlFlavor->_swf->_jpegQuality = $cdlFlavor->getJpegQuality();
         $kdlFlavor->_swf->_sameWindow = $cdlFlavor->getSameWindow();
         $kdlFlavor->_swf->_insertStop = $cdlFlavor->getInsertStop();
         $kdlFlavor->_swf->_useShapes = $cdlFlavor->getUseShapes();
         $kdlFlavor->_swf->_storeFonts = $cdlFlavor->getStoreFonts();
         $kdlFlavor->_swf->_flatten = $cdlFlavor->getFlatten();
     }
     if ($cdlFlavor instanceof PdfFlavorParams || $cdlFlavor instanceof PdfFlavorParamsOutput) {
         $kdlFlavor->_pdf = new KDLPDFData();
         $kdlFlavor->_pdf->_resolution = $cdlFlavor->getResolution();
         $kdlFlavor->_pdf->_paperHeight = $cdlFlavor->getPaperHeight();
         $kdlFlavor->_pdf->_paperWidth = $cdlFlavor->getPaperWidth();
         $kdlFlavor->_pdf->_readonly = $cdlFlavor->getReadonly();
     }
     if ($cdlFlavor instanceof ImageFlavorParams || $cdlFlavor instanceof ImageFlavorParamsOutput) {
         $kdlFlavor->_image = new KDLImageData();
         $kdlFlavor->_image->_densityWidth = $cdlFlavor->getDensityWidth();
         $kdlFlavor->_image->_densityHeight = $cdlFlavor->getDensityHeight();
         $kdlFlavor->_image->_sizeWidth = $cdlFlavor->getSizeWidth();
         $kdlFlavor->_image->_sizeHeight = $cdlFlavor->getSizeHeight();
         $kdlFlavor->_image->_depth = $cdlFlavor->getDepth();
         $kdlFlavor->_image->_format = $cdlFlavor->getFormat();
     }
     //KalturaLog::log(__METHOD__."\nKDL Flavor==>\n".print_r($kdlFlavor,true));
     return $kdlFlavor;
 }
function testOperatorJSON()
{
    if (1) {
        require_once '../kOperator.php';
        require_once '../kOperatorSets.php';
        //	$transObjArr=KDLUtils::parseTranscoderList("(1),(2#99#5),98,4,1","(--FE_SOMETING 0)|(-b 30#-a 23 -c ee# vcodec;c:7)|--FE_AAA 1234||101");
        //print_r($transObjArr);
        //print_r($transObjArr);
        $json2 = '[[{"id":2}]]';
        $json3 = '[[{\\"id\\":2,\\"extra\\":null,\\"command\\":\\"-i __inFileName__ -vcodec flv -b 251k -s 320x240 -r 14.96 -g 60 -acodec libmp3lame -ab 64k -ar 44100 -ac 2 -f flv -y __outFileName__\\"},{\\"id\\":98,\\"extra\\":null,\\"command\\":\\"-i __inFileName__ -vcodec flv -b 251k -s 320x240 -r 14.96 -g 60 -acodec libmp3lame -ab 64k -ar 44100 -ac 2 -f flv -y __outFileName__\\"}]]';
        $json4 = '[[{"id":2,"extra":null,"command":"-i __inFileName__ -vcodec flv -b 251k -s 320x240 -r 14.96 -g 60 -acodec libmp3lame -ab 64k -ar 44100 -ac 2 -f flv -y __outFileName__"},{"id":98,"extra":null,"command":"-i __inFileName__ -vcodec flv -b 251k -s 320x240 -r 14.96 -g 60 -acodec libmp3lame -ab 64k -ar 44100 -ac 2 -f flv -y __outFileName__"}]]';
        $json = '
[
	[
		{
			"id":6,
			"extra":"A extra params 1 ",
			"command":"A command line data 1",
			"azaz":12345
		}
	],
	[
		{
			"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"
		}
	]
]';
        $oprSets = new kOperatorSets();
        $oprSets->setSerialized(stripslashes($json));
        print_r($oprSets);
        echo "<br>\n\n";
        echo "333333333333333333";
        return;
        $transObjArr = KDLWrap::convertOperatorsCdl2Kdl($json);
        KDLUtils::RecursiveScan($transObjArr, "transcoderSetFuncTest", KDLConstants::$TranscodersCdl2Kdl, "");
        echo "<br>\n\n";
        print_r($transObjArr);
        $cdlOprSets = new kOperatorSets();
        //		$cdlOprSets = KDLWrap::convertOperatorsKdl2Cdl($transObjArr);
        //		print_r($cdlOprSets);
        //return;
        foreach ($transObjArr as $transObj) {
            $auxArr = array();
            if (is_array($transObj)) {
                foreach ($transObj as $tr) {
                    $opr = new kOperator();
                    $key = array_search($tr->_id, KDLWrap::$TranscodersCdl2Kdl);
                    if ($key === false) {
                        $opr->id = $tr->_id;
                    } else {
                        $opr->id = $key;
                    }
                    $opr->extra = $tr->_extra;
                    $opr->command = $tr->_cmd;
                    $auxArr[] = $opr;
                }
            } else {
                $opr = new kOperator();
                $key = array_search($transObj->_id, KDLWrap::$TranscodersCdl2Kdl);
                if ($key === false) {
                    $opr->id = $transObj->_id;
                } else {
                    $opr->id = $key;
                }
                $opr->extra = $transObj->_extra;
                $opr->command = $transObj->_cmd;
                $auxArr[] = $opr;
            }
            $cdlOprSets->addSet($auxArr);
        }
        print_r($cdlOprSets);
        return;
    }
}