Fixed : Conversion Myself -_-

This commit is contained in:
Arslan Hassan 2014-11-22 15:22:41 +00:00
parent d87b464ac5
commit db5bbed7ed
9 changed files with 2237 additions and 1473 deletions

View file

@ -165,11 +165,15 @@ switch($mode)
//exec(php_path()." -q ".BASEDIR."/actions/video_convert.php &> /dev/null &"); //exec(php_path()." -q ".BASEDIR."/actions/video_convert.php &> /dev/null &");
if (stristr(PHP_OS, 'WIN')) { if (stristr(PHP_OS, 'WIN')) {
//echo php_path()." -q ".BASEDIR."/actions/video_convert_test.php $targetFileName"; //echo php_path()." -q ".BASEDIR."/actions/video_convert_test.php $targetFileName";
exec(php_path()." -q ".BASEDIR."/actions/video_convert_test.php $targetFileName"); exec(php_path()." -q ".BASEDIR."/actions/video_convert.php $targetFileName");
}elseif(stristr(PHP_OS, 'darwin'))
{
exec(php_path()." -q ".BASEDIR."/actions/video_convert.php $targetFileName </dev/null >/dev/null &");
} else { } else {
// for ubuntu or linux // for ubuntu or linux
//echo php_path()." -q ".BASEDIR."/actions/video_convert_test.php $targetFileName > /dev/null &"; //echo php_path()." -q ".BASEDIR."/actions/video_convert_test.php $targetFileName > /dev/null &";
exec(php_path()." -q ".BASEDIR."/actions/video_convert_test.php $targetFileName > /dev/null &"); exec(php_path()." -q ".BASEDIR."/actions/video_convert.php $targetFileName > /dev/null &");
} }
} }

View file

@ -1,210 +1,210 @@
<?php <?php
/**
* Written by : Arslan Hassan // This script runs only via command line
* Software : ClipBucket v2
* License : Attribution Assurance License -- http://www.opensource.org/licenses/attribution.php include(dirname(__FILE__)."/../includes/config.inc.php");
* require_once(dirname(dirname(__FILE__))."/includes/classes/sLog.php");
* I have done MANY experiments on video conversion define("MP4Box_BINARY",get_binaries('MP4Box'));
* so these results are the best possible output define("FLVTool2_BINARY",get_binaries('flvtool2'));
* you can further discuss about it on forums.clip-bucket.com define('FFMPEG_BINARY', get_binaries('ffmpeg'));
**/
/*
getting the aguments
$argv[1] => first argument, in our case its the path of the file
ini_set('mysql.connect_timeout','6000'); */
$log = new SLog();
$in_bg_cron = true;
//error_reporting(E_ALL);
include(dirname(__FILE__)."/../includes/config.inc.php");
//Calling Cron Functions $fileName = (isset($argv[1])) ? $argv[1] : false;
cb_call_functions('video_convert_cron'); $dosleep = (isset($argv[2])) ? $argv[2] : '';
//$fileName = "/home/sajjad/Desktop/abc.mp4";
$server_friendly = config('server_friendly_conversion'); $log->newSection("Starting Conversion Log");
$use_crons = config('use_crons'); $log->writeLine("File to be converted", $fileName, false);
if($server_friendly=='yes' && $use_crons=='yes'){ $status = "Successful";
/* /*
Thanks to Erickson Reyes ercbluemonday at yahoo dot com | so processes dont overlap Getting the videos which are currently in our queue
ref : http://www.php.net/manual/en/function.getmypid.php#94531 waiting for conversion
*/ */
// Initialize variables if(isset($_GET['test']))
$found = 0; $queue_details = get_queued_video(false,$fileName);
$file = basename(__FILE__); else
$commands = array(); $queue_details = get_queued_video(TRUE,$fileName);
// Get running processes.
exec("ps w", $commands);
// If processes are found $fileDir = $queue_details["date_added"];
if (count($commands) > 0) { $dateAdded = explode(" ", $fileDir);
foreach ($commands as $command) { $dateAdded = array_shift($dateAdded);
if (strpos($command, $file) === false) { $fileDir = implode("/", explode("-", $dateAdded));
// Do nothin' //logData($fileDir);
}
else { /*
// Let's count how many times the file is found. Getting the file information from the queue for conversion
$found++; */
}
} $tmp_file = $queue_details['cqueue_name'];
} $tmp_ext = $queue_details['cqueue_tmp_ext'];
$ext = $queue_details['cqueue_ext'];
// If the instance of the file is found more than once. $outputFileName = $tmp_file;
if ($found > 1) { if(!empty($tmp_file)){
echo "Another process is running.\n";
die(); $temp_file = TEMP_DIR.'/'.$tmp_file.'.'.$tmp_ext;
} $orig_file = CON_DIR.'/'.$tmp_file.'.'.$ext;
}
/*
$SYSTEM_OS = $row['sys_os'] ? $row['sys_os'] : 'linux'; Delete the uploaded file from temp directory
and move it into the conversion queue directory for conversion
//Including FFMPEG CLASS */
require_once(BASEDIR.'/includes/classes/conversion/ffmpeg.class.php');
if(isset($_GET['test']))
if($argv[1]) copy($temp_file,$orig_file);
$fileName = $argv[1]; else
else rename($temp_file,$orig_file);
$fileName = false;
/*
if($argv[2] == 'sleep') Preparing the configurations for video conversion from database
$dosleep = 'sleep'; */
else
$dosleep = ''; $configs = array(
'format' => 'mp4',
//Get Video 'video_codec'=> config('video_codec'),
$queue_details = get_queued_video(TRUE,$fileName); 'audio_codec'=> config('audio_codec'),
if(!$queue_details) 'audio_rate'=> config("srate"),
exit("Nothing to do"); 'audio_bitrate'=> config("sbrate"),
'video_rate'=> config("vrate"),
'video_bitrate'=> config("vbrate"),
//Setting up details, moving files 'video_bitrate_hd'=> config("vbrate_hd"),
$tmp_file = $queue_details['cqueue_name']; 'normal_res' => config('normal_resolution'),
$tmp_ext = $queue_details['cqueue_tmp_ext']; 'high_res' => config('high_resolution'),
$ext = $queue_details['cqueue_ext']; 'max_video_duration' => config('max_video_duration'),
'resize'=>'max',
if(!empty($tmp_file)){ 'outputPath' => $fileDir,
);
$temp_file = TEMP_DIR.'/'.$tmp_file.'.'.$tmp_ext; require_once(BASEDIR.'/includes/classes/conversion/ffmpeg.class.php');
$orig_file = CON_DIR.'/'.$tmp_file.'.'.$ext;
//copy($temp_file,$orig_file); $ffmpeg = new FFMpeg($configs, $log);
rename($temp_file,$orig_file); $ffmpeg->convertVideo($orig_file);
$res169 = array();
$res169['240'] = array('428','240'); //exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $orig_file");
$res169['360'] = array('640','360'); //exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php &> /dev/null &");
$res169['480'] = array('853','480');
$res169['720'] = array('1280','720'); if (stristr(PHP_OS, 'WIN'))
$res169['1080'] = array('1920','1080'); {
exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $orig_file $dosleep");
$res43 = array(); }elseif(stristr(PHP_OS, 'darwin'))
$res43['240'] = array('320','240'); {
$res43['360'] = array('480','360'); exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $orig_file $dosleep </dev/null >/dev/null &");
$res43['480'] = array('640','480');
$res43['720'] = array('960','720'); } else {
$res43['1080'] = array('1440','1080'); exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $orig_file $dosleep &> /dev/null &");
}
$configs = array
( if(!isset($_GET['test']))
'use_video_rate' => true, unlink($orig_file);
'use_video_bit_rate' => true,
'use_audio_rate' => true,
'use_audio_bit_rate' => true, }
'use_audio_codec' => true,
'use_video_codec' => true,
'format' => 'mp4', exit();
'video_codec'=> config('video_codec'), $str = "/".date("Y")."/".date("m")."/".date("d")."/";
'audio_codec'=> config('audio_codec'), $orig_file1 = BASEDIR.'/files/videos'.$str.$tmp_file.'-sd.'.$ext;
'audio_rate'=> config("srate"),
'audio_bitrate'=> config("sbrate"), if($orig_file1)
'video_rate'=> config("vrate"), {
'video_bitrate'=> config("vbrate"), $status = "Successful";
'normal_res' => config('normal_resolution'), if(PHP_OS == "Linux")
'high_res' => config('high_resolution'), {
'max_video_duration' => config('max_video_duration'), $ffMpegPath = FFMPEG_BINARY;
'res169' => $res169, $out = shell_exec($ffMpegPath." -i ".$orig_file1." -acodec copy -vcodec copy -y -f null /dev/null 2>&1");
'res43' => $res43, sleep(1);
'resize'=>'max'
); $log->writeLog();
$len = strlen($out);
$findme = 'Duration';
/** $findme1 = 'start';
* Calling Functions before converting Video $pos = strpos($out, $findme);
*/ $pos = $pos + 10;
if(get_functions('before_convert_functions')) $pos1 = strpos($out, $findme1);
{ $bw = $len - ($pos1 - 5);
foreach(get_functions('before_convert_functions') as $func) $rest = substr($out, $pos, -$bw);
{ $duration = explode(':',$rest);
if(@function_exists($func)) //Convert Duration to seconds
$func(); $hours = $duration[0];
} $minutes = $duration[1];
} $seconds = $duration[2];
$hours = $hours * 60 * 60;
$ffmpeg = new ffmpeg($orig_file); $minutes = $minutes * 60;
$ffmpeg->configs = $configs;
$ffmpeg->gen_thumbs = TRUE; $duration = $hours+$minutes+$seconds;
$ffmpeg->gen_big_thumb = TRUE; //$duration = (int) $ffmpeg->videoDetails['duration'];
$ffmpeg->num_of_thumbs = config('num_thumbs'); if($duration > 0)
$ffmpeg->thumb_dim = config('thumb_width')."x".config('thumb_height'); {
$ffmpeg->big_thumb_dim = config('big_thumb_width')."x".config('big_thumb_height');
$ffmpeg->tmp_dir = TEMP_DIR; $status = "Successful";
$ffmpeg->input_ext = $ext; $log->writeLine("Conversion Result", "Successful");
$ffmpeg->output_file = VIDEOS_DIR.'/'.$tmp_file.'-sd.mp4'; }
$ffmpeg->hq_output_file = VIDEOS_DIR.'/'.$tmp_file.'-hd.mp4'; else
$str = "/".date("Y")."/".date("m")."/".date("d")."/"; {
$ffmpeg->log_file = LOGS_DIR.$str.$tmp_file.'.log'; $status = "Failure";
//$ffmpeg->remove_input = TRUE; $log->writeLine("Conversion Result", "Failure");
$ffmpeg->keep_original = config('keep_original'); }
$ffmpeg->original_output_path = ORIGINAL_DIR.'/'.$tmp_file.'.'.$ext; }
$ffmpeg->ClipBucket(); else
{
$ffMpegPath = FFMPEG_BINARY;
$out = shell_exec($ffMpegPath." -i ".$orig_file1." -acodec copy -vcodec copy -y -f null /dev/null 2>&1");
sleep(1);
////exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php &> /dev/null &");
if (stristr(PHP_OS, 'WIN')) $log->writeLog();
{ $len = strlen($out);
exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $fileName $dosleep"); $findme = 'Duration';
} else { $findme1 = 'start';
exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $fileName $dosleep &> /dev/null &"); $pos = strpos($out, $findme);
} $pos = $pos + 10;
$pos1 = strpos($out, $findme1);
$bw = $len - ($pos1 - 5);
//Converting File In HD Format $rest = substr($out, $pos, -$bw);
if($ffmpeg->input_details['video_height']>'719') $duration = explode(':',$rest);
$hq_output = config('hq_output'); //Convert Duration to seconds
else $hours = $duration[0];
$hq_output = 'no'; $minutes = $duration[1];
$seconds = $duration[2];
if($hq_output=='yes' && !$ffmpeg->failed_reason) $hours = $hours * 60 * 60;
{ $minutes = $minutes * 60;
while(1)
{ $duration = $hours+$minutes+$seconds;
$use_crons = config('use_crons'); //$duration = (int) $ffmpeg->videoDetails['size'];
if($duration > "0")
if(!$ffmpeg->isLocked(PROCESSESS_AT_ONCE) || $use_crons=='yes' || !$ffmpeg->set_conv_lock) {
{
$status = "Successful";
$ffmpeg->convert_to_hd();
if($ffmpeg->lock_file && file_exists($ffmpeg->lock_file)) $db->update(tbl('video'), array("duration"), array($duration), " file_name = '{$outputFileName}'");
unlink($ffmpeg->lock_file); $db->update(tbl('video'), array("status"), array($status), " file_name = '{$outputFileName}'");
break; $log->writeLine("Conversion Result", "Successful");
} }
else
{
if($use_crons=='no') $status = "Failed";
sleep(10); $db->update(tbl('video'), array("duration"), array($duration), " file_name = '{$outputFileName}'");
else $db->update(tbl('video'), array("status"), array($status), " file_name = '{$outputFileName}'");
break; $log->writeLine("Conversion Result", "Failed");
} }
} }
}
// update the video details in the database as successful conversion or not and video duration
unlink($ffmpeg->input_file); $myfile = fopen("123.txt", "w");
} $txt = " file_name = '{$outputFileName}'";
fwrite($myfile, $duration.$status.$txt);
fclose($myfile);
?>

View file

@ -32,8 +32,26 @@ if($file_details)
{ {
$fileDetailsArray = explode("\n", $file_details); $fileDetailsArray = explode("\n", $file_details);
$file_details = implode("<br>", $fileDetailsArray); $file_details = implode("<br>", $fileDetailsArray);
$videoDetails = json_decode($fileDetailsArray[187]);
$video_details = '[]';
$start = 0;
foreach($fileDetailsArray as $key => $value)
{
if($start) $start++;
if($value=='videoDetails')
{
$start = 1;
}
if($start==3)
{
$video_details = $value;
}
}
$videoDetails = json_decode($video_details);
$videoDetails->file_name = $file_name; $videoDetails->file_name = $file_name;
assign('data',$file_details); assign('data',$file_details);
assign('videoDetails',$videoDetails); assign('videoDetails',$videoDetails);
} }

View file

@ -154,7 +154,7 @@ INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES
(151, 'player_logo_file', 'logo.jpg'), (151, 'player_logo_file', 'logo.jpg'),
(152, 'logo_placement', 'tl'), (152, 'logo_placement', 'tl'),
(153, 'buffer_time', '5'), (153, 'buffer_time', '5'),
(155, 'use_ffmpeg_vf', 'no'), (155, 'use_ffmpeg_vf', 'yes'),
(224, 'own_photo_rating', ''), (224, 'own_photo_rating', ''),
(157, 'mail_type', 'mail'), (157, 'mail_type', 'mail'),
(158, 'smtp_host', ''), (158, 'smtp_host', ''),

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -37,6 +37,7 @@ class SLog{
} }
public function writeLog(){ public function writeLog(){
if(!$this->logFile) return;
$this->fileHandle = fopen($this->logFile, "w+"); $this->fileHandle = fopen($this->logFile, "w+");
fwrite($this->fileHandle, $this->logData); fwrite($this->fileHandle, $this->logData);
fclose($this->fileHandle); fclose($this->fileHandle);

View file

@ -3852,9 +3852,11 @@
function get_db_size() function get_db_size()
{ {
$result = mysql_query("SHOW TABLE STATUS"); global $db;
$dbsize = 0; $results = $db->_select("SHOW TABLE STATUS");
while( $row = mysql_fetch_array( $result ) )
foreach($results as $row)
{ {
$dbsize += $row[ "Data_length" ] + $row[ "Index_length" ]; $dbsize += $row[ "Data_length" ] + $row[ "Index_length" ];
} }

View file

@ -837,8 +837,11 @@ function parse_duration($log)
{ {
$duration = false; $duration = false;
$log_details = get_file_details($log); $log_details = get_file_details($log);
if(isset($log['output_duration']))
$duration = $log['output_duration']; $duration = $log['output_duration'];
if(!$duration || !is_numeric($duration))
if((!$duration || !is_numeric($duration)) && isset($log['duration']))
$duration = $log['duration']; $duration = $log['duration'];
if(!$duration || !is_numeric($duration)) if(!$duration || !is_numeric($duration))