PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Vendor/phpvideotoolkit/adapters/ffmpeg-php/tests/test_ffmpeg.php

https://github.com/Wargo/reddevil
PHP | 118 lines | 91 code | 12 blank | 15 comment | 19 complexity | 5cd4e55f0a86b9aa44409c7d7e349608 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1, GPL-3.0
  1. <?
  2. /*
  3. * This test script is not part of the automatic regression tests. It serves
  4. * as a simple manual test script and an example of the syntax for calling
  5. * the ffmpeg-php functions
  6. *
  7. * To run it from the command line type 'php -q ffmpeg_test.php 'or from a
  8. * browser * copy this file into your web root and point your browser at it.
  9. */
  10. $extension = "ffmpeg";
  11. $extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
  12. $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;
  13. // load extension
  14. if (extension_loaded($extension)) {
  15. echo 'The FFMPEG-PHP module is loaded and therefore these tests will be carried out upon the module and not the ffmpeg class apapters';
  16. }
  17. else
  18. {
  19. require_once '../ffmpeg_movie.php';
  20. require_once '../ffmpeg_frame.php';
  21. require_once '../ffmpeg_animated_gif.php';
  22. }
  23. if (php_sapi_name() != 'cgi') {
  24. echo '<pre>';
  25. }
  26. $ignore_demo_files = true;
  27. $dir = dirname(dirname(dirname(dirname(__FILE__))));
  28. require_once $dir.'/examples/example-config.php';
  29. $tmp_dir = PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH.'tmp/';
  30. // printf("ffmpeg-php version string: %s\n", FFMPEG_PHP_VERSION_STRING);
  31. // printf("libavcodec build number: %d\n", LIBAVCODEC_BUILD_NUMBER);
  32. // printf("libavcodec version number: %d\n", LIBAVCODEC_VERSION_NUMBER);
  33. echo "--------------------";
  34. print_class_methods("ffmpeg_movie");
  35. echo "\n\n--------------------";
  36. print_class_methods("ffmpeg_frame");
  37. echo "\n\n--------------------";
  38. print_class_methods("ffmpeg_animated_gif");
  39. echo "\n\n--------------------\n";
  40. // get an array for movies from the test media directory
  41. $movies = getDirFiles($dir.'/examples/to-be-processed');
  42. // print_r($movies);
  43. foreach($movies as $movie) {
  44. $mov = new PHPVideoToolkit_movie($movie, false, $tmp_dir);
  45. printf("file name = %s\n", $mov->getFileName());
  46. printf("duration = %s seconds\n", $mov->getDuration());
  47. printf("frame count = %s\n", $mov->getFrameCount());
  48. printf("frame rate = %0.3f fps\n", $mov->getFrameRate());
  49. printf("comment = %s\n", $mov->getComment());
  50. printf("title = %s\n", $mov->getTitle());
  51. printf("author = %s\n", $mov->getAuthor());
  52. printf("copyright = %s\n", $mov->getCopyright());
  53. printf("get bit rate = %d\n", $mov->getBitRate());
  54. printf("has audio = %s\n", $mov->hasAudio() == 0 ? 'No' : 'Yes');
  55. if ($mov->hasAudio()) {
  56. printf("get audio codec = %s\n", $mov->getAudioCodec());
  57. printf("get audio bit rate = %d\n", $mov->getAudioBitRate());
  58. printf("get audio sample rate = %d \n", $mov->getAudioSampleRate());
  59. printf("get audio channels = %s\n", $mov->getAudioChannels());
  60. }
  61. printf("has video = %s\n", $mov->hasVideo() == 0 ? 'No' : 'Yes');
  62. if ($mov->hasVideo()) {
  63. printf("frame height = %d pixels\n", $mov->getFrameHeight());
  64. printf("frame width = %d pixels\n", $mov->getFrameWidth());
  65. printf("get video codec = %s\n", $mov->getVideoCodec());
  66. printf("get video bit rate = %d\n", $mov->getVideoBitRate());
  67. printf("get pixel format = %s\n", $mov->getPixelFormat());
  68. printf("get pixel aspect ratio = %s\n", $mov->getPixelAspectRatio());
  69. printf("get frame = %s\n", is_object($mov->getFrame(10)) ? 'true' : 'false');
  70. printf("get frame number = %d\n", $mov->getFrameNumber());
  71. }
  72. echo "\n\n--------------------\n";
  73. }
  74. if (php_sapi_name() != 'cgi') {
  75. echo '</pre>';
  76. }
  77. /* FUNCTIONS */
  78. function print_class_methods($class) {
  79. echo "\nMethods available in class '$class':\n";
  80. $methods = get_class_methods($class);
  81. if (is_array($methods)) {
  82. foreach($methods as $method) {
  83. echo $method . "\n";
  84. }
  85. } else {
  86. echo "No Methods Defined\n";
  87. }
  88. }
  89. function getDirFiles($dirPath)
  90. {
  91. if ($handle = opendir($dirPath))
  92. {
  93. while (false !== ($file = readdir($handle))) {
  94. if(strpos($file, '.') !== 0)
  95. {
  96. $fullpath = $dirPath . '/' . $file;
  97. $info = pathinfo($fullpath);
  98. if (!is_dir($fullpath) && $file != "CVS" && $info['extension'] != 'jpg')
  99. $filesArr[] = trim($fullpath);
  100. }
  101. }
  102. closedir($handle);
  103. }
  104. return $filesArr;
  105. }
  106. ?>