Guest User

Untitled

a guest
Apr 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. <?php
  2. class videoEditor {
  3.  
  4. public $config;
  5. public $output;
  6.  
  7. public function __construct( $config = array() )
  8. {
  9.  
  10. $this->config = array_merge( array(
  11. 'video_path' => '',
  12. 'lang' => 'en',
  13. 'upload_allowed' => array('mp4','flv','avi','mpg','webm'),
  14. 'out_video_formats' => array('mp4','flv','webm','ogv'),
  15. 'access_permissions' => $config['access_permissions'], //array( 'upload', 'delete_output_files', 'delete_input_files', 'create_video' ),
  16. 'out_video_sizes' => array( 360, 480, 576, 720),
  17. 'youtube_download' => array( 'quality' => 'medium', 'type' => 'mp4' ),
  18. 'max_output_files_count' => false,
  19. 'use_mp4box' => true,
  20. 'use_mencoder' => true,
  21. 'use_avidemux' => true,
  22. 'ffmpeg_string_arr' => array(
  23. 'flv' => '-vcodec flv -s {resolution} -aspect {aspect} -b:v {quality} -acodec libmp3lame -b:a 64k',//libfaac | aac
  24. 'mp4' => '-vcodec libx264 -s {resolution} -aspect {aspect} -b:v {quality} -acodec libmp3lame -b:a 64k',//mpeg4
  25. 'webm' => '-vcodec libvpx -s {resolution} -aspect {aspect} -b:v {quality} -acodec libvorbis -b:a 64k',
  26. 'ogv' => '-vcodec libtheora -s {resolution} -aspect {aspect} -b:v {quality} -acodec libvorbis -b:a 64k'
  27. )
  28. ), $config );
  29.  
  30. $this->output = array( 'data' => array(), 'msg' => '', 'error' => false );
  31.  
  32. }
  33.  
  34. /**
  35. * utf8_basename
  36. *
  37. * @param string $file_path
  38. */
  39. public function utf8_basename( $file_path )
  40. {
  41.  
  42. $temp_arr = explode('/',$file_path);
  43.  
  44. return array_pop( $temp_arr );
  45.  
  46. }
  47.  
  48. /**
  49. * getFrame
  50. *
  51. * @param string $time
  52. * @param string $video_file_path
  53. * @param string $file_out_path
  54. */
  55. public function getFrame( $time, $video_file_path, $file_out_path )
  56. {
  57. //mencoder
  58. if( $this->config['use_mencoder'] ){
  59.  
  60. $temp_dir = $this->config['tmp_path'] . $this->config['session_id'];
  61. if( !is_dir( $temp_dir ) ){
  62. mkdir( $temp_dir, 0777 );
  63. }
  64. $seconds = $this->timeToSeconds( $time );
  65. $command = "cd '{$temp_dir}' && mplayer -frames 1 -ss {$seconds} -vo jpeg -nosound '{$video_file_path}'";
  66.  
  67. @exec( $command );
  68.  
  69. $sceenshot_path = $temp_dir . '/00000001.jpg';
  70.  
  71. if( file_exists($sceenshot_path) ){
  72. @rename( $sceenshot_path, $file_out_path );
  73. @chmod( $file_out_path, 0777 );
  74. //delete temp directory
  75. $this->deleteDirectory( $temp_dir );
  76. }
  77.  
  78. }
  79. //ffmpeg
  80. else{
  81.  
  82. $command = "ffmpeg -ss {$time} -i '{$video_file_path}' -frames:v 1 -y '{$file_out_path}' 2>&1";
  83.  
  84. exec( $command );
  85. @chmod( $file_out_path, 0777 );
  86.  
  87. }
  88.  
  89. $this->logging( $command );
  90.  
  91. return $this->utf8_basename( $file_out_path );
  92.  
  93. }
  94.  
  95. /**
  96. * getFilesList
  97. *
  98. * @param string $dir_path
  99. */
  100. public function getFilesList( $dir_path )
  101. {
  102.  
  103. $out = array();
  104.  
  105. $files = array_diff(scandir($dir_path), array(".", ".."));
  106.  
  107. foreach( $files as $file ){
  108. array_push( $out, $dir_path . $file );
  109. }
  110.  
  111. usort($out, function($a, $b) {
  112. return filemtime($a) < filemtime($b);
  113. });
  114.  
  115. return $out;
  116.  
  117. }
  118.  
  119. /**
  120. * timeToSeconds
  121. *
  122. * @param string $time
  123. */
  124. public function timeToSeconds( $time )
  125. {
  126.  
  127. $output = 0;
  128.  
  129. $time_arr = explode(':',$time);
  130. $t = array(3600, 60, 1);
  131.  
  132. foreach( $time_arr as $k => $tt ){
  133. $output += ( floatval( $tt ) * $t[$k] );
  134. }
  135.  
  136. return $output;
  137.  
  138. }
  139.  
  140.  
  141. /**
  142. * upload
  143. *
  144. * @param string $link
  145. */
  146. public function action_upload( $link )
  147. {
  148.  
  149. if( !$this->isPermitted( 'upload' ) ){
  150. header( "refresh:4;url=" . str_replace('action.php','',$_SERVER['PHP_SELF']) );
  151. header( "Content-Type: text/html; charset=UTF-8" );
  152. echo LANG_NOT_PERMITTED;
  153. exit;
  154. }
  155.  
  156. $link = !empty( $_POST['link'] ) && !is_array( $_POST['link'] ) ? urldecode(trim( $_POST['link'] )) : '';
  157.  
  158. if( $link ){
  159.  
  160. if( ( strpos($link, 'youtube.com/') !== false) || (strpos($link, 'youtu.be/') !== false)) {
  161.  
  162. $upload_path = $this->config['video_path'] . date('d-m-y_H-i-s') . '.mp4';
  163. $this->downloadFromYoutube( $link, $upload_path, $this->config['youtube_download'] );
  164.  
  165. }else{
  166.  
  167. $name = $this->utf8_basename( $link );
  168. $temp_arr = explode('.',$name);
  169. $ext = end($temp_arr);
  170. if( in_array( $ext, $this->config['upload_allowed'] ) ){
  171. $file_name = $name;//date('d-m-y_H-i-s') . '.' . $ext;
  172. file_put_contents( $this->config['video_path'].$file_name, file_get_contents( $link ) );
  173. @chmod( $this->config['video_path'].$file_name, 0777 );
  174. }
  175.  
  176. }
  177.  
  178. }else{
  179.  
  180. if ( $_FILES["file"]["error"] == UPLOAD_ERR_OK ) {
  181.  
  182. if ($error == UPLOAD_ERR_OK) {
  183.  
  184. $tmp_name = $_FILES["file"]["tmp_name"];
  185. $name = $_FILES["file"]["name"];
  186. $temp_arr = explode('.',$name);
  187. $ext = end($temp_arr);
  188.  
  189. if( in_array( $ext, $this->config['upload_allowed'] ) ){
  190.  
  191. $file_name = $name;//date('d-m-y_H-i-s') . '.' . $ext;
  192. move_uploaded_file($tmp_name, $this->config['video_path'] . $file_name);
  193. @chmod( $this->config['video_path'] . $file_name, 0777 );
  194. }
  195.  
  196. header("Location: " . str_replace('action.php','',$_SERVER['PHP_SELF']) );
  197. }
  198. }
  199. }
  200. }
  201. /**
  202. * remove_video
  203. *
  204. */
  205. public function action_remove_video()
  206. {
  207.  
  208. $name = !empty( $_POST['name'] ) && !is_array( $_POST['name'] ) ? urldecode(trim( $_POST['name'] )) : '';
  209. $type = !empty( $_POST['type'] ) && !is_array( $_POST['type'] ) ? urldecode(trim( $_POST['type'] )) : 'input';
  210. }
  211. }
Add Comment
Please, Sign In to add comment