kaltura /package/app/app/tests/unitTests/kdl/KDLUnitTest.php

Language PHP Lines 221
MD5 Hash 07ef8bd8c9f7ffa1abe08d249abce327 Estimated Cost $3,660 (why?)
Repository https://bitbucket.org/pandaos/kaltura.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php

class KDLUnitTest
{
	/* ------------------------------
	 * function mediaDs2flavor
	 */
	public static function simulateFlavor($fmt, $vcodec, $w=0, $h, $br, $acodec="", $ab=96, $ar=22050, $clipStart=0, $clipDur=0, $engines="2,3,99,(6#2#7)")
	{
		$fl = new KDLFlavor();
		$fl->_audio = new KDLAudioData();
		$fl->_video = new KDLVideoData();
		$fl->_container = new KDLContainerData();
		$fl->_clipDur = $clipDur;
		$fl->_clipStart = $clipStart;
		//		$fl = $source;
		$fl->_container->_id = $fmt;
		$fl->_video->_id = $vcodec;
		$fl->_video->_bitRate = $br;
		$fl->_video->_width = $w;
		$fl->_video->_height = $h; 
		$fl->_video->_gop = 0;
//		$fl->_video->_frameRate = 0;
//		$fl->_flags = KDLFlavor::ForceCommandLineFlagBit;
		$fl->_audio->_id = $acodec;
//		$fl->_audio->_channels = 2;
		$fl->_audio->_sampleRate = $ar;
		$fl->_audio->_bitRate = $ab;
//		$fl->_audio->_resolution=16;
		
///		$fl->_transcoders[] = new KDLOperationParams("cli_encode");
	
		$fl->_transcoders=KDLUtils::parseTranscoderList($engines,"", KDLWrap::$TranscodersCdl2Kdl);
		/*
		$fl->_transcoders[] = new KDLOperationParams("encoding.com");
		$fl->_transcoders[] = new KDLOperationParams("ffmpeg");
		$fl->_transcoders[] = new KDLOperationParams("ffmpeg-aux");
		$fl->_transcoders[] = new KDLOperationParams("mencoder");
		//$fl->_transcoders["encoding.com"] = true; 
		//$fl->_transcoders["cli_encode"] = true; 
		 
		*/
		KDLUtils::RecursiveScan($fl->_transcoders, "transcoderSetFuncTest", null, null);
//KalturaLog::log(__METHOD__."==>\n".print_r($fl->_transcoders,true));  
		return $fl;
	}
	
	/* ------------------------------
	 * function runDirTest
	 */
	public static function runDirTest($path, $pattern, $profile=null)
	{
		if ( !$path )
		{
			KalturaLog::log ( "Usage " . $argv[0] . " <path-to-iterate> [<file-pattern>]" );
			die();
		}
		
		KalturaLog::log ( "Will search in path [$path] for pattern [$pattern]" );
		if ( $pattern )
			$path_pattern = $path . "/" . $pattern;
		else
			$path_pattern = $path . "/*";
		$files = glob ( $path_pattern );
KalturaLog::log( "--------");
	
		foreach ($files as $file )
		{
			// iterate files and links only
			if(is_dir($file)) {
				self::runDirTest($file, "*", $profile);
				continue;
			}

			if ( ! is_file( $file ) && ! is_link ( $file ) ) 
				continue;
				
			mediaTestStub($file, $profile);
				
//			$dlPrc = new KDLProcessor();
//			self::runFileTest($file, $dlPrc, $profile);
//			echo "<br>\n";
		}
	}

	/* ------------------------------
	 * function runFileTest
	 */
	public static function runFileTest($file, &$dlPrc, $profile=null){
//	echo $profile->ToString()."<br>\n"; 	
		KalturaLog::log( $file);
		$mediaInfoStr = shell_exec(MediaInfoProgram." ". realpath($file));
		self::runMediainfoTest($mediaInfoStr, $dlPrc, $profile);
//	echo $profile->ToString()."<br>\n"; 	
	}

	/* ------------------------------
	 * function runMediainfoTest
	 */
	public static function runMediainfoTest($mediaInfoStr, &$dlPrc, $profile=null){
//echo $mediaInfoStr;
//	echo $profile->ToString()."<br>\n"; 	
		$mdLoader = new KDLMediaInfoLoader($mediaInfoStr);
		$mediaInfoObj = new KDLMediaDataSet();
		$mdLoader->Load($mediaInfoObj);

		self::runMediasetTest($mediaInfoObj, $dlPrc, $profile);
		return;
	}

	/* ------------------------------
	 * function runMediasetTest
	 */
	public static function runMediasetTest(KDLMediaDataSet $mediaSet, &$dlPrc, $profile=null){
			$inFile = realpath($mediaSet->_container->_fileName);
//$mediaSet = 100; //new KDLMediaDataSet();
		KalturaLog::log( "....S-->".$mediaSet->ToString());

		//		unset($targetList); // Remarked by Tan-Tan $targetList doesn't exist
		$targetList = array();
		$errors = array();
		$warnings = array();
		{
			$dlPrc = new KDLProcessor();

			$dlPrc->Generate($mediaSet, $profile, $targetList);
			$dlPrc->_targets=$targetList;
			$errors   = $errors   + $dlPrc->get_errors();
			$warnings = $warnings + $dlPrc->get_warnings();
			if(count($errors)>0)
				$rv = false;
			else
				$rv = true;
		}
		if($rv==false){
			KalturaLog::log( "....E==>");
			print_r($errors);
			KalturaLog::log( "\n");
		}
		KalturaLog::log( "....W==>");
		print_r($warnings);
		KalturaLog::log( "\n");
		if($profile==null)
			return;

$xmlStr = KDLProcessor::ProceessFlavorsForCollection($targetList);
KalturaLog::log(__METHOD__."-->XML-->\n".print_r($xmlStr,true)."\n<--");
	
		foreach ($targetList as $target){


$output = array();
$rv = 0;
			KalturaLog::log( "...T-->".$target->ToString());
			$outFile = "aaa1.mp4";
			
			if(file_exists($outFile)) unlink($outFile);
$cmdLineGenerator = $target->SetTranscoderCmdLineGenerator($inFile,$outFile);
			$cmdLineGenerator->_clipDur = 10000;
$exeStr = "FFMpeg ".$cmdLineGenerator->FFMpeg(null);
//			KalturaLog::log( ".CMD-->".$exeStr);
			$exeStr = "cli_encode ".$cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::ON2), 1000);
			kLog::log( ".CMD-->".$exeStr);
			$exeStr = "mencoder ".$cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::MENCODER), 1000);
			kLog::log( ".CMD-->".$exeStr);
			$exeStr = "ffmpeg ".$cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::FFMPEG), 1000);
			kLog::log( ".CMD-->".$exeStr);
			exec($exeStr, $output, $rv);
			kLog::log( "..RV-->In".$inFile."==>");
			if(!file_exists($outFile) || filesize($outFile)==0)
				kLog::log( "Failed");
			else {
				kLog::log( "Succeeded, Filesize:".filesize($outFile));
				$mediaInfoStr = shell_exec(MediaInfoProgram." ". realpath($outFile));
				$medLoader = new KDLMediaInfoLoader($mediaInfoStr);
				$product = new KDLFlavor();
				$medLoader->Load($product);
				$target->ValidateProduct($mediaSet, $product);
				kLog::log("\n".$mediaInfoStr);
//				kLog::log( ".PRD-->".$product->ToString());
				
				//				unlink($outFile);
			}
		}
	}
}
	
		/* ---------------------------
		 * transcoderSetFuncTest
		 */
function transcoderSetFuncTest($oprObj, $transDictionary, $param2)
{
	$trId = KDLUtils::trima($oprObj->_id);
	if(!is_null($transDictionary) && array_key_exists($trId, $transDictionary)){
		$oprObj->_id = $transDictionary[$trId];
	}
	if($oprObj->_id==KDLTranscoders::QUICK_TIME_PLAYER_TOOLS){
		$engineClassName = "KDLTranscoderQTPTools";
	}
	else if($oprObj->_id==KDLTranscoders::QT_FASTSTART){
		$engineClassName = "KDLOperatorQTFastStart";
	}
	else if($oprObj->_id==KDLTranscoders::AVIDEMUX){
		$engineClassName = "KDLOperatorAvidemux";
	}
	else if($oprObj->_id==KDLTranscoders::EXPRESSION_ENCODER){
		$engineClassName = "KDLOperatorExpressionEncoder";
	}
	else if($oprObj->_id==KDLTranscoders::PDF_CREATOR){
		$engineClassName = "KDLTranscoderPdfCreator";
	}
	else if($oprObj->_id==KDLTranscoders::PDF2SWF){
		$engineClassName = "KDLTranscoderPdf2Swf";
	}
	else {
		$engineClassName = "KDLOperatorWrapper";
	}
	$oprObj->_engine = new $engineClassName($oprObj->_id,"");
}

?>
Back to Top