PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/pandaos/kaltura
PHP | 221 lines | 138 code | 18 blank | 65 comment | 24 complexity | 07ef8bd8c9f7ffa1abe08d249abce327 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-2.0, LGPL-3.0, JSON, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?php
  2. class KDLUnitTest
  3. {
  4. /* ------------------------------
  5. * function mediaDs2flavor
  6. */
  7. 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)")
  8. {
  9. $fl = new KDLFlavor();
  10. $fl->_audio = new KDLAudioData();
  11. $fl->_video = new KDLVideoData();
  12. $fl->_container = new KDLContainerData();
  13. $fl->_clipDur = $clipDur;
  14. $fl->_clipStart = $clipStart;
  15. // $fl = $source;
  16. $fl->_container->_id = $fmt;
  17. $fl->_video->_id = $vcodec;
  18. $fl->_video->_bitRate = $br;
  19. $fl->_video->_width = $w;
  20. $fl->_video->_height = $h;
  21. $fl->_video->_gop = 0;
  22. // $fl->_video->_frameRate = 0;
  23. // $fl->_flags = KDLFlavor::ForceCommandLineFlagBit;
  24. $fl->_audio->_id = $acodec;
  25. // $fl->_audio->_channels = 2;
  26. $fl->_audio->_sampleRate = $ar;
  27. $fl->_audio->_bitRate = $ab;
  28. // $fl->_audio->_resolution=16;
  29. /// $fl->_transcoders[] = new KDLOperationParams("cli_encode");
  30. $fl->_transcoders=KDLUtils::parseTranscoderList($engines,"", KDLWrap::$TranscodersCdl2Kdl);
  31. /*
  32. $fl->_transcoders[] = new KDLOperationParams("encoding.com");
  33. $fl->_transcoders[] = new KDLOperationParams("ffmpeg");
  34. $fl->_transcoders[] = new KDLOperationParams("ffmpeg-aux");
  35. $fl->_transcoders[] = new KDLOperationParams("mencoder");
  36. //$fl->_transcoders["encoding.com"] = true;
  37. //$fl->_transcoders["cli_encode"] = true;
  38. */
  39. KDLUtils::RecursiveScan($fl->_transcoders, "transcoderSetFuncTest", null, null);
  40. //KalturaLog::log(__METHOD__."==>\n".print_r($fl->_transcoders,true));
  41. return $fl;
  42. }
  43. /* ------------------------------
  44. * function runDirTest
  45. */
  46. public static function runDirTest($path, $pattern, $profile=null)
  47. {
  48. if ( !$path )
  49. {
  50. KalturaLog::log ( "Usage " . $argv[0] . " <path-to-iterate> [<file-pattern>]" );
  51. die();
  52. }
  53. KalturaLog::log ( "Will search in path [$path] for pattern [$pattern]" );
  54. if ( $pattern )
  55. $path_pattern = $path . "/" . $pattern;
  56. else
  57. $path_pattern = $path . "/*";
  58. $files = glob ( $path_pattern );
  59. KalturaLog::log( "--------");
  60. foreach ($files as $file )
  61. {
  62. // iterate files and links only
  63. if(is_dir($file)) {
  64. self::runDirTest($file, "*", $profile);
  65. continue;
  66. }
  67. if ( ! is_file( $file ) && ! is_link ( $file ) )
  68. continue;
  69. mediaTestStub($file, $profile);
  70. // $dlPrc = new KDLProcessor();
  71. // self::runFileTest($file, $dlPrc, $profile);
  72. // echo "<br>\n";
  73. }
  74. }
  75. /* ------------------------------
  76. * function runFileTest
  77. */
  78. public static function runFileTest($file, &$dlPrc, $profile=null){
  79. // echo $profile->ToString()."<br>\n";
  80. KalturaLog::log( $file);
  81. $mediaInfoStr = shell_exec(MediaInfoProgram." ". realpath($file));
  82. self::runMediainfoTest($mediaInfoStr, $dlPrc, $profile);
  83. // echo $profile->ToString()."<br>\n";
  84. }
  85. /* ------------------------------
  86. * function runMediainfoTest
  87. */
  88. public static function runMediainfoTest($mediaInfoStr, &$dlPrc, $profile=null){
  89. //echo $mediaInfoStr;
  90. // echo $profile->ToString()."<br>\n";
  91. $mdLoader = new KDLMediaInfoLoader($mediaInfoStr);
  92. $mediaInfoObj = new KDLMediaDataSet();
  93. $mdLoader->Load($mediaInfoObj);
  94. self::runMediasetTest($mediaInfoObj, $dlPrc, $profile);
  95. return;
  96. }
  97. /* ------------------------------
  98. * function runMediasetTest
  99. */
  100. public static function runMediasetTest(KDLMediaDataSet $mediaSet, &$dlPrc, $profile=null){
  101. $inFile = realpath($mediaSet->_container->_fileName);
  102. //$mediaSet = 100; //new KDLMediaDataSet();
  103. KalturaLog::log( "....S-->".$mediaSet->ToString());
  104. // unset($targetList); // Remarked by Tan-Tan $targetList doesn't exist
  105. $targetList = array();
  106. $errors = array();
  107. $warnings = array();
  108. {
  109. $dlPrc = new KDLProcessor();
  110. $dlPrc->Generate($mediaSet, $profile, $targetList);
  111. $dlPrc->_targets=$targetList;
  112. $errors = $errors + $dlPrc->get_errors();
  113. $warnings = $warnings + $dlPrc->get_warnings();
  114. if(count($errors)>0)
  115. $rv = false;
  116. else
  117. $rv = true;
  118. }
  119. if($rv==false){
  120. KalturaLog::log( "....E==>");
  121. print_r($errors);
  122. KalturaLog::log( "\n");
  123. }
  124. KalturaLog::log( "....W==>");
  125. print_r($warnings);
  126. KalturaLog::log( "\n");
  127. if($profile==null)
  128. return;
  129. $xmlStr = KDLProcessor::ProceessFlavorsForCollection($targetList);
  130. KalturaLog::log(__METHOD__."-->XML-->\n".print_r($xmlStr,true)."\n<--");
  131. foreach ($targetList as $target){
  132. $output = array();
  133. $rv = 0;
  134. KalturaLog::log( "...T-->".$target->ToString());
  135. $outFile = "aaa1.mp4";
  136. if(file_exists($outFile)) unlink($outFile);
  137. $cmdLineGenerator = $target->SetTranscoderCmdLineGenerator($inFile,$outFile);
  138. $cmdLineGenerator->_clipDur = 10000;
  139. $exeStr = "FFMpeg ".$cmdLineGenerator->FFMpeg(null);
  140. // KalturaLog::log( ".CMD-->".$exeStr);
  141. $exeStr = "cli_encode ".$cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::ON2), 1000);
  142. kLog::log( ".CMD-->".$exeStr);
  143. $exeStr = "mencoder ".$cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::MENCODER), 1000);
  144. kLog::log( ".CMD-->".$exeStr);
  145. $exeStr = "ffmpeg ".$cmdLineGenerator->Generate(new KDLOperationParams(KDLTranscoders::FFMPEG), 1000);
  146. kLog::log( ".CMD-->".$exeStr);
  147. exec($exeStr, $output, $rv);
  148. kLog::log( "..RV-->In".$inFile."==>");
  149. if(!file_exists($outFile) || filesize($outFile)==0)
  150. kLog::log( "Failed");
  151. else {
  152. kLog::log( "Succeeded, Filesize:".filesize($outFile));
  153. $mediaInfoStr = shell_exec(MediaInfoProgram." ". realpath($outFile));
  154. $medLoader = new KDLMediaInfoLoader($mediaInfoStr);
  155. $product = new KDLFlavor();
  156. $medLoader->Load($product);
  157. $target->ValidateProduct($mediaSet, $product);
  158. kLog::log("\n".$mediaInfoStr);
  159. // kLog::log( ".PRD-->".$product->ToString());
  160. // unlink($outFile);
  161. }
  162. }
  163. }
  164. }
  165. /* ---------------------------
  166. * transcoderSetFuncTest
  167. */
  168. function transcoderSetFuncTest($oprObj, $transDictionary, $param2)
  169. {
  170. $trId = KDLUtils::trima($oprObj->_id);
  171. if(!is_null($transDictionary) && array_key_exists($trId, $transDictionary)){
  172. $oprObj->_id = $transDictionary[$trId];
  173. }
  174. if($oprObj->_id==KDLTranscoders::QUICK_TIME_PLAYER_TOOLS){
  175. $engineClassName = "KDLTranscoderQTPTools";
  176. }
  177. else if($oprObj->_id==KDLTranscoders::QT_FASTSTART){
  178. $engineClassName = "KDLOperatorQTFastStart";
  179. }
  180. else if($oprObj->_id==KDLTranscoders::AVIDEMUX){
  181. $engineClassName = "KDLOperatorAvidemux";
  182. }
  183. else if($oprObj->_id==KDLTranscoders::EXPRESSION_ENCODER){
  184. $engineClassName = "KDLOperatorExpressionEncoder";
  185. }
  186. else if($oprObj->_id==KDLTranscoders::PDF_CREATOR){
  187. $engineClassName = "KDLTranscoderPdfCreator";
  188. }
  189. else if($oprObj->_id==KDLTranscoders::PDF2SWF){
  190. $engineClassName = "KDLTranscoderPdf2Swf";
  191. }
  192. else {
  193. $engineClassName = "KDLOperatorWrapper";
  194. }
  195. $oprObj->_engine = new $engineClassName($oprObj->_id,"");
  196. }
  197. ?>