Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class videoEditor {
- public $config;
- public $output;
- public function __construct( $config = array() )
- {
- $this->config = array_merge( array(
- 'video_path' => '',
- 'lang' => 'en',
- 'upload_allowed' => array('mp4','flv','avi','mpg','webm'),
- 'out_video_formats' => array('mp4','flv','webm','ogv'),
- 'access_permissions' => $config['access_permissions'], //array( 'upload', 'delete_output_files', 'delete_input_files', 'create_video' ),
- 'out_video_sizes' => array( 360, 480, 576, 720),
- 'youtube_download' => array( 'quality' => 'medium', 'type' => 'mp4' ),
- 'max_output_files_count' => false,
- 'use_mp4box' => true,
- 'use_mencoder' => true,
- 'use_avidemux' => true,
- 'ffmpeg_string_arr' => array(
- 'flv' => '-vcodec flv -s {resolution} -aspect {aspect} -b:v {quality} -acodec libmp3lame -b:a 64k',//libfaac | aac
- 'mp4' => '-vcodec libx264 -s {resolution} -aspect {aspect} -b:v {quality} -acodec libmp3lame -b:a 64k',//mpeg4
- 'webm' => '-vcodec libvpx -s {resolution} -aspect {aspect} -b:v {quality} -acodec libvorbis -b:a 64k',
- 'ogv' => '-vcodec libtheora -s {resolution} -aspect {aspect} -b:v {quality} -acodec libvorbis -b:a 64k'
- )
- ), $config );
- $this->output = array( 'data' => array(), 'msg' => '', 'error' => false );
- }
- /**
- * utf8_basename
- *
- * @param string $file_path
- */
- public function utf8_basename( $file_path )
- {
- $temp_arr = explode('/',$file_path);
- return array_pop( $temp_arr );
- }
- /**
- * getFrame
- *
- * @param string $time
- * @param string $video_file_path
- * @param string $file_out_path
- */
- public function getFrame( $time, $video_file_path, $file_out_path )
- {
- //mencoder
- if( $this->config['use_mencoder'] ){
- $temp_dir = $this->config['tmp_path'] . $this->config['session_id'];
- if( !is_dir( $temp_dir ) ){
- mkdir( $temp_dir, 0777 );
- }
- $seconds = $this->timeToSeconds( $time );
- $command = "cd '{$temp_dir}' && mplayer -frames 1 -ss {$seconds} -vo jpeg -nosound '{$video_file_path}'";
- @exec( $command );
- $sceenshot_path = $temp_dir . '/00000001.jpg';
- if( file_exists($sceenshot_path) ){
- @rename( $sceenshot_path, $file_out_path );
- @chmod( $file_out_path, 0777 );
- //delete temp directory
- $this->deleteDirectory( $temp_dir );
- }
- }
- //ffmpeg
- else{
- $command = "ffmpeg -ss {$time} -i '{$video_file_path}' -frames:v 1 -y '{$file_out_path}' 2>&1";
- exec( $command );
- @chmod( $file_out_path, 0777 );
- }
- $this->logging( $command );
- return $this->utf8_basename( $file_out_path );
- }
- /**
- * getFilesList
- *
- * @param string $dir_path
- */
- public function getFilesList( $dir_path )
- {
- $out = array();
- $files = array_diff(scandir($dir_path), array(".", ".."));
- foreach( $files as $file ){
- array_push( $out, $dir_path . $file );
- }
- usort($out, function($a, $b) {
- return filemtime($a) < filemtime($b);
- });
- return $out;
- }
- /**
- * timeToSeconds
- *
- * @param string $time
- */
- public function timeToSeconds( $time )
- {
- $output = 0;
- $time_arr = explode(':',$time);
- $t = array(3600, 60, 1);
- foreach( $time_arr as $k => $tt ){
- $output += ( floatval( $tt ) * $t[$k] );
- }
- return $output;
- }
- /**
- * upload
- *
- * @param string $link
- */
- public function action_upload( $link )
- {
- if( !$this->isPermitted( 'upload' ) ){
- header( "refresh:4;url=" . str_replace('action.php','',$_SERVER['PHP_SELF']) );
- header( "Content-Type: text/html; charset=UTF-8" );
- echo LANG_NOT_PERMITTED;
- exit;
- }
- $link = !empty( $_POST['link'] ) && !is_array( $_POST['link'] ) ? urldecode(trim( $_POST['link'] )) : '';
- if( $link ){
- if( ( strpos($link, 'youtube.com/') !== false) || (strpos($link, 'youtu.be/') !== false)) {
- $upload_path = $this->config['video_path'] . date('d-m-y_H-i-s') . '.mp4';
- $this->downloadFromYoutube( $link, $upload_path, $this->config['youtube_download'] );
- }else{
- $name = $this->utf8_basename( $link );
- $temp_arr = explode('.',$name);
- $ext = end($temp_arr);
- if( in_array( $ext, $this->config['upload_allowed'] ) ){
- $file_name = $name;//date('d-m-y_H-i-s') . '.' . $ext;
- file_put_contents( $this->config['video_path'].$file_name, file_get_contents( $link ) );
- @chmod( $this->config['video_path'].$file_name, 0777 );
- }
- }
- }else{
- if ( $_FILES["file"]["error"] == UPLOAD_ERR_OK ) {
- if ($error == UPLOAD_ERR_OK) {
- $tmp_name = $_FILES["file"]["tmp_name"];
- $name = $_FILES["file"]["name"];
- $temp_arr = explode('.',$name);
- $ext = end($temp_arr);
- if( in_array( $ext, $this->config['upload_allowed'] ) ){
- $file_name = $name;//date('d-m-y_H-i-s') . '.' . $ext;
- move_uploaded_file($tmp_name, $this->config['video_path'] . $file_name);
- @chmod( $this->config['video_path'] . $file_name, 0777 );
- }
- header("Location: " . str_replace('action.php','',$_SERVER['PHP_SELF']) );
- }
- }
- }
- }
- /**
- * remove_video
- *
- */
- public function action_remove_video()
- {
- $name = !empty( $_POST['name'] ) && !is_array( $_POST['name'] ) ? urldecode(trim( $_POST['name'] )) : '';
- $type = !empty( $_POST['type'] ) && !is_array( $_POST['type'] ) ? urldecode(trim( $_POST['type'] )) : 'input';
- }
- }
Add Comment
Please, Sign In to add comment