diff options
author | Fabio Varesano <fax8@13637.no-reply.drupal.org> | 2007-01-11 07:43:59 +0000 |
---|---|---|
committer | Fabio Varesano <fax8@13637.no-reply.drupal.org> | 2007-01-11 07:43:59 +0000 |
commit | 18fbdce5034299832762b72e4653bf6028e8252d (patch) | |
tree | 0b90a46b465c8a08f995da02f14d77214672a604 | |
parent | d2c9046205bd5c9a61ffe1792470defbfa0250ce (diff) | |
download | video-18fbdce5034299832762b72e4653bf6028e8252d.tar.gz video-18fbdce5034299832762b72e4653bf6028e8252d.tar.bz2 |
Added *draft* and *incomplete* support for video conversion throught the video_render.php script
Added functions for video_render.php to video_ffmpeg_helper.module
Fixed bug #108445 reported by incom (http://drupal.org/user/64246)
Call to undefined function: module_exist() in /home/..../modules/video/views_video.inc on line 69
-rw-r--r-- | plugins/video_ffmpeg_helper/video_ffmpeg_helper.module | 75 | ||||
-rw-r--r-- | plugins/video_ffmpeg_helper/video_render.php | 110 | ||||
-rw-r--r-- | plugins/video_image/video_image.module | 6 | ||||
-rw-r--r-- | plugins/video_upload/video_upload.module | 1 | ||||
-rw-r--r-- | views_video.inc | 4 |
5 files changed, 185 insertions, 11 deletions
diff --git a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module b/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module index 96e16dc..16db8f4 100644 --- a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module +++ b/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module @@ -8,6 +8,13 @@ * @author Fabio Varesano <fvaresano at yahoo dot it> */ +/** + * Define some constants +*/ +define('VIDEO_RENDERING_PENGING', 0); +define('VIDEO_RENDERING_ACTIVE', 5); +define('VIDEO_RENDERING_COMPLETE', 10); + /** * Implementation of hook_help(). @@ -132,6 +139,32 @@ function video_ffmpeg_helper_admin_settings() { '#title' => t('Debug auto-thumbnail process'), '#default_value' => variable_get('video_ffmpeg_helper_auto_thumbnail_debug', false), ); + + // automatic video conversion settings + $form['autoconv'] = array( + '#type' => 'fieldset', + '#title' => t('Automatic video conversion'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['autoconv']['video_ffmpeg_helper_auto_conversion'] = array( + '#type' => 'checkbox', + '#title' => t('Auto conversion for videos'), + '#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( + '#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 %convertfile'), + ); + $form['autoconv']['video_ffmpeg_helper_auto_converter_busy_video_path'] = array( + '#type' => 'textfield', + '#title' => t('Busy video path'), + '#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'), + ); return system_settings_form($form); } @@ -141,7 +174,7 @@ function video_ffmpeg_helper_admin_settings() { */ function video_ffmpeg_helper_form_alter($form_id, &$form) { - //print_r($form); + //print_r($form); if($form_id == 'video_node_form') { if (function_exists('_image_check_settings')) { @@ -154,7 +187,7 @@ function video_ffmpeg_helper_form_alter($form_id, &$form) { } } - if(variable_get('video_ffmpeg_helper_auto_resolution', false)) { + if(variable_get('video_ffmpeg_helper_auto_resolution', false) || variable_get('video_ffmpeg_helper_auto_convert', false)) { $form['video']['videox'] = NULL; $form['video']['videoy'] = NULL; } @@ -182,10 +215,19 @@ function video_ffmpeg_helper_nodeapi(&$node, $op, $teaser) { if(variable_get('video_ffmpeg_helper_auto_resolution', false) || variable_get('video_ffmpeg_helper_auto_playtime', false)) { _video_ffmpeg_helper_get_video_info($node); } + break; - case 'prepare': + case 'insert': + if(variable_get('video_ffmpeg_helper_auto_conversion', false)) { + // add rendering job to queue + _video_ffmpeg_helper_add_rendering($node); + } + + break; + case 'prepare': + ; // for future uses break; case 'view': @@ -193,7 +235,7 @@ function video_ffmpeg_helper_nodeapi(&$node, $op, $teaser) { break; case 'delete': - ; // for future uses + db_query('DELETE FROM {video_rendering} WHERE vid = %d AND nid = %d', $node->vid, $node->nid); break; } @@ -201,6 +243,25 @@ function video_ffmpeg_helper_nodeapi(&$node, $op, $teaser) { } +/** + * Add a video conversion rendering process to the queue +*/ +function _video_ffmpeg_helper_add_rendering(&$node) { + $file = $_SESSION['video_upload_file_stored']->filepath; + //print_r($node); die; + db_query('INSERT INTO {video_rendering} (vid, nid, origfile, pid, status, started, completed) VALUES (%d, %d, "%s", %d, %d, %d, %d)', $node->vid, $node->nid, $file, 0, VIDEO_RENDERING_PENGING, 0, 0); + + // let's add the rendering in progress video + $node->vidfile = variable_get('video_ffmpeg_helper_auto_converter_busy_video_path', 'busy.flv'); + db_query('UPDATE {video} SET vidfile = "%s" WHERE nid=%d AND vid=%d', $node->vidfile, $node->nid, $node->vid); + +} + + + +/** + * Get some informations from the video file +*/ function _video_ffmpeg_helper_get_video_info(&$node) { // escape file name for safety @@ -216,7 +277,7 @@ function _video_ffmpeg_helper_get_video_info(&$node) { $command_output = ob_get_contents(); ob_end_clean(); - print $command_output; + // print $command_output; if(variable_get('video_ffmpeg_helper_auto_resolution', false)) { // get resolution @@ -231,13 +292,13 @@ function _video_ffmpeg_helper_get_video_info(&$node) { } - if(variable_get('video_ffmpeg_helper_auto_resolution', false) || variable_get('video_ffmpeg_helper_auto_playtime', false)) { + if(variable_get('video_ffmpeg_helper_auto_playtime', false)) { // get playtime $pattern = '/[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]/'; preg_match_all($pattern, $command_output, $matches, PREG_PATTERN_ORDER); $playtime = $matches[0][0]; - // ffmpge return lenght as 00:00:31.1 Let's get palytime from that + // ffmpge return lenght as 00:00:31.1 Let's get playtime from that $hmsmm = explode(":", $playtime); $tmp = explode(".", $hmsmm[2]); diff --git a/plugins/video_ffmpeg_helper/video_render.php b/plugins/video_ffmpeg_helper/video_render.php new file mode 100644 index 0000000..eddae56 --- /dev/null +++ b/plugins/video_ffmpeg_helper/video_render.php @@ -0,0 +1,110 @@ +<?php +// $Id$ + +/** + * @file + * Manage video rendering scheduling. + * + * @author Fabio Varesano <fvaresano at yahoo dot it> + */ + + +/** + * Configuration constats +*/ +define(VIDEO_RENDERING_FFMPEG_PATH, '/usr/bin/ffmpeg'); // set to the ffmpeg executable +define(VIDEO_RENDERING_TEMP_PATH, '/tmp/video'); // set to the temp file path + + +/** + * Define some constants +*/ +define(VIDEO_RENDERING_PENGING, 0); +define(VIDEO_RENDERING_ACTIVE, 5); +define(VIDEO_RENDERING_COMPLETE, 10); + + +include_once './includes/bootstrap.inc'; +drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); + +video_render_main(); + +/** + * Main for video_render.php +*/ +function video_render_main() { + + if($job = video_render_select()) { + video_render_start($job); + } + else { + print 'no jobs to schedule' . "\n"; + } +} + + +/** + * Starts rendering for a job +*/ +function video_render_start($job) { + // 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 %convertfile.flv')); + + $command = "$converter $options"; + + print('executing ' . $command); + + //execute the command + ob_start(); + passthru($command." 2>&1", $command_return); + $command_output = ob_get_contents(); + ob_end_clean(); + + print $command_output; + + if (!file_exists($convfile)) { + print 'video conversion failed'; + // TODO: better error handling + } + else { + // move the video to the definitive location + $file = array( + 'filename' => $job->origfile . ".flv", + 'filemime' => 'application/octet-stream', // is there something better??? + 'filesize' => filesize($convfile), + 'filepath' => $convfile, + 'nid' => $job->nid, + ); + + $file = ((object) $file); + + $dest_dir = variable_get('video_upload_default_path', 'videos') .'/'; + + //print file_directory_path() . '/' . $dest_dir . basename($file->filename); + if (file_move($file, $dest)) { + $file->fid = db_next_id('{files}_fid'); + print_r($file); + db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $file->fid, $job->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize); + + db_query("INSERT INTO {file_revisions} (fid, vid, list, description) VALUES (%d, %d, %d, '%s')", $file->fid, $job->vid, $file->list, $file->description); + + db_query('UPDATE {video} SET vidfile = "%s" WHERE nid=%d AND vid=%d', $file->filename, $job->nid, $job->vid); + } + else { + print 'error moving video to the final directory'; + } + } +} + + +/** + * Select a job from the queue +*/ +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); + + return db_fetch_object($result); +} diff --git a/plugins/video_image/video_image.module b/plugins/video_image/video_image.module index 9b8c0da..4c134eb 100644 --- a/plugins/video_image/video_image.module +++ b/plugins/video_image/video_image.module @@ -54,13 +54,15 @@ function video_image_admin_settings() { '#type' => 'checkbox', '#title' => t('Publish the video thumbnails'), '#description' => t('Checking this value will cause the video thumbnail image nodes to be published and therefore could show up in blocks. Usually, this is not what you want because then you could end up with both the thumbnail node and the video node showing up and since there is no way to link the image node to the video node, this is not desirable. However, with this unchecked, the administrator will end up with a lot of unpublished nodes.'), - '#default_value' => _video_publish_thumbnails(), + '#default_value' => _video_image_publish_thumbnails(), ); $form['video_image_promote_thumbnail'] = array( '#type' => 'checkbox', '#title' => t('Promote the thumbnails to the front page'), - '#default_value' => _video_promote_thumbnails(), + '#default_value' => _video_image_promote_thumbnails(), ); + + return system_settings_form($form); } /** diff --git a/plugins/video_upload/video_upload.module b/plugins/video_upload/video_upload.module index c11cd1e..f22327b 100644 --- a/plugins/video_upload/video_upload.module +++ b/plugins/video_upload/video_upload.module @@ -233,6 +233,7 @@ function _video_upload_store(&$node) { $file->fid = db_next_id('{files}_fid'); db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $file->fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize); db_query("INSERT INTO {file_revisions} (fid, vid, list, description) VALUES (%d, %d, %d, '%s')", $file->fid, $node->vid, $file->list, $file->description); + $_SESSION['video_upload_file_stored'] = $file; unset($_SESSION['video_upload_file']); } else { diff --git a/views_video.inc b/views_video.inc index 77bce9c..6bbed4d 100644 --- a/views_video.inc +++ b/views_video.inc @@ -66,7 +66,7 @@ function video_views_tables() { ); // Add video_image support only if the video_image module is enabled - if (module_exist('video_image')) { + if (module_exists('video_image')) { $tables['video']['fields']['video_image'] = array( 'name' => t('Video: Thumbnail'), 'notafield' => true, @@ -211,4 +211,4 @@ function video_views_handler_field_video_image($fieldinfo, $fielddata, $value, $ $node = node_load($data->nid); $output = theme_video_image_body($node); return $output; -}
\ No newline at end of file +} |