aboutsummaryrefslogtreecommitdiff
path: root/plugins/video_ffmpeg_helper/video_scheduler.php
diff options
context:
space:
mode:
authorFabio Varesano <fax8@13637.no-reply.drupal.org>2007-01-14 09:45:57 +0000
committerFabio Varesano <fax8@13637.no-reply.drupal.org>2007-01-14 09:45:57 +0000
commit018f720fc65b950e14db154f83e83137a86011c8 (patch)
tree1b8a0df0378acdc9e0824cfb17ea1cb2286f286e /plugins/video_ffmpeg_helper/video_scheduler.php
parent40dff270e7aaca67d6b5633dd842d4239aa1a65d (diff)
downloadvideo-018f720fc65b950e14db154f83e83137a86011c8.tar.gz
video-018f720fc65b950e14db154f83e83137a86011c8.tar.bz2
Support for concurrent video conversion.
Diffstat (limited to 'plugins/video_ffmpeg_helper/video_scheduler.php')
-rw-r--r--plugins/video_ffmpeg_helper/video_scheduler.php108
1 files changed, 108 insertions, 0 deletions
diff --git a/plugins/video_ffmpeg_helper/video_scheduler.php b/plugins/video_ffmpeg_helper/video_scheduler.php
new file mode 100644
index 0000000..de64bc0
--- /dev/null
+++ b/plugins/video_ffmpeg_helper/video_scheduler.php
@@ -0,0 +1,108 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Implement video rendering scheduling.
+ *
+ * @author Fabio Varesano <fvaresano at yahoo dot it>
+ */
+
+
+/**
+ * video_scheduler.php configuration
+*/
+
+// set to the ffmpeg executable
+define('VIDEO_RENDERING_FFMPEG_PATH', '/usr/bin/ffmpeg');
+
+// set to the temp file path.
+//IMPORTANT: the user who runs this script must have permissions to create files there. If this is not the case the default php temporary folder will be used.
+define('VIDEO_RENDERING_TEMP_PATH', '/tmp/video');
+
+// number of conversion jobs active at the same time
+define('VIDEO_RENDERING_FFMPEG_INSTANCES', 5);
+
+/**
+ * video_scheduler.php configuration ends.
+ * DO NOT EDIT BELOW THIS LINE
+*/
+
+/**
+ * Define some constants
+*/
+define('VIDEO_RENDERING_PENGING', 0);
+define('VIDEO_RENDERING_ACTIVE', 5);
+define('VIDEO_RENDERING_COMPLETE', 10);
+
+
+include_once './includes/bootstrap.inc';
+// disable error reporting for bootstrap process
+error_reporting(E_ERROR);
+// let's bootstrap: we will be able to use drupal apis
+drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+// enable full error reporting again
+error_reporting(E_ALL);
+
+
+// allow execution only from the command line!
+if(empty($_SERVER['REQUEST_METHOD'])) {
+ video_scheduler_main();
+}
+else {
+ print t('This script is only executable from the command line.');
+ die();
+}
+
+
+
+/**
+ * Main for video_scheduler.php
+*/
+function video_scheduler_main() {
+
+ if($jobs = video_scheduler_select()) {
+ foreach ($jobs as $job) {
+ video_scheduler_start($job);
+ }
+ }
+ else {
+ watchdog('video_scheduler', t('no video conversion jobs to schedule.'));
+ }
+}
+
+
+/**
+ * Starts rendering for a job
+*/
+function video_scheduler_start($job) {
+ exec("php video_render.php $job->nid $job->vid > /dev/null &");
+}
+
+
+/**
+ * Select VIDEO_RENDERING_FFMPEG_INSTANCES jobs from the queue
+ *
+ * @return an array containing jobs
+*/
+function video_scheduler_select() {
+
+ $result = db_query('SELECT * FROM {video_rendering} vr INNER JOIN {node} n ON vr.vid = n.vid INNER JOIN {video} v ON n.vid = v.vid WHERE n.nid = v.nid AND vr.nid = n.nid AND vr.status = %d ORDER BY n.created', VIDEO_RENDERING_PENDING);
+
+ // TODO: order jobs by priority
+
+ $jobs = array();
+ $i = 0;
+ $count = db_num_rows($result);
+ while($i < $count && $i < VIDEO_RENDERING_FFMPEG_INSTANCES) {
+ $jobs[] = db_fetch_object($result);
+ $i++;
+ }
+
+ return $jobs;
+}
+
+
+
+
+?>