2009-08-25 12:16:42 +00:00
|
|
|
<?php
|
2009-12-09 13:43:19 +00:00
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
/**
|
|
|
|
* @Author : Arslan Hassan
|
|
|
|
* @Since : 2012
|
|
|
|
* @version : 3.0
|
|
|
|
*/
|
|
|
|
$in_bg_cron = true;
|
2010-03-03 08:51:43 +00:00
|
|
|
|
2009-08-25 12:16:42 +00:00
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
//Including new conversion kit, called cb kit.
|
|
|
|
include("../includes/config.inc.php");
|
|
|
|
include("../includes/classes/conversion/conversion.class.php");
|
2011-01-10 14:59:36 +00:00
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
//Initializing new conversio kit
|
|
|
|
$cb_converter = new CBConverter();
|
2010-03-20 12:27:19 +00:00
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
$max_processes = 5;
|
2011-01-11 13:56:34 +00:00
|
|
|
|
2009-08-25 12:16:42 +00:00
|
|
|
//Get Vido
|
2012-07-16 12:01:09 +00:00
|
|
|
$queued_files = $cbupload->get_queued_files();
|
|
|
|
|
2012-12-20 15:54:42 +00:00
|
|
|
define('CONV_TEST_MODE', false);
|
2012-12-19 21:06:27 +00:00
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
//Total Running proccesses...
|
|
|
|
$process_running = $cbupload->conversion_count();
|
|
|
|
|
2012-12-20 12:33:53 +00:00
|
|
|
if ($process_running <= $max_processes && $queued_files)
|
|
|
|
{
|
|
|
|
foreach ($queued_files as $queue)
|
|
|
|
{
|
2012-07-16 12:01:09 +00:00
|
|
|
//Creating dated folders
|
2012-08-31 12:35:45 +00:00
|
|
|
$folder = $queue['file_directory'];
|
2012-09-01 23:03:02 +00:00
|
|
|
|
|
|
|
$original_source = ORIGINAL_DIR . '/' . $folder . '/' . $queue['queue_name'] . '.'
|
|
|
|
. $queue['queue_ext'];
|
|
|
|
|
|
|
|
$temp_source = TEMP_DIR . '/' . $queue['queue_name'] . '.' . $queue['queue_tmp_ext'];
|
|
|
|
|
2012-12-20 12:33:53 +00:00
|
|
|
if (!file_exists($original_source))
|
|
|
|
{
|
|
|
|
|
|
|
|
if (CONV_TEST_MODE)
|
|
|
|
copy($temp_source, $original_source);
|
|
|
|
else
|
|
|
|
rename($temp_source, $original_source);
|
|
|
|
|
|
|
|
if (!file_exists($original_source))
|
|
|
|
{
|
2012-07-16 12:01:09 +00:00
|
|
|
echo "Cannot make use of original file...(Err 1)";
|
2013-01-25 14:55:54 +00:00
|
|
|
$cbupload->update_queue_status($queue, 's', 'Cannot make use of original file...(Err 1)');
|
2012-12-20 12:33:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-16 12:01:09 +00:00
|
|
|
//Get source information using ffmpeg and save it in our
|
|
|
|
//video file database..
|
|
|
|
$video_info = $cb_converter->getInfo($original_source);
|
2012-09-01 23:03:02 +00:00
|
|
|
|
2012-12-20 12:33:53 +00:00
|
|
|
if ($video_info['has_video'] == 'no')
|
|
|
|
{
|
2012-09-01 23:03:02 +00:00
|
|
|
$cbupload->update_queue_status($queue, 'f', 'Invalid video file');
|
2012-12-20 12:33:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!CONV_TEST_MODE)
|
|
|
|
$cbupload->add_video_file($queue, $video_info, 's');
|
2013-01-25 14:55:54 +00:00
|
|
|
|
|
|
|
$cbupload->update_queue_status($queue, 'started', 'Video info extracted');
|
2012-07-16 12:01:09 +00:00
|
|
|
}
|
2012-08-31 12:25:39 +00:00
|
|
|
}
|
2012-09-01 23:03:02 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 12:33:53 +00:00
|
|
|
if (file_exists($original_source))
|
|
|
|
{
|
2012-09-01 23:03:02 +00:00
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
$video_profiles = $cbvid->get_video_profiles();
|
|
|
|
$convert = false;
|
2012-12-20 12:33:53 +00:00
|
|
|
foreach ($video_profiles as $vid_profile)
|
|
|
|
{
|
|
|
|
if (!$cbupload->video_file_exists($queue['queue_name'], $queue['queue_id'], $vid_profile['profile_id']))
|
|
|
|
{
|
2013-01-25 14:55:54 +00:00
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
$convert = true;
|
|
|
|
|
2012-09-01 23:03:02 +00:00
|
|
|
$output_name = $queue['queue_name'] . $vid_profile['suffix'] . '.' . $vid_profile['ext'];
|
|
|
|
$output_file = VIDEOS_DIR . '/' . $folder . '/' . $output_name;
|
|
|
|
|
|
|
|
$log_file = $folder . '/' . $queue['queue_name'] . $vid_profile['suffix'] . '-' . $vid_profile['ext'] . '.log';
|
|
|
|
|
2012-12-20 12:33:53 +00:00
|
|
|
|
|
|
|
if (!CONV_TEST_MODE)
|
|
|
|
$fid = $cbupload->add_video_file($queue, array('noinfo'), 'p', $vid_profile['profile_id'], $log_file);
|
|
|
|
|
|
|
|
if (!CONV_TEST_MODE)
|
|
|
|
$cbupload->update_queue_status($queue, 'u', 'Started conversion using Profile # ' . $vid_profile['profile_id'], true);
|
2012-07-16 12:01:09 +00:00
|
|
|
|
2012-09-01 23:03:02 +00:00
|
|
|
$log_file = LOGS_DIR . '/' . $log_file;
|
2012-07-16 12:01:09 +00:00
|
|
|
|
2012-09-01 23:03:02 +00:00
|
|
|
/** All of our new conversion code is written here * */
|
|
|
|
$converter = new CBConverter($original_source);
|
2012-09-05 15:14:08 +00:00
|
|
|
//$converter->set_preset_path('D:\usr\local\share\ffmpeg');
|
2012-07-16 12:01:09 +00:00
|
|
|
$converter->set_log($log_file);
|
2012-09-01 23:03:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** AS $converter is already being initited, its
|
|
|
|
* good to check for thumbs and if they are not
|
|
|
|
* generated, we should extract them first before
|
|
|
|
* we move on for next step
|
|
|
|
*/
|
2012-12-20 12:33:53 +00:00
|
|
|
if (!hasThumbs($queue))
|
|
|
|
{
|
|
|
|
if (!CONV_TEST_MODE)
|
|
|
|
$cbupload->update_queue_status($queue, 'u', 'Generating thumbs...', false);
|
2012-09-02 16:35:24 +00:00
|
|
|
|
2012-09-01 23:03:02 +00:00
|
|
|
//Generate thumbnails first...then move on..
|
|
|
|
$thumb_sizes = get_thumb_sizes();
|
2012-12-20 12:33:53 +00:00
|
|
|
$thumbs_dir = THUMBS_DIR . '/' . $folder;
|
|
|
|
|
|
|
|
if ($thumb_sizes)
|
|
|
|
{
|
|
|
|
foreach ($thumb_sizes as $thumb_size)
|
|
|
|
{
|
2012-09-04 10:38:50 +00:00
|
|
|
$size = $thumb_size;
|
|
|
|
$suffix = $size;
|
2012-12-20 12:33:53 +00:00
|
|
|
|
|
|
|
$outname = $queue['queue_name'] . '-' . $suffix;
|
|
|
|
|
|
|
|
if (!CONV_TEST_MODE)
|
|
|
|
$cbupload->update_queue_status($queue, 'u', 'Extacting ' . $outname, false);
|
|
|
|
|
2012-09-01 23:03:02 +00:00
|
|
|
//Using Multi Thumb Gen function..
|
|
|
|
//$converter = new CBConverter($original_source);
|
|
|
|
$converter->extractThumb(NULL, array(
|
|
|
|
'size' => $size,
|
|
|
|
'num' => 5,
|
|
|
|
'increment' => true,
|
|
|
|
'outname' => $outname,
|
|
|
|
'outdir' => $thumbs_dir,
|
|
|
|
'resize' => 'fit'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2012-12-20 12:33:53 +00:00
|
|
|
|
2012-09-04 10:38:50 +00:00
|
|
|
//Index thumb..
|
2012-09-04 11:15:04 +00:00
|
|
|
$cbvid->index_video_thumbs($queue['queue_name']);
|
2012-09-01 23:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
/**
|
|
|
|
* @todo : Add Filters for this params
|
|
|
|
*/
|
|
|
|
$twoPass = false;
|
2012-09-01 23:03:02 +00:00
|
|
|
if ($vid_profile['2pass'] == 'yes')
|
2012-07-16 12:01:09 +00:00
|
|
|
$twoPass = true;
|
2012-09-01 23:03:02 +00:00
|
|
|
|
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
$params = array(
|
2012-09-01 23:03:02 +00:00
|
|
|
'format' => $vid_profile['format'],
|
|
|
|
'output_file' => $output_file,
|
|
|
|
'preset' => $vid_profile['preset'],
|
|
|
|
'height' => $vid_profile['height'],
|
|
|
|
'width' => $vid_profile['width'],
|
|
|
|
'resize' => $vid_profile['resize'],
|
|
|
|
'bitrate' => $vid_profile['video_bitrate'],
|
|
|
|
'aspect_ratio' => $vid_profile['aspect_ratio'],
|
|
|
|
'arate' => $vid_profile['audio_rate'],
|
|
|
|
'fps' => $vid_profile['video_rate'],
|
|
|
|
'abitrate' => $vid_profile['audio_bitrate'],
|
|
|
|
'2pass' => $twoPass,
|
2012-07-16 12:01:09 +00:00
|
|
|
);
|
2012-09-01 23:03:02 +00:00
|
|
|
|
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
$converter->convert($params);
|
|
|
|
$output_details = $converter->getInfo($output_file);
|
|
|
|
$time_finished = time();
|
2012-07-16 14:53:27 +00:00
|
|
|
$log = $converter->log();
|
2012-09-01 23:03:02 +00:00
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
$fields = array(
|
2012-12-20 12:33:53 +00:00
|
|
|
'log' => json_encode($log),
|
2012-07-16 12:01:09 +00:00
|
|
|
'status' => 's',
|
2012-12-20 12:33:53 +00:00
|
|
|
'output_results' => json_encode($output_details),
|
2012-07-16 12:01:09 +00:00
|
|
|
'date_completed' => $time_finished,
|
|
|
|
);
|
2012-12-20 15:54:42 +00:00
|
|
|
|
|
|
|
|
2012-09-01 23:03:02 +00:00
|
|
|
|
|
|
|
$cbupload->update_video_file($fid, $fields);
|
|
|
|
|
2012-07-16 12:01:09 +00:00
|
|
|
unset($converter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-20 15:54:42 +00:00
|
|
|
|
|
|
|
$file_name = $queue['queue_name'];
|
2012-12-20 18:05:08 +00:00
|
|
|
|
2012-12-20 15:54:42 +00:00
|
|
|
if($file_name)
|
|
|
|
exec(php_path() . " -q " . BASEDIR . "/actions/verify_videos.php $file_name &> /dev/null &");
|
2012-12-20 18:05:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!$convert)
|
|
|
|
{
|
|
|
|
$cbupload->update_queue_status($queue, 's', 'File removed from queue');
|
|
|
|
}
|
2012-07-16 12:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2011-01-11 13:56:34 +00:00
|
|
|
}
|
2009-08-25 12:16:42 +00:00
|
|
|
?>
|