PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/html/modules/fileManager/class/Ffmpeg.class.php

http://xoopscube-modules.googlecode.com/
PHP | 121 lines | 68 code | 12 blank | 41 comment | 16 complexity | 7170f16aef025d0f275dd8c468873a38 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * Filemaneger
  4. * (C)2007-2009 BeaBo Japan by Hiroki Seike
  5. * http://beabo.net/
  6. **/
  7. if (!defined('XOOPS_ROOT_PATH')) exit();
  8. class Ffmpeg {
  9. // image capture
  10. function imageCapture($file) {
  11. $root =& XCube_Root::getSingleton();
  12. $mConfig = $root->mContext->mModuleConfig;
  13. // get dirctory permission
  14. $dirPermission = fileperms(dirname(XOOPS_UPLOAD_PATH . $file)) ;
  15. // dirctory permission is 0777
  16. if($dirPermission =='16895') {
  17. // check is this movie file ?
  18. if (Ffmpeg::checkMovie($file)) {
  19. $captureFilePath = XOOPS_UPLOAD_PATH . $file ;
  20. $fineName = basename($file, substr( strrchr( $file, "." ), 0));
  21. $imageFileName = Ffmpeg::getBaseFile($captureFilePath) .'.jpg' ;
  22. // ffmpeg command path
  23. if ($mConfig['ffmpegpath'] != '') {
  24. putenv("PATH=".$mConfig['ffmpegpath']."");
  25. }
  26. // image capture
  27. system("ffmpeg -i ".$captureFilePath." -ss ".$mConfig['ffmpegcapture']." -vcodec mjpeg -vframes 1 -an -f rawvideo -y ". $imageFileName);
  28. return true;
  29. } else {
  30. // error : file extension
  31. return false;
  32. }
  33. } else {
  34. // error : dirctory permission
  35. return false;
  36. }
  37. }
  38. // media convert
  39. function mediaConvert($file) {
  40. $root =& XCube_Root::getSingleton();
  41. $mConfig = $root->mContext->mModuleConfig;
  42. // get dirctory permission
  43. $dirPermission = fileperms(dirname(XOOPS_UPLOAD_PATH . $file)) ;
  44. // dirctory permission is 0777
  45. if($dirPermission =='16895') {
  46. // check is this movie file ?
  47. if (Ffmpeg::checkMovie($file)) {
  48. // you need check movie file
  49. $captureFilePath = XOOPS_UPLOAD_PATH . $file ;
  50. $fineName = basename($file, substr( strrchr( $file, "." ), 0));
  51. $convertFileName = Ffmpeg::getBaseFile($captureFilePath) .'.flv' ;
  52. $imageFileName = Ffmpeg::getBaseFile($captureFilePath) .'.jpg' ;
  53. // ffmpeg command path
  54. if ($mConfig['ffmpegpath'] != '') {
  55. putenv("PATH=".$mConfig['ffmpegpath']."");
  56. }
  57. ini_set('max_execution_time', 3600);
  58. // file convert options
  59. system("ffmpeg -i ". $captureFilePath. " -ar 44100 -s qvga -y ". $convertFileName); // qvga - defult
  60. // you need chenge your server settings and ffmpeg version
  61. // etc options(saample)
  62. // chenge to your server
  63. // system("ffmpeg -i ". $captureFilePath. " -ar 44100 -b 1150k -s vga -y ". $convertFileName); // vga bitrate 128k
  64. // system("ffmpeg -i ". $captureFilePath. " -ar 44100 -b 128k -s vga -y ". $convertFileName); // vga bitrate 128k
  65. // system("ffmpeg -i ". $captureFilePath. " -ar 44100 -s vga -y ". $convertFileName); // vga
  66. // system("ffmpeg -i ". $captureFilePath. " -ar 44100 -s qvga -y ". $convertFileName ." > /dev/null &");; // qvga
  67. // image capture
  68. // You need convrt movie file to capture image
  69. // system("ffmpeg -i ". $convertFileName. " -ss ". $mConfig['ffmpegcapture']. " -vcodec mjpeg -vframes 1 -an -f rawvideo -y ". $imageFileName);
  70. return true;
  71. } else {
  72. // error : file extension
  73. return false;
  74. }
  75. } else {
  76. // error : dirctory permission
  77. return false;
  78. }
  79. }
  80. // check movie file
  81. function checkMovie($fileName = '') {
  82. if ($fileName == '') {
  83. return false;
  84. }
  85. // $movie file extension white list
  86. // ffmpegmoviefile sample is 'flv|avi|mwv|mov|mpg|qt|mov|3gp|3gp2|mp4'
  87. $movieTypeWhitelist = $mConfig['ffmpegmoviefile'];
  88. $fileExtension = substr( strrchr( $fileName, "." ), 1);
  89. if (eregi($movieTypeWhitelist, $fileExtension)) {
  90. return true;
  91. }
  92. return false;
  93. }
  94. // delete file extension
  95. // $path : /var/www/html/uploads/akb48/AKB48-sukart_hirari.flv
  96. // to : /var/www/html/uploads/akb48/AKB48-sukart_hirari
  97. function getBaseFile($path) {
  98. $fileNameCount = strlen($path) - strlen(strrchr( $path, "." )) ;
  99. return substr($path, 0, $fileNameCount);
  100. }
  101. // get path
  102. // $path : /var/www/html/uploads/akb48/AKB48-sukart_hirari.flv
  103. // to : /var/www/html/uploads/akb48/
  104. function getBasePath($path) {
  105. $fileNameCount = strlen($path) - strlen(strrchr( $path, "/" )) +1 ;
  106. return substr($path, 0, $fileNameCount);
  107. }
  108. }
  109. ?>