aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorFabio Varesano <fax8@13637.no-reply.drupal.org>2007-01-13 17:01:34 +0000
committerFabio Varesano <fax8@13637.no-reply.drupal.org>2007-01-13 17:01:34 +0000
commitc933d514eea5b207b903c9ca6daf8ca56677e2df (patch)
tree11a90b5fcbc7b0bbbb2e386a38d6e51ae0c4fbda /plugins
parent1cabdaa865adb6a03589908cedc00de9c93d7448 (diff)
downloadvideo-c933d514eea5b207b903c9ca6daf8ca56677e2df.tar.gz
video-c933d514eea5b207b903c9ca6daf8ca56677e2df.tar.bz2
More configurable ffmpeg execution.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/video_ffmpeg_helper/video_ffmpeg_helper.module45
-rw-r--r--plugins/video_ffmpeg_helper/video_render.php86
2 files changed, 107 insertions, 24 deletions
diff --git a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module b/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module
index b765538..a6fc1e8 100644
--- a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module
+++ b/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module
@@ -83,7 +83,7 @@ function video_ffmpeg_helper_admin_settings() {
$form['video_ffmpeg_helper_ffmpeg_path'] = array(
'#type' => 'textfield',
- '#title' => t('Ffmpeg executable path'),
+ '#title' => t('FFmpeg executable path'),
'#description' => t('Set the full path to the ffmpeg executable here.'),
'#default_value' => variable_get('video_ffmpeg_helper_ffmpeg_path', '/usr/bin/ffmpeg'),
);
@@ -153,11 +153,29 @@ function video_ffmpeg_helper_admin_settings() {
'#description' => t('If set up correctly, this will auto-convert each uploaded video to the configured format.') . '<br />' . t("IMPORTANT: you will need the video_render.php correctly configured and run by cron. See README.txt for more informations."),
'#default_value' => variable_get('video_ffmpeg_helper_auto_conversion', false),
);
- $form['autoconv']['video_ffmpeg_helper_auto_converter_options'] = array(
+ $form['autoconv']['video_ffmpeg_helper_auto_converter_width'] = array(
'#type' => 'textfield',
- '#title' => t('Video thumbnailer options'),
- '#description' => t('Provide the ffmpeg options to configure the video conversion. Available argument values are: ').'<ol><li>'.t('%videofile (the video file to convert)').'<li>'.t('%convertfile (a newly created file to store the converted file)').'</ol>',
- '#default_value' => variable_get('video_ffmpeg_helper_auto_converter_options', '-y -i %videofile -f flv -ar 22050 %convertfile'),
+ '#title' => t('Video rendering width'),
+ '#description' => t('The width of the converted video. The height will be automatically calculated to maintain aspect ratio.'),
+ '#size' => 3,
+ '#maxlength' => 3,
+ '#default_value' => variable_get('video_ffmpeg_helper_auto_converter_width', 400),
+ );
+ $form['autoconv']['video_ffmpeg_helper_auto_converter_video_bitrate'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Video bitrate'),
+ '#description' => t('The video bitrate in kbit/s of the converted video.'),
+ '#size' => 3,
+ '#maxlength' => 4,
+ '#default_value' => variable_get('video_ffmpeg_helper_auto_converter_video_bitrate', 200),
+ );
+ $form['autoconv']['video_ffmpeg_helper_auto_converter_audio_bitrate'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Audio bitrate'),
+ '#description' => t('The audio bitrate in kbit/s of the converted video.'),
+ '#size' => 3,
+ '#maxlength' => 4,
+ '#default_value' => variable_get('video_ffmpeg_helper_auto_converter_audio_bitrate', 64),
);
$form['autoconv']['video_ffmpeg_helper_auto_converter_busy_video_path'] = array(
'#type' => 'textfield',
@@ -165,6 +183,23 @@ function video_ffmpeg_helper_admin_settings() {
'#description' => t('Provide the relative path to a video displayed when the video is being rendered.'),
'#default_value' => variable_get('video_ffmpeg_helper_auto_converter_busy_video_path', 'busy.flv'),
);
+ $form['autoconv']['advanced'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Advanced settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE
+ );
+ $form['autoconv']['advanced']['video_ffmpeg_helper_auto_converter_options'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Video converter options'),
+ '#description' => t('Provide the ffmpeg options to configure the video conversion. Available argument values are: ').'<ul>'.
+ '<li>'.t('%videofile (the video file to convert)').
+ '<li>'.t('%convertfile (a newly created file to store the converted file)').
+ '<li>'.t('%size (video resolution of the converted file)').
+ '</ul>'.
+ t('For further informations refer to the !ffmpegdoc', array('!ffmpegdoc' => l(t('Official FFMpeg documentation.'), 'http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html', NULL, NULL, TRUE))),
+ '#default_value' => variable_get('video_ffmpeg_helper_auto_converter_options', '-y -i %videofile -f flv -ar 22050 -ab %audiobitrate -s %size -b %videobitrate %convertfile'),
+ );
return system_settings_form($form);
}
diff --git a/plugins/video_ffmpeg_helper/video_render.php b/plugins/video_ffmpeg_helper/video_render.php
index 09e7fb6..5622fd9 100644
--- a/plugins/video_ffmpeg_helper/video_render.php
+++ b/plugins/video_ffmpeg_helper/video_render.php
@@ -20,8 +20,13 @@ define('VIDEO_RENDERING_FFMPEG_PATH', '/usr/bin/ffmpeg');
//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_render.php configuration ends.
+ * DO NOT EDIT BELOW THIS LINE
+*/
/**
* Define some constants
@@ -56,8 +61,10 @@ else {
*/
function video_render_main() {
- if($job = video_render_select()) {
- video_render_start($job);
+ if($jobs = video_render_select()) {
+ foreach ($jobs as $job) {
+ video_render_start($job);
+ }
}
else {
watchdog('video_render', t('no video conversion jobs to schedule.'));
@@ -69,17 +76,10 @@ function video_render_main() {
* Starts rendering for a job
*/
function video_render_start($job) {
- print_r($job);
- db_query('DELETE FROM {video_rendering} WHERE nid=%d AND vid=%d', $job->nid, $job->vid);
+ // print_r($job);
+ //db_query('DELETE FROM {video_rendering} WHERE nid=%d AND vid=%d', $job->nid, $job->vid);
- // escape file name for safety
- $videofile = escapeshellarg($job->origfile);
- $convfile = tempnam(VIDEO_RENDERING_TEMP_PATH, 'video-rendering');
-
- $converter = VIDEO_RENDERING_FFMPEG_PATH;
- $options = preg_replace(array('/%videofile/', '/%convertfile/'), array($videofile, $convfile), variable_get('video_ffmpeg_helper_auto_converter_options', '-y -i %videofile -f flv -ar 22050 %convertfile.flv'));
-
- $command = "$converter $options";
+ $command = _video_render_get_command($job);
print('executing ' . $command);
@@ -91,7 +91,7 @@ function video_render_start($job) {
print $command_output;
- if (!file_exists($convfile)) {
+ if (!file_exists($job->convfile)) {
watchdog('video_render', t('video conversion failed. ffmpeg reported the following output: ' . $command_output, WATCHDOG_ERROR));
}
else {
@@ -99,8 +99,8 @@ function video_render_start($job) {
$file = array(
'filename' => basename($job->origfile . ".flv"),
'filemime' => 'application/octet-stream', // is there something better???
- 'filesize' => filesize($convfile),
- 'filepath' => $convfile,
+ 'filesize' => filesize($job->convfile),
+ 'filepath' => $job->convfile,
'nid' => $job->nid,
);
@@ -109,7 +109,6 @@ function video_render_start($job) {
print_r($file);
$dest_dir = variable_get('video_upload_default_path', 'videos') .'/';
- //print file_directory_path() . '/' . $dest_dir . basename($file->filename);
if (file_copy($file, file_directory_path() . '/' . $dest_dir)) {
$file->fid = db_next_id('{files}_fid');
print_r($file);
@@ -130,14 +129,63 @@ function video_render_start($job) {
/**
- * Select a job from the queue
+ * Select VIDEO_RENDERING_FFMPEG_INSTANCES jobs from the queue
+ *
+ * @return an array containing jobs
*/
function video_render_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;
+}
+
+
+/**
+ * Get a string cointaining the command to be executed including options
+*/
+function _video_render_get_command(&$job) {
+
+ $videofile = escapeshellarg($job->origfile); // escape file name for safety
+ $convfile = tempnam(VIDEO_RENDERING_TEMP_PATH, 'video-rendering');
+ $audiobitrate = variable_get('video_ffmpeg_helper_auto_converter_audio_bitrate', 64);
+ $videobitrate = variable_get('video_ffmpeg_helper_auto_converter_video_bitrate', 200);
+ $size = _video_render_get_size($job);
+
+ $converter = VIDEO_RENDERING_FFMPEG_PATH;
+ $options = preg_replace(array('/%videofile/', '/%convertfile/', '/%audiobitrate/', '/%size/', '/%videobitrate/'), array($videofile, $convfile, $audiobitrate, $size, $videobitrate), variable_get('video_ffmpeg_helper_auto_converter_options', '-y -i %videofile -f flv -ar 22050 -ab %audiobitrate -s %size -b %videobitrate %convertfile'));
+ // set to the converted file output
+ $job->convfile = $convfile;
- return db_fetch_object($result);
+ return "$converter $options";
}
+
+
+
+/**
+ * Calculate the converted video size basing on the width set on administration.
+ * Aspect ration is maintained.
+*/
+function _video_render_get_size(&$job) {
+ $def_width = variable_get('video_ffmpeg_helper_auto_converter_width', 400);
+ $x = $job->videox;
+ $y = $job->videoy;
+
+ $height = $def_width * ($y / $x); // do you remember proportions?? :-)
+ return $def_width . 'x' . $height;
+}
+
+
+?>