aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/conversion.inc9
-rw-r--r--includes/transcoder.inc4
-rw-r--r--includes/video_helper.inc1
-rw-r--r--modules/video_ui/video.admin.inc6
-rw-r--r--transcoders/video_ffmpeg.inc7
-rw-r--r--video.drush.inc7
-rw-r--r--video.module32
7 files changed, 54 insertions, 12 deletions
diff --git a/includes/conversion.inc b/includes/conversion.inc
index 6611e06..ae25245 100644
--- a/includes/conversion.inc
+++ b/includes/conversion.inc
@@ -7,6 +7,8 @@
*/
defined('VIDEO_RENDERING_PENDING') ||
define('VIDEO_RENDERING_PENDING', 1);
+defined('VIDEO_RENDERING_INQUEUE') ||
+ define('VIDEO_RENDERING_INQUEUE', 2);
defined('VIDEO_RENDERING_ACTIVE') ||
define('VIDEO_RENDERING_ACTIVE', 5);
defined('VIDEO_RENDERING_COMPLETE') ||
@@ -42,8 +44,7 @@ class video_conversion {
* @return
* An array containing all the videos to be proccessed.
*/
- private function load_job_queue() {
- // @TODO : allow only limited jobs to process
+ public function load_job_queue() {
return $this->transcoder->load_job_queue();
}
@@ -97,6 +98,10 @@ class video_conversion {
return $this->transcoder->delete_job($video);
}
+ public function change_status($vid, $status) {
+ return $this->transcoder->change_status($vid, $status);
+ }
+
/**
* Load a file based on the file id ($fid)
*
diff --git a/includes/transcoder.inc b/includes/transcoder.inc
index e5f7123..bdb447a 100644
--- a/includes/transcoder.inc
+++ b/includes/transcoder.inc
@@ -172,6 +172,10 @@ class video_transcoder {
return $this->transcoder->delete_job($video);
}
+ public function change_status($vid, $status) {
+ return $this->transcoder->change_status($vid, $status);
+ }
+
/**
* Load a file based on the file id ($fid)
*
diff --git a/includes/video_helper.inc b/includes/video_helper.inc
index a4f2b65..e47830c 100644
--- a/includes/video_helper.inc
+++ b/includes/video_helper.inc
@@ -77,7 +77,6 @@ class video_helper {
// Moved to last to recheck incase we changed our extension above.
$video->flash_player = variable_get('video_extension_' . $video->player . '_flash_player', '');
-
// Return our object
return $video;
}
diff --git a/modules/video_ui/video.admin.inc b/modules/video_ui/video.admin.inc
index 8ab19b3..e55e774 100644
--- a/modules/video_ui/video.admin.inc
+++ b/modules/video_ui/video.admin.inc
@@ -154,6 +154,12 @@ function video_cron_admin_settings() {
'#default_value' => variable_get('video_cron', TRUE),
'#description' => t('If you would like to use Drupals built in cron hook, check this box. Please be warned that transcoding videos is very resource intensive. If you use poor mans cron, I highly discourage this option. I also suggest you setup your cron to call this function through CLI instead of WGET.'),
);
+ $form['video_queue_timeout'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Video queue timeout (s).'),
+ '#default_value' => variable_get('video_queue_timeout', 90),
+ '#description' => t('The maximum time allow a video to complete their transcoding. Put a larger value for larger size video.'),
+ );
$form['video_ffmpeg_instances'] = array(
'#type' => 'textfield',
'#title' => t('Total videos to convert during each cron process.'),
diff --git a/transcoders/video_ffmpeg.inc b/transcoders/video_ffmpeg.inc
index d1096f0..791b5ca 100644
--- a/transcoders/video_ffmpeg.inc
+++ b/transcoders/video_ffmpeg.inc
@@ -385,8 +385,8 @@ class video_ffmpeg implements transcoder_interface {
$converted = unserialize($video->data);
if (!empty($converted)) {
foreach ($converted as $file) {
- if (file_exists($file->filepath))
- @unlink($file->filepath);
+ if (file_exists(drupal_realpath($file->uri)))
+ @drupal_unlink($file->uri);
}
}
//now delete our rows.
@@ -416,7 +416,6 @@ class video_ffmpeg implements transcoder_interface {
* @see sites/all/modules/video/includes/transcoder_interface#load_job_queue()
*/
public function load_job_queue() {
-// return;
$total_videos = variable_get('video_ffmpeg_instances', 5);
$videos = array();
$result = db_query_range('SELECT f.*, vf.vid, vf.nid, vf.dimensions, vf.status as video_status
@@ -440,7 +439,7 @@ class video_ffmpeg implements transcoder_interface {
foreach ($data as $value) {
$extension = pathinfo(drupal_realpath($value->uri), PATHINFO_EXTENSION);
$video->files->{$extension}->filename = $value->filename;
- $video->files->{$extension}->uri = $value->uri;
+ $video->files->{$extension}->filepath = $value->uri;
$video->files->{$extension}->url = file_create_url($value->uri);
$video->files->{$extension}->extension = $extension;
$video->player = strtolower($extension);
diff --git a/video.drush.inc b/video.drush.inc
index bcb03ee..8c01f6d 100644
--- a/video.drush.inc
+++ b/video.drush.inc
@@ -5,7 +5,7 @@
*/
function video_drush_command() {
$items = array();
-
+
$items['video-scheduler'] = array(
'description' => 'Run video transcoder scheduler',
'callback' => 'drush_video_scheduler',
@@ -14,10 +14,13 @@ function video_drush_command() {
'--limit' => 'Change the number of video items to transcode',
),
);
-
+
return $items;
}
+/**
+ * Callback function
+ */
function drush_video_scheduler() {
$limit = (int) drush_get_option('limit', variable_get('video_ffmpeg_instances', 5));
$GLOBALS['conf']['video_ffmpeg_instances'] = $limit;
diff --git a/video.module b/video.module
index 7f3283d..6e38cab 100644
--- a/video.module
+++ b/video.module
@@ -127,14 +127,40 @@ function video_theme() {
*/
function video_cron() {
- return;
- module_load_include('inc', 'video', 'includes/conversion');
if (variable_get('video_cron', TRUE)) {
+ module_load_include('inc', 'video', 'includes/conversion');
$video_conversion = new video_conversion;
- $video_conversion->run_queue();
+ if ($videos = $video_conversion->load_job_queue()) {
+ $queue = DrupalQueue::get('video_queue');
+ foreach ($videos as $video) {
+ if ($queue->createItem($video)) {
+ $video_conversion->change_status($video->vid, VIDEO_RENDERING_INQUEUE);
+ }
+ }
+ }
}
}
+/**
+ * Implmentation of hook_cron_queue_info()
+ */
+function video_cron_queue_info() {
+ $queues['video_queue'] = array(
+ 'worker callback' => 'video_queue_process',
+ 'time' => variable_get('video_queue_timeout', 90),
+ );
+ return $queues;
+}
+
+/**
+ * Process video transcoding queue
+ */
+function video_queue_process($video) {
+ module_load_include('inc', 'video', 'includes/conversion');
+ $video_conversion = new video_conversion;
+ $video_conversion->process($video);
+}
+
/*
* Utility function that will add a preview of thumbnails for you to select when uploading videos.
*/