Fixed : Conversion Myself -_-
This commit is contained in:
parent
d87b464ac5
commit
db5bbed7ed
9 changed files with 2237 additions and 1473 deletions
|
@ -165,11 +165,15 @@ switch($mode)
|
|||
//exec(php_path()." -q ".BASEDIR."/actions/video_convert.php &> /dev/null &");
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
//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 {
|
||||
// for ubuntu or linux
|
||||
//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 &");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,210 +1,210 @@
|
|||
<?php
|
||||
/**
|
||||
* Written by : Arslan Hassan
|
||||
* Software : ClipBucket v2
|
||||
* License : Attribution Assurance License -- http://www.opensource.org/licenses/attribution.php
|
||||
*
|
||||
* I have done MANY experiments on video conversion
|
||||
* so these results are the best possible output
|
||||
* you can further discuss about it on forums.clip-bucket.com
|
||||
**/
|
||||
|
||||
|
||||
|
||||
ini_set('mysql.connect_timeout','6000');
|
||||
|
||||
$in_bg_cron = true;
|
||||
|
||||
include(dirname(__FILE__)."/../includes/config.inc.php");
|
||||
//Calling Cron Functions
|
||||
cb_call_functions('video_convert_cron');
|
||||
|
||||
$server_friendly = config('server_friendly_conversion');
|
||||
$use_crons = config('use_crons');
|
||||
if($server_friendly=='yes' && $use_crons=='yes'){
|
||||
/*
|
||||
Thanks to Erickson Reyes ercbluemonday at yahoo dot com | so processes dont overlap
|
||||
ref : http://www.php.net/manual/en/function.getmypid.php#94531
|
||||
*/
|
||||
|
||||
// Initialize variables
|
||||
$found = 0;
|
||||
$file = basename(__FILE__);
|
||||
$commands = array();
|
||||
|
||||
// Get running processes.
|
||||
exec("ps w", $commands);
|
||||
|
||||
// If processes are found
|
||||
if (count($commands) > 0) {
|
||||
foreach ($commands as $command) {
|
||||
if (strpos($command, $file) === false) {
|
||||
// Do nothin'
|
||||
}
|
||||
else {
|
||||
// Let's count how many times the file is found.
|
||||
$found++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the instance of the file is found more than once.
|
||||
if ($found > 1) {
|
||||
echo "Another process is running.\n";
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
$SYSTEM_OS = $row['sys_os'] ? $row['sys_os'] : 'linux';
|
||||
|
||||
//Including FFMPEG CLASS
|
||||
require_once(BASEDIR.'/includes/classes/conversion/ffmpeg.class.php');
|
||||
|
||||
if($argv[1])
|
||||
$fileName = $argv[1];
|
||||
else
|
||||
$fileName = false;
|
||||
|
||||
if($argv[2] == 'sleep')
|
||||
$dosleep = 'sleep';
|
||||
else
|
||||
$dosleep = '';
|
||||
|
||||
//Get Video
|
||||
$queue_details = get_queued_video(TRUE,$fileName);
|
||||
if(!$queue_details)
|
||||
exit("Nothing to do");
|
||||
|
||||
|
||||
//Setting up details, moving files
|
||||
$tmp_file = $queue_details['cqueue_name'];
|
||||
$tmp_ext = $queue_details['cqueue_tmp_ext'];
|
||||
$ext = $queue_details['cqueue_ext'];
|
||||
|
||||
if(!empty($tmp_file)){
|
||||
|
||||
|
||||
$temp_file = TEMP_DIR.'/'.$tmp_file.'.'.$tmp_ext;
|
||||
$orig_file = CON_DIR.'/'.$tmp_file.'.'.$ext;
|
||||
|
||||
//copy($temp_file,$orig_file);
|
||||
rename($temp_file,$orig_file);
|
||||
|
||||
$res169 = array();
|
||||
$res169['240'] = array('428','240');
|
||||
$res169['360'] = array('640','360');
|
||||
$res169['480'] = array('853','480');
|
||||
$res169['720'] = array('1280','720');
|
||||
$res169['1080'] = array('1920','1080');
|
||||
|
||||
$res43 = array();
|
||||
$res43['240'] = array('320','240');
|
||||
$res43['360'] = array('480','360');
|
||||
$res43['480'] = array('640','480');
|
||||
$res43['720'] = array('960','720');
|
||||
$res43['1080'] = array('1440','1080');
|
||||
|
||||
$configs = array
|
||||
(
|
||||
'use_video_rate' => true,
|
||||
'use_video_bit_rate' => true,
|
||||
'use_audio_rate' => true,
|
||||
'use_audio_bit_rate' => true,
|
||||
'use_audio_codec' => true,
|
||||
'use_video_codec' => true,
|
||||
'format' => 'mp4',
|
||||
'video_codec'=> config('video_codec'),
|
||||
'audio_codec'=> config('audio_codec'),
|
||||
'audio_rate'=> config("srate"),
|
||||
'audio_bitrate'=> config("sbrate"),
|
||||
'video_rate'=> config("vrate"),
|
||||
'video_bitrate'=> config("vbrate"),
|
||||
'normal_res' => config('normal_resolution'),
|
||||
'high_res' => config('high_resolution'),
|
||||
'max_video_duration' => config('max_video_duration'),
|
||||
'res169' => $res169,
|
||||
'res43' => $res43,
|
||||
'resize'=>'max'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Calling Functions before converting Video
|
||||
*/
|
||||
if(get_functions('before_convert_functions'))
|
||||
{
|
||||
foreach(get_functions('before_convert_functions') as $func)
|
||||
{
|
||||
if(@function_exists($func))
|
||||
$func();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$ffmpeg = new ffmpeg($orig_file);
|
||||
$ffmpeg->configs = $configs;
|
||||
$ffmpeg->gen_thumbs = TRUE;
|
||||
$ffmpeg->gen_big_thumb = TRUE;
|
||||
$ffmpeg->num_of_thumbs = config('num_thumbs');
|
||||
$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;
|
||||
$ffmpeg->input_ext = $ext;
|
||||
$ffmpeg->output_file = VIDEOS_DIR.'/'.$tmp_file.'-sd.mp4';
|
||||
$ffmpeg->hq_output_file = VIDEOS_DIR.'/'.$tmp_file.'-hd.mp4';
|
||||
$str = "/".date("Y")."/".date("m")."/".date("d")."/";
|
||||
$ffmpeg->log_file = LOGS_DIR.$str.$tmp_file.'.log';
|
||||
//$ffmpeg->remove_input = TRUE;
|
||||
$ffmpeg->keep_original = config('keep_original');
|
||||
$ffmpeg->original_output_path = ORIGINAL_DIR.'/'.$tmp_file.'.'.$ext;
|
||||
$ffmpeg->ClipBucket();
|
||||
|
||||
|
||||
|
||||
|
||||
////exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php &> /dev/null &");
|
||||
if (stristr(PHP_OS, 'WIN'))
|
||||
{
|
||||
exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $fileName $dosleep");
|
||||
} else {
|
||||
exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $fileName $dosleep &> /dev/null &");
|
||||
}
|
||||
|
||||
|
||||
//Converting File In HD Format
|
||||
if($ffmpeg->input_details['video_height']>'719')
|
||||
$hq_output = config('hq_output');
|
||||
else
|
||||
$hq_output = 'no';
|
||||
|
||||
|
||||
if($hq_output=='yes' && !$ffmpeg->failed_reason)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
$use_crons = config('use_crons');
|
||||
|
||||
if(!$ffmpeg->isLocked(PROCESSESS_AT_ONCE) || $use_crons=='yes' || !$ffmpeg->set_conv_lock)
|
||||
{
|
||||
|
||||
$ffmpeg->convert_to_hd();
|
||||
if($ffmpeg->lock_file && file_exists($ffmpeg->lock_file))
|
||||
unlink($ffmpeg->lock_file);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if($use_crons=='no')
|
||||
sleep(10);
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unlink($ffmpeg->input_file);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
// This script runs only via command line
|
||||
|
||||
include(dirname(__FILE__)."/../includes/config.inc.php");
|
||||
require_once(dirname(dirname(__FILE__))."/includes/classes/sLog.php");
|
||||
define("MP4Box_BINARY",get_binaries('MP4Box'));
|
||||
define("FLVTool2_BINARY",get_binaries('flvtool2'));
|
||||
define('FFMPEG_BINARY', get_binaries('ffmpeg'));
|
||||
|
||||
/*
|
||||
getting the aguments
|
||||
$argv[1] => first argument, in our case its the path of the file
|
||||
*/
|
||||
$log = new SLog();
|
||||
|
||||
//error_reporting(E_ALL);
|
||||
|
||||
$fileName = (isset($argv[1])) ? $argv[1] : false;
|
||||
$dosleep = (isset($argv[2])) ? $argv[2] : '';
|
||||
//$fileName = "/home/sajjad/Desktop/abc.mp4";
|
||||
$log->newSection("Starting Conversion Log");
|
||||
$log->writeLine("File to be converted", $fileName, false);
|
||||
$status = "Successful";
|
||||
/*
|
||||
Getting the videos which are currently in our queue
|
||||
waiting for conversion
|
||||
*/
|
||||
|
||||
if(isset($_GET['test']))
|
||||
$queue_details = get_queued_video(false,$fileName);
|
||||
else
|
||||
$queue_details = get_queued_video(TRUE,$fileName);
|
||||
|
||||
|
||||
|
||||
|
||||
$fileDir = $queue_details["date_added"];
|
||||
$dateAdded = explode(" ", $fileDir);
|
||||
$dateAdded = array_shift($dateAdded);
|
||||
$fileDir = implode("/", explode("-", $dateAdded));
|
||||
//logData($fileDir);
|
||||
|
||||
/*
|
||||
Getting the file information from the queue for conversion
|
||||
*/
|
||||
|
||||
$tmp_file = $queue_details['cqueue_name'];
|
||||
$tmp_ext = $queue_details['cqueue_tmp_ext'];
|
||||
$ext = $queue_details['cqueue_ext'];
|
||||
$outputFileName = $tmp_file;
|
||||
if(!empty($tmp_file)){
|
||||
|
||||
$temp_file = TEMP_DIR.'/'.$tmp_file.'.'.$tmp_ext;
|
||||
$orig_file = CON_DIR.'/'.$tmp_file.'.'.$ext;
|
||||
|
||||
/*
|
||||
Delete the uploaded file from temp directory
|
||||
and move it into the conversion queue directory for conversion
|
||||
*/
|
||||
|
||||
if(isset($_GET['test']))
|
||||
copy($temp_file,$orig_file);
|
||||
else
|
||||
rename($temp_file,$orig_file);
|
||||
|
||||
/*
|
||||
Preparing the configurations for video conversion from database
|
||||
*/
|
||||
|
||||
$configs = array(
|
||||
'format' => 'mp4',
|
||||
'video_codec'=> config('video_codec'),
|
||||
'audio_codec'=> config('audio_codec'),
|
||||
'audio_rate'=> config("srate"),
|
||||
'audio_bitrate'=> config("sbrate"),
|
||||
'video_rate'=> config("vrate"),
|
||||
'video_bitrate'=> config("vbrate"),
|
||||
'video_bitrate_hd'=> config("vbrate_hd"),
|
||||
'normal_res' => config('normal_resolution'),
|
||||
'high_res' => config('high_resolution'),
|
||||
'max_video_duration' => config('max_video_duration'),
|
||||
'resize'=>'max',
|
||||
'outputPath' => $fileDir,
|
||||
);
|
||||
|
||||
require_once(BASEDIR.'/includes/classes/conversion/ffmpeg.class.php');
|
||||
|
||||
|
||||
$ffmpeg = new FFMpeg($configs, $log);
|
||||
$ffmpeg->convertVideo($orig_file);
|
||||
|
||||
|
||||
//exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $orig_file");
|
||||
//exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php &> /dev/null &");
|
||||
|
||||
if (stristr(PHP_OS, 'WIN'))
|
||||
{
|
||||
exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $orig_file $dosleep");
|
||||
}elseif(stristr(PHP_OS, 'darwin'))
|
||||
{
|
||||
exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $orig_file $dosleep </dev/null >/dev/null &");
|
||||
|
||||
} else {
|
||||
exec(php_path()." -q ".BASEDIR."/actions/verify_converted_videos.php $orig_file $dosleep &> /dev/null &");
|
||||
}
|
||||
|
||||
if(!isset($_GET['test']))
|
||||
unlink($orig_file);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
exit();
|
||||
$str = "/".date("Y")."/".date("m")."/".date("d")."/";
|
||||
$orig_file1 = BASEDIR.'/files/videos'.$str.$tmp_file.'-sd.'.$ext;
|
||||
|
||||
if($orig_file1)
|
||||
{
|
||||
$status = "Successful";
|
||||
if(PHP_OS == "Linux")
|
||||
{
|
||||
$ffMpegPath = FFMPEG_BINARY;
|
||||
$out = shell_exec($ffMpegPath." -i ".$orig_file1." -acodec copy -vcodec copy -y -f null /dev/null 2>&1");
|
||||
sleep(1);
|
||||
|
||||
$log->writeLog();
|
||||
$len = strlen($out);
|
||||
$findme = 'Duration';
|
||||
$findme1 = 'start';
|
||||
$pos = strpos($out, $findme);
|
||||
$pos = $pos + 10;
|
||||
$pos1 = strpos($out, $findme1);
|
||||
$bw = $len - ($pos1 - 5);
|
||||
$rest = substr($out, $pos, -$bw);
|
||||
$duration = explode(':',$rest);
|
||||
//Convert Duration to seconds
|
||||
$hours = $duration[0];
|
||||
$minutes = $duration[1];
|
||||
$seconds = $duration[2];
|
||||
|
||||
$hours = $hours * 60 * 60;
|
||||
$minutes = $minutes * 60;
|
||||
|
||||
$duration = $hours+$minutes+$seconds;
|
||||
//$duration = (int) $ffmpeg->videoDetails['duration'];
|
||||
if($duration > 0)
|
||||
{
|
||||
|
||||
$status = "Successful";
|
||||
$log->writeLine("Conversion Result", "Successful");
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = "Failure";
|
||||
$log->writeLine("Conversion Result", "Failure");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ffMpegPath = FFMPEG_BINARY;
|
||||
$out = shell_exec($ffMpegPath." -i ".$orig_file1." -acodec copy -vcodec copy -y -f null /dev/null 2>&1");
|
||||
sleep(1);
|
||||
|
||||
$log->writeLog();
|
||||
$len = strlen($out);
|
||||
$findme = 'Duration';
|
||||
$findme1 = 'start';
|
||||
$pos = strpos($out, $findme);
|
||||
$pos = $pos + 10;
|
||||
$pos1 = strpos($out, $findme1);
|
||||
$bw = $len - ($pos1 - 5);
|
||||
$rest = substr($out, $pos, -$bw);
|
||||
$duration = explode(':',$rest);
|
||||
//Convert Duration to seconds
|
||||
$hours = $duration[0];
|
||||
$minutes = $duration[1];
|
||||
$seconds = $duration[2];
|
||||
|
||||
$hours = $hours * 60 * 60;
|
||||
$minutes = $minutes * 60;
|
||||
|
||||
$duration = $hours+$minutes+$seconds;
|
||||
//$duration = (int) $ffmpeg->videoDetails['size'];
|
||||
if($duration > "0")
|
||||
{
|
||||
|
||||
$status = "Successful";
|
||||
|
||||
$db->update(tbl('video'), array("duration"), array($duration), " file_name = '{$outputFileName}'");
|
||||
$db->update(tbl('video'), array("status"), array($status), " file_name = '{$outputFileName}'");
|
||||
|
||||
$log->writeLine("Conversion Result", "Successful");
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = "Failed";
|
||||
$db->update(tbl('video'), array("duration"), array($duration), " file_name = '{$outputFileName}'");
|
||||
$db->update(tbl('video'), array("status"), array($status), " file_name = '{$outputFileName}'");
|
||||
$log->writeLine("Conversion Result", "Failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
// update the video details in the database as successful conversion or not and video duration
|
||||
$myfile = fopen("123.txt", "w");
|
||||
$txt = " file_name = '{$outputFileName}'";
|
||||
fwrite($myfile, $duration.$status.$txt);
|
||||
fclose($myfile);
|
||||
|
||||
|
|
|
@ -32,8 +32,26 @@ if($file_details)
|
|||
{
|
||||
$fileDetailsArray = explode("\n", $file_details);
|
||||
$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;
|
||||
|
||||
assign('data',$file_details);
|
||||
assign('videoDetails',$videoDetails);
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ INSERT INTO `{tbl_prefix}config` (`configid`, `name`, `value`) VALUES
|
|||
(151, 'player_logo_file', 'logo.jpg'),
|
||||
(152, 'logo_placement', 'tl'),
|
||||
(153, 'buffer_time', '5'),
|
||||
(155, 'use_ffmpeg_vf', 'no'),
|
||||
(155, 'use_ffmpeg_vf', 'yes'),
|
||||
(224, 'own_photo_rating', ''),
|
||||
(157, 'mail_type', 'mail'),
|
||||
(158, 'smtp_host', ''),
|
||||
|
|
File diff suppressed because it is too large
Load diff
1255
upload/includes/classes/conversion/old.ffmpeg.class.php
Normal file
1255
upload/includes/classes/conversion/old.ffmpeg.class.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -37,6 +37,7 @@ class SLog{
|
|||
}
|
||||
|
||||
public function writeLog(){
|
||||
if(!$this->logFile) return;
|
||||
$this->fileHandle = fopen($this->logFile, "w+");
|
||||
fwrite($this->fileHandle, $this->logData);
|
||||
fclose($this->fileHandle);
|
||||
|
|
|
@ -3852,9 +3852,11 @@
|
|||
|
||||
function get_db_size()
|
||||
{
|
||||
$result = mysql_query("SHOW TABLE STATUS");
|
||||
$dbsize = 0;
|
||||
while( $row = mysql_fetch_array( $result ) )
|
||||
global $db;
|
||||
$results = $db->_select("SHOW TABLE STATUS");
|
||||
|
||||
|
||||
foreach($results as $row)
|
||||
{
|
||||
$dbsize += $row[ "Data_length" ] + $row[ "Index_length" ];
|
||||
}
|
||||
|
|
|
@ -837,8 +837,11 @@ function parse_duration($log)
|
|||
{
|
||||
$duration = false;
|
||||
$log_details = get_file_details($log);
|
||||
|
||||
if(isset($log['output_duration']))
|
||||
$duration = $log['output_duration'];
|
||||
if(!$duration || !is_numeric($duration))
|
||||
|
||||
if((!$duration || !is_numeric($duration)) && isset($log['duration']))
|
||||
$duration = $log['duration'];
|
||||
|
||||
if(!$duration || !is_numeric($duration))
|
||||
|
|
Loading…
Add table
Reference in a new issue