aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ffmpeg.inc275
-rw-r--r--plugins/ffmpeg_wrapper.inc406
-rw-r--r--plugins/video_ffmpeg_helper/README.txt47
-rw-r--r--plugins/video_ffmpeg_helper/video_ffmpeg_helper.info8
-rw-r--r--plugins/video_ffmpeg_helper/video_ffmpeg_helper.install89
-rw-r--r--plugins/video_ffmpeg_helper/video_ffmpeg_helper.module539
-rw-r--r--plugins/video_ffmpeg_helper/video_render.php256
-rw-r--r--plugins/video_ffmpeg_helper/video_scheduler.php115
-rw-r--r--plugins/video_image/video_image.info8
-rw-r--r--plugins/video_image/video_image.module570
-rw-r--r--plugins/video_multidownload/video_multidownload.info6
-rw-r--r--plugins/video_multidownload/video_multidownload.module393
-rw-r--r--plugins/video_optmetadata/video_optmetadata.info7
-rw-r--r--plugins/video_optmetadata/video_optmetadata.module146
-rw-r--r--plugins/video_params/video_params.info7
-rw-r--r--plugins/video_params/video_params.module106
-rw-r--r--plugins/zencoder.inc307
17 files changed, 988 insertions, 2297 deletions
diff --git a/plugins/ffmpeg.inc b/plugins/ffmpeg.inc
new file mode 100644
index 0000000..e8e0057
--- /dev/null
+++ b/plugins/ffmpeg.inc
@@ -0,0 +1,275 @@
+<?php
+//$Id$
+
+/**
+ * @file
+ * Provide a api for video conversion and auto thumbnailing using ffmpeg.
+ *
+ * @author Heshan Wanigasooriya <heshan at heidisoft.com, heshanmw at gmail dot com>
+ * TODO: add common settings from video module configurations and extend it from ffmpeg.inc
+ * since we need to have executable path of ffmpeg to ffmpeg.inc we need to have it
+ */
+
+/**
+ * Define some constants
+ */
+defined('VIDEO_RENDERING_PENDING')
+ or define('VIDEO_RENDERING_PENDING', 1);
+defined('VIDEO_RENDERING_ACTIVE')
+ or define('VIDEO_RENDERING_ACTIVE', 5);
+defined('VIDEO_RENDERING_COMPLETE')
+ or define('VIDEO_RENDERING_COMPLETE', 10);
+defined('VIDEO_RENDERING_FAILED')
+ or define('VIDEO_RENDERING_FAILED', 20);
+
+// nice value to append at the beginning of the command
+defined('VIDEO_RENDERING_NICE')
+ or define('VIDEO_RENDERING_NICE', 'nice -n 19');
+
+
+// TODO : add cron API to video module
+function ffmpeg_cron() {
+ global $base_url;
+
+ if(variable_get('video_ffmpeg_helper_auto_cvr_cron', true)) {
+ exec("php video_scheduler.php $base_url > /dev/null &");
+ }
+}
+
+
+/**
+ * Get some informations from the video file
+ */
+function ffmpeg_get_video_info($vidfile) {
+ static $ffmpeg_info;
+ $fid = $vidfile['fid'];
+ // $command_output = cache_get($fid);
+ // if(empty($command_output)) {
+ // escape file name for safety
+ $file = escapeshellarg($vidfile['filepath']);
+ // create the full command to execute
+ $command = variable_get('video_transcoder_path', '/usr/bin/ffmpeg') . ' -i ' . $file;
+
+ //execute the command
+ ob_start();
+ passthru($command." 2>&1", $command_return);
+ $command_output = ob_get_contents();
+ ob_end_clean();
+
+ // cache the result for further calls
+ // $ffmpeg_info[$vidfile['fid']] = $command_output;
+ // cache_set($vidfile['fid'], $command_output);
+ // }
+
+ return $command_output;
+}
+
+
+/**
+ * Return the video resolution
+ */
+function ffmpeg_auto_resolution(&$node) {
+
+ if(!variable_get('video_ffmpeg_helper_auto_resolution', false)) {
+
+ // call ffmpeg -i
+ $ffmpeg_output = ffmpeg_get_video_info($node);
+
+ // get resolution
+ $pattern = '/Video: .*, ([0-9]{2,4}x[0-9]{2,4})/';
+ preg_match_all($pattern, $ffmpeg_output, $matches, PREG_PATTERN_ORDER);
+ $resolution = $matches[1][0];
+
+ return explode("x", $resolution);
+ }
+ return null;
+}
+
+
+/**
+ * Return the playtime seconds of a video
+ */
+function ffmpeg_auto_playtime($file) {
+
+ if(!variable_get('video_ffmpeg_helper_auto_playtime', false)) {
+
+ // call ffmpeg -i
+ $ffmpeg_output = ffmpeg_get_video_info($file);
+
+ // get playtime
+ $pattern = '/Duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9])/';
+ preg_match_all($pattern, $ffmpeg_output, $matches, PREG_PATTERN_ORDER);
+ $playtime = $matches[1][0];
+
+ // ffmpeg return lenght as 00:00:31.1 Let's get playtime from that
+ $hmsmm = explode(":", $playtime);
+
+ $tmp = explode(".", $hmsmm[2]);
+ $seconds = $tmp[0];
+
+ $hours = $hmsmm[0];
+ $minutes = $hmsmm[1];
+
+ return $seconds + ($hours * 3600) + ($minutes * 60);
+ }
+}
+
+/**
+ * Generates a thumbnail from the video file
+ * Implementing hook_auto_thumbnail on inc
+ *
+ * @param $vidfile
+ * object with element information
+ *
+ * @return
+ * a drupal file objects
+ */
+function ffmpeg_auto_thumbnail($vidfile) {
+ global $user;
+ $uploaded_file = $vidfile;
+ $fid = $uploaded_file["fid"];
+
+ // are we debugging?
+ // escape the filename for safety
+ $videofile = escapeshellarg($uploaded_file['filepath']);
+ $thumb_path = variable_get('video_thumb_path', 'video_thumbs');
+ //files will save in files/video_thumbs/#fileId folder
+ $tmp = file_directory_path(). '/' . $thumb_path . '/' . $fid;
+ // Ensure the destination directory exists and is writable.
+ $directories = explode('/', $tmp);
+ // array_pop($directories); // Remove the file itself.
+ // Get the file system directory.
+ $file_system = file_directory_path();
+ foreach ($directories as $directory) {
+ $full_path = isset($full_path) ? $full_path . '/' . $directory : $directory;
+ // Don't check directories outside the file system path.
+ if (strpos($full_path, $file_system) === 0) {
+ field_file_check_directory($full_path, FILE_CREATE_DIRECTORY);
+ }
+ }
+ $count = variable_get('no_of_video_thumbs', 5);
+ $duration = ffmpeg_auto_playtime($vidfile);
+ $files = NULL;
+ for($i = 1; $i <= $count; $i++) {
+ // get ffmpeg configurations
+ $seek = ($duration/$count) * $i;
+ $thumbfile = $tmp . "/video-thumb-for-$fid-$i.png";
+ //skip files already exists, this will save ffmpeg traffic
+ if (!is_file($thumbfile)) {
+ $tnail = variable_get('video_transcoder_path', '/usr/bin/ffmpeg');
+ $options = preg_replace(array('/%videofile/', '/%thumbfile/', '/%seek/'), array($videofile, $thumbfile, $seek), variable_get('video_ffmpeg_thumbnailer_options', '-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile'));
+ // $options = preg_replace(array('/%videofile/', '/%tmp/', '/%id/', '/%interval/'), array($videofile, $tmp, $i, ($duration/$count)), variable_get('video_image_thumbnailer_options', '-ss %id*%interval -i %videofile -vframes 1 %thumbfile'));
+ // ffmpeg -ss $i*$interval -i intro.mov -vframes 1 -s 320x240 thumb_$i.jpg
+ //ffmpeg -i superstunt_8uiarzrh.mp4 -r 0.1 -ss 00:00:5 -f image2 img/images%02d.png
+ ////ffmpeg -i superstunt_8uiarzrh.mp4 -r 0.05 -ss 00:00:5 -f image2 img/images%1d.jpg
+ // executes the command
+ $command = "$tnail $options";
+ ob_start();
+ passthru($command." 2>&1", $tnail_return);
+ $tnail_output = ob_get_contents();
+ ob_end_clean();
+ if (!file_exists($thumbfile)) {
+ $error_param = array(
+ '%file' => $thumbfile,
+ '%cmd' => $command,
+ '%out' => $tnail_output,
+ );
+ $error_msg = t("error generating thumbnail for video: generated file %file does not exist.<br />Command Executed:<br />%cmd<br />Command Output:<br />%out", $error_param);
+ // let's log this
+ watchdog('video_ffmpeg',$error_msg, array(), WATCHDOG_ERROR);
+ }
+ }
+ // Begin building file object.
+ //TODO : use file_munge_filename()
+ $file = new stdClass();
+ $file->uid = $user->uid;
+ $file->status = FILE_STATUS_TEMPORARY;
+ $file->filename = trim("video-thumb-for-$fid-$i.png");
+ $file->filepath = $thumbfile;
+ $file->filemime = file_get_mimetype("video-thumb-for-$fid-$i.png");
+ $file->filesize = filesize($thumbfile);
+ $file->timestamp = time();
+ $files[] = $file;
+ }
+ return $files;
+}
+
+/**
+ * Implementing hook_chcek_exepath() on inc
+ * To check the the path is executable or not
+ * @param <type> path to check
+ * @return bool TRUE/FALSE
+ */
+function ffmpeg_check_exe_path($path=NULL) {
+ if (!$path) {
+ $path = variable_get('video_transcoder_path', '/usr/bin/ffmpeg');
+ }
+ if (function_exists('is_executable')) {
+ $test = 'is_executable';
+ } else {
+ $test = 'file_exists';
+ }
+ return $test($path);
+}
+
+/**
+ * Implementing hook_auto_convert();
+ * @param <type> $job
+ */
+function ffmpeg_auto_convert(&$job) {
+ $videofile = escapeshellarg($job->filepath); // escape file name for safety
+ $convfile = tempnam(file_directory_temp(), 'video-rendering');
+ $audiobitrate = variable_get('video_ffmpeg_helper_auto_cvr_audio_bitrate', 64);
+ $videobitrate = variable_get('video_ffmpeg_helper_auto_cvr_video_bitrate', 200);
+ $size = _video_render_get_size();
+ $converter = variable_get('video_transcoder_path', '/usr/bin/ffmpeg');
+
+ $options = preg_replace(array('/%videofile/', '/%convertfile/', '/%audiobitrate/', '/%size/', '/%videobitrate/'),
+ array($videofile, $convfile, $audiobitrate, $size, $videobitrate),
+ variable_get('video_ffmpeg_helper_auto_cvr_options',
+ '-y -i %videofile -f flv -ar 22050 -ab %audiobitrate -s %size -b %videobitrate -qscale 1 %convertfile'));
+
+ // set to the converted file output
+ $job->convfile = $convfile;
+
+ $command = VIDEO_RENDERING_NICE . " $converter $options";
+
+ //print('executing ' . $command); die;
+ watchdog('video_render', 'executing: ' . $command, array(), WATCHDOG_DEBUG);
+// watchdog('video_render', 'Starting : ' . time());
+ //execute the command
+ ob_start();
+ passthru($command." 2>&1", $command_return);
+ $command_output = ob_get_contents();
+ ob_end_clean();
+// watchdog('video_render', 'Completed');
+ //print $command_output;
+
+ if (!file_exists($job->convfile) || !filesize($job->convfile)) {
+ watchdog('video_render', 'video conversion failed. ffmpeg reported the following output: ' . $command_output, array(), WATCHDOG_ERROR);
+ // _video_render_set_video_encoded_fid($job->nid, $job->vid, -1);
+ // _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_FAILED);
+ }
+ else {
+ $file_name = basename($job->filename . ".flv");
+ $file = new stdClass();
+ $file->uid = $job->uid;
+ $file->status = FILE_STATUS_PERMANENT;
+ $file->filename = basename($file_name);
+ $file->filepath = $job->convfile;
+ $file->filemime = file_get_mimetype($file_name);
+ $file->filesize = filesize($job->convfile);
+ $file->timestamp = time();
+
+ $job->converted = $file;
+ }
+}
+
+
+/**
+ * Calculate the converted video size basing on the width set on administration.
+ * Aspect ration is maintained.
+ */
+function _video_render_get_size() {
+ return variable_get('video_ffmpeg_width', 640) . 'x' . variable_get('video_ffmpeg_height', 480);
+} \ No newline at end of file
diff --git a/plugins/ffmpeg_wrapper.inc b/plugins/ffmpeg_wrapper.inc
new file mode 100644
index 0000000..228d8ce
--- /dev/null
+++ b/plugins/ffmpeg_wrapper.inc
@@ -0,0 +1,406 @@
+<?php
+//$Id$
+
+/**
+ * @file
+ * Provide a api for video conversion and auto thumbnailing using ffmpeg.
+ *
+ * You must have ffmpeg_wrapper module installed in order to use this
+ *
+ * @author Heshan Wanigasooriya <heshan at heidisoft.com, heshanmw at gmail dot com>
+ */
+
+/**
+ * Define some constants
+ */
+defined('VIDEO_RENDERING_PENDING')
+ or define('VIDEO_RENDERING_PENDING', 1);
+defined('VIDEO_RENDERING_ACTIVE')
+ or define('VIDEO_RENDERING_ACTIVE', 5);
+defined('VIDEO_RENDERING_COMPLETE')
+ or define('VIDEO_RENDERING_COMPLETE', 10);
+defined('VIDEO_RENDERING_FAILED')
+ or define('VIDEO_RENDERING_FAILED', 20);
+
+// nice value to append at the beginning of the command
+defined('VIDEO_RENDERING_NICE')
+ or define('VIDEO_RENDERING_NICE', 'nice -n 19');
+
+
+// TODO : add cron API to video module
+function ffmpeg_wrapper_cron() {
+ global $base_url;
+
+ if(variable_get('video_ffmpeg_helper_auto_cvr_cron', true)) {
+ exec("php video_scheduler.php $base_url > /dev/null &");
+ }
+}
+
+
+/**
+ * Get some informations from the video file
+ */
+function ffmpeg_wrapper_get_video_info($vidfile) {
+ static $ffmpeg_info;
+ $fid = $vidfile['fid'];
+ // $command_output = cache_get($fid);
+ // if(empty($command_output)) {
+ // escape file name for safety
+ $file = escapeshellarg($vidfile['filepath']);
+ // create the full command to execute
+ $command = variable_get('video_transcoder_path', '/usr/bin/ffmpeg') . ' -i ' . $file;
+
+ //execute the command
+ ob_start();
+ passthru($command." 2>&1", $command_return);
+ $command_output = ob_get_contents();
+ ob_end_clean();
+
+ // cache the result for further calls
+ // $ffmpeg_info[$vidfile['fid']] = $command_output;
+ // cache_set($vidfile['fid'], $command_output);
+ // }
+
+ return $command_output;
+}
+
+
+/**
+ * Return the video resolution
+ */
+function ffmpeg_wrapper_auto_resolution(&$vidfile) {
+
+ if(!variable_get('video_ffmpeg_helper_auto_resolution', false)) {
+
+ // call ffmpeg -i
+ $filepath = escapeshellarg($vidfile['filepath']);
+ $ffmpeg_output = ffmpeg_wrapper_file_data($filepath);
+
+ // get resolution
+ $pattern = '/Video: .*, ([0-9]{2,4}x[0-9]{2,4})/';
+ preg_match_all($pattern, $ffmpeg_output, $matches, PREG_PATTERN_ORDER);
+ $resolution = $matches[1][0];
+
+ return explode("x", $resolution);
+ }
+ return null;
+}
+
+
+/**
+ * Return the playtime seconds of a video
+ */
+function ffmpeg_wrapper_auto_playtime($file) {
+
+ if(!variable_get('video_ffmpeg_helper_auto_playtime', false)) {
+
+ // call ffmpeg -i
+ $ffmpeg_output = ffmpeg_wrapper_get_video_info($file);
+
+ // get playtime
+ $pattern = '/Duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9])/';
+ preg_match_all($pattern, $ffmpeg_output, $matches, PREG_PATTERN_ORDER);
+ $playtime = $matches[1][0];
+
+ // ffmpeg return lenght as 00:00:31.1 Let's get playtime from that
+ $hmsmm = explode(":", $playtime);
+
+ $tmp = explode(".", $hmsmm[2]);
+ $seconds = $tmp[0];
+
+ $hours = $hmsmm[0];
+ $minutes = $hmsmm[1];
+
+ return $seconds + ($hours * 3600) + ($minutes * 60);
+ }
+}
+
+/**
+ * Generates a thumbnail from the video file
+ * Implementing hook_auto_thumbnail on inc
+ *
+ * @param $vidfile
+ * object with element information
+ *
+ * @return
+ * a drupal file objects
+ */
+function ffmpeg_wrapper_auto_thumbnail($vidfile) {
+ global $user;
+ $uploaded_file = $vidfile;
+ $fid = $uploaded_file["fid"];
+
+ // are we debugging?
+ // escape the filename for safety
+ $videofile = escapeshellarg($uploaded_file['filepath']);
+ $thumb_path = variable_get('video_thumb_path', 'video_thumbs');
+ //files will save in files/video_thumbs/#fileId folder
+ $tmp = file_directory_path(). '/' . $thumb_path . '/' . $fid;
+ // Ensure the destination directory exists and is writable.
+ $directories = explode('/', $tmp);
+ // array_pop($directories); // Remove the file itself.
+ // Get the file system directory.
+ $file_system = file_directory_path();
+ foreach ($directories as $directory) {
+ $full_path = isset($full_path) ? $full_path . '/' . $directory : $directory;
+ // Don't check directories outside the file system path.
+ if (strpos($full_path, $file_system) === 0) {
+ field_file_check_directory($full_path, FILE_CREATE_DIRECTORY);
+ }
+ }
+ $count = variable_get('no_of_video_thumbs', 5);
+ // set file path
+ $filepath = $vidfile['filepath'];
+ // calling ffmpeg_wrapper_file_data function
+ $file_data = ffmpeg_wrapper_file_data($filepath);
+ $duration = $file_data['duration'];
+ $files = NULL;
+ for($i = 1; $i <= $count; $i++) {
+ // get ffmpeg configurations
+ $seek = ($duration/$count) * $i;
+ $thumbfile = $tmp . "/video-thumb-for-$fid-$i.png";
+ //skip files already exists, this will save ffmpeg traffic
+ if (!is_file($thumbfile)) {
+// $tnail = variable_get('video_transcoder_path', '/usr/bin/ffmpeg');
+ $options = preg_replace(array('/%videofile/', '/%thumbfile/', '/%seek/'), array($videofile, $thumbfile, $seek), variable_get('video_ffmpeg_thumbnailer_options', '-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile'));
+ // executes the command
+ $tnail_output = ffmpeg_wrapper_run_command($options, $error_check = true, $path = '');
+// $command = "$tnail $options";
+// ob_start();
+// passthru($command." 2>&1", $tnail_return);
+// $tnail_output = ob_get_contents();
+// ob_end_clean();
+ if (!file_exists($thumbfile)) {
+ $error_param = array(
+ '%file' => $thumbfile,
+ '%cmd' => $options,
+ '%out' => $tnail_output,
+ );
+ $error_msg = t("error generating thumbnail for video: generated file %file does not exist.<br />Command Executed:<br />%cmd<br />Command Output:<br />%out", $error_param);
+ // let's log this
+ watchdog('video_ffmpeg',$error_msg);
+ }
+ }
+ // Begin building file object.
+ //TODO : use file_munge_filename()
+ $file = new stdClass();
+ $file->uid = $user->uid;
+ $file->status = FILE_STATUS_TEMPORARY;
+ $file->filename = trim("video-thumb-for-$fid-$i.png");
+ $file->filepath = $thumbfile;
+ $file->filemime = file_get_mimetype("video-thumb-for-$fid-$i.png");
+ $file->filesize = filesize($thumbfile);
+ $file->timestamp = time();
+ $files[] = $file;
+ }
+ return $files;
+}
+
+/**
+ * Implementing hook_chcek_exepath() on inc
+ * To check the the path is executable or not
+ * @param <type> path to check
+ * @return bool TRUE/FALSE
+ */
+function ffmpeg_wrapper_check_exe_path($path = NULL) {
+ return ffmpeg_wrapper_executable();
+}
+
+/**
+ * Implementing hook_auto_convert();
+ * @param <type> $job
+ */
+//function ffmpeg_wrapper_auto_convert(&$job) {
+// $videofile = escapeshellarg($job->filepath); // escape file name for safety
+// $convfile = tempnam(file_directory_temp(), 'video-rendering');
+// $audiobitrate = variable_get('video_ffmpeg_helper_auto_cvr_audio_bitrate', 64);
+// $videobitrate = variable_get('video_ffmpeg_helper_auto_cvr_video_bitrate', 200);
+// $size = _video_render_get_size();
+//// $converter = variable_get('video_transcoder_path', '/usr/bin/ffmpeg');
+//
+// $options = preg_replace(array('/%videofile/', '/%convertfile/', '/%audiobitrate/', '/%size/', '/%videobitrate/'),
+// array($videofile, $convfile, $audiobitrate, $size, $videobitrate),
+// variable_get('video_ffmpeg_helper_auto_cvr_options',
+// '-y -i %videofile -f flv -ar 22050 -ab %audiobitrate -s %size -b %videobitrate -qscale 1 %convertfile'));
+//
+// // set to the converted file output
+// $job->convfile = $convfile;
+//
+// // run conversion commands from ffmpeg_wrapper module
+// $command_output = ffmpeg_wrapper_run_command($options, $error_check = true, $path = '');
+//
+//// $command = VIDEO_RENDERING_NICE . " $converter $options";
+//
+// //print('executing ' . $command); die;
+// watchdog('video_render', 'executing: ' . $options);
+//// watchdog('video_render', 'Starting : ' . time());
+// //execute the command
+//// ob_start();
+//// passthru($command." 2>&1", $command_return);
+//// $command_output = ob_get_contents();
+//// ob_end_clean();
+//// watchdog('video_render', 'Completed');
+// //print $command_output;
+//
+// if (!file_exists($job->convfile) || !filesize($job->convfile)) {
+// watchdog('video_render', 'video conversion failed. ffmpeg reported the following output: ' . $command_output);
+// // _video_render_set_video_encoded_fid($job->nid, $job->vid, -1);
+// // _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_FAILED);
+// }
+// else {
+// $file_name = basename($job->filename . ".flv");
+// $file = new stdClass();
+// $file->uid = $job->uid;
+// $file->status = FILE_STATUS_PERMANENT;
+// $file->filename = basename($file_name);
+// $file->filepath = $job->convfile;
+// $file->filemime = file_get_mimetype($file_name);
+// $file->filesize = filesize($job->convfile);
+// $file->timestamp = time();
+//
+// $job->converted = $file;
+// }
+//}
+
+
+/**
+ * This runs FFmpeg based on the form data passed into it.
+ * @param string $input_file
+ * path to the file to operate on
+ * @param array $params
+ * configuration options in the format set in the ffmpeg_wrapper_configuration_form()
+ * @param string $output_file_path
+ * where to place the file, assumes same dir as $input_file. No trailing slash
+ * @param object $ffmpeg_object
+ * contains debug information that calling functions can utilize
+ * @return string
+ *
+ */
+function ffmpeg_wrapper_auto_convert(&$job) {
+
+ $ffmpeg_object = new stdClass();
+ // check configuration are pass of then use global $conf
+ if(empty ($params)){
+ global $conf;
+ $params = $conf;
+ }
+
+ $input_file = $job->filepath; // escape file name for safety
+
+ // first error check, make sure that we can decode this kind of file
+ if (! ffmpeg_wrapper_can_decode($input_file)) {
+ $message = 'FFmpeg Wrapper can not decode this file: !file';
+ $variables = array('!file' => l($input_file, file_create_url($input_file)));
+ watchdog('video_render', $message, $variables, WATCHDOG_ERROR);
+ $ffmpeg_object->errors[] = $message;
+ return false;
+ }
+
+ // build the output file path if we don't have one. Use the output type as the extension.
+ $output_file = file_create_filename(basename($input_file) .'.'. $params['ffmpeg_output_type'], ($output_file_path ? $output_file_path : dirname($input_file)));
+
+ // did the admin define a specific FFmpeg comand to run?
+ // we only run what the admin specified
+ if ($params['ffmpeg_video_custom']) {
+ $options[] = str_replace(array('%in_file', '%out_file'), array($input_file, $output_file), $params['ffmpeg_video_custom_command']);
+ }
+ // build a standard configuration
+ else {
+ // build the ffmpeg command structure out
+ $options = array();
+
+ // input file
+ $options[] = "-i '". $input_file ."'";
+
+ // build the watermark config
+ if ($params['ffmpeg_video_wm']) {
+ $options[] = "-vhook '". ffmpeg_wrapper_path_to_vhook('watermark.so') ." -f ". $params['ffmpeg_video_wm_file'] ."'";
+ }
+
+ // build the audio config
+ if ($params['ffmpeg_audio_advanced']) {
+
+ // use a specifc codec?
+ if ($params['ffmpeg_audio_acodec']) {
+ $options[] = '-acodec '. $params['ffmpeg_audio_acodec'];
+ }
+
+ // use a specific sample rate?
+ if ($params['ffmpeg_audio_ar'] ) {
+ $options[] = '-ar '. $params['ffmpeg_audio_ar'];
+ }
+
+ // use a specific bit rate?
+ if ($params['ffmpeg_audio_ab']) {
+ $options[] = '-ab '. $params['ffmpeg_audio_ab'];
+ }
+ }
+
+ // build the video config
+ if ($params['ffmpeg_video_advanced']) {
+
+ // is codec set?
+ if ($params['ffmpeg_video_vcodec']) {
+ $options[] = '-vcodec '. $params['ffmpeg_video_vcodec'];
+ }
+
+ // is frame size set?
+ if ($params['ffmpeg_video_size']) {
+ $options[] = '-s '. $params[$params['ffmpeg_video_size'] == 'other' ? 'ffmpeg_video_size_other' : 'ffmpeg_video_size'];
+ }
+
+ // is the bit rate set?
+ if ($params['ffmpeg_video_br']) {
+ $options[] = '-b '. $params['ffmpeg_video_br'];
+ }
+
+ // is frame rate set?
+ if ($params['ffmpeg_video_fps']) {
+ $options[] = '-r '. $params['ffmpeg_video_fps'];
+ }
+ }
+
+ // implement truncating
+ if ($params['ffmpeg_time_advanced']) {
+ $options[] = '-t '. $params['ffmpeg_time'];
+ }
+
+ // add the output file
+ $options[] = "'". $output_file ."'";
+ }
+
+ $ffmpeg_object->command = implode(" ", $options);
+
+ // run ffmpeg with error checking
+ if (! $success = ffmpeg_wrapper_run_command($ffmpeg_object->command)) {
+ watchdog('video_render', 'video conversion failed. ffmpeg reported the following output: ' . $success);
+ return false;
+ }
+
+ // successful convert, make a note in the log
+ $message = 'FFmpeg converted this file: @file';
+ $message .= '<br />'. 'FFmpeg ran this command: <br /><pre> !command </pre>';
+ $variables = array('@file' => $output_file, '!command' => $ffmpeg_object->command);
+ watchdog('video_render', $message, $variables, WATCHDOG_NOTICE);
+
+ $ffmpeg_object->output_file = $output_file;
+
+ if (!file_exists($output_file) || !filesize($output_file)) {
+ watchdog('video_render', 'video conversion failed. ffmpeg reported the following output: ' . $command_output);
+ // _video_render_set_video_encoded_fid($job->nid, $job->vid, -1);
+ // _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_FAILED);
+ }
+ else {
+ $file_name = basename($output_file);
+ $file = new stdClass();
+ $file->uid = $job->uid;
+ $file->status = FILE_STATUS_PERMANENT;
+ $file->filename = basename($file_name);
+ $file->filepath = $output_file;
+ $file->filemime = file_get_mimetype($file_name);
+ $file->filesize = filesize($output_file);
+ $file->timestamp = time();
+
+ $job->converted = $file;
+ }
+}
diff --git a/plugins/video_ffmpeg_helper/README.txt b/plugins/video_ffmpeg_helper/README.txt
deleted file mode 100644
index fb63547..0000000
--- a/plugins/video_ffmpeg_helper/README.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-FFMPEG Video.module helper
-==========================
-
-See : http://video.heidisoft.com/docs/users-guide-26
-
-This helper module facilitates uploading new videos using the video module. It
-features a batch processing queue for videos to be transcoded and automatic
-thumbnail generation.
-
-IMPORTANT: the ffmpeg helper currently only works on unix based environment. It currently doesn't support Windows based servers.
-
-Install instructions
---------------------
-
-1. Activate the video_ffmpeg_helper module
-2. Setup it's advanced options to meet your needs
-3. Move (or symlink) video_render.php and video_scheduler.php into your Drupal root
-4. Edit the first "Configuration" code lines of those files to meet your needs (IMPORTANT: path to ffmpeg executable on your server)
-5. Check permissions of the files and folders (/tmp/video and files/* must be writable by the webserver or the user executling the cron job)
-6. You now have two options to execute the video_scheduler.php script:
-
- 6.1 (default) Enable the execution of video_scheduler.php using standard drupal cron.
- GMM: 07/23/2009 Note: ** Do not use this method if your Apache server is running with suPHP **
- As of this writing, suPHP will cause the Drupal cron to loop infinitely and no video
- will be rendered. In this case crontab should be used instead of Drupal cron!
-
- 6.2 Schedule the execution of video_scheduler.php using unix cron
-
- The crontab should look something like this:
-
- # m h dom mon dow user command
- */20 * * * * www-data cd /absolute/path/to/drupal/ ; php video_scheduler.php http://www.example.com/path_to_drupal
-
- This will execute the video_scheduler every 20 minutes.
-
- Note that the video_scheduler doesn't produce any output and cannot be called
- from the web. It will, however, put some information in the watchdog.
-
-
-
-Troubleshooting
-------------------------
-
-Configuring and installing ffmpeg in a web server environment might be pretty difficult. In order to help you troubleshoot the transcoding process the ffmpeg helper puts debugging informations on the drupal logs. I strongly suggest to have a look at them if you are experiencing problems with transcoding.
-
-The ffmpeg puts in the drupal logs the commands it was trying to execute. You might try to rerun them on a command shell in order understand what went wrong.
-
diff --git a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.info b/plugins/video_ffmpeg_helper/video_ffmpeg_helper.info
deleted file mode 100644
index 9706e09..0000000
--- a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.info
+++ /dev/null
@@ -1,8 +0,0 @@
-;$Id$
-name = Video ffmpeg Helper
-description = Provide apis for ffmpeg. Simplify video nodes creation.
-dependencies[] = video
-dependencies[] = video_upload
-package = "Video"
-core = 6.x
-
diff --git a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.install b/plugins/video_ffmpeg_helper/video_ffmpeg_helper.install
deleted file mode 100644
index aa76914..0000000
--- a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.install
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-//$Id$
-/**
- * @file
- * Provide installation functions for video_ffmpeg_helper.module .
- *
- * @author Heshan Wanigasooriya <heshan at heidisoft dot com>
- * <heshanmw at gmail dot com>
- * @todo
- */
-
-/**
- * Implementation of hook_schema().
- */
-function video_ffmpeg_helper_schema() {
- $schema['video_rendering'] = array(
- 'description' => t('Store video transcoding queue'),
- 'fields' => array(
- 'vid' => array(
- 'description' => t('video id : primary key'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'nid' => array(
- 'description' => t('Node id : index of the {node}.nid'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'origfile' => array(
- 'description' => t('original file path'),
- 'type' => 'text',
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'pid' => array(
- 'description' => t('Pid'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'status' => array(
- 'description' => t('status of the transcoding'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'started' => array(
- 'description' => t('Started transcodings'),
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'completed' => array(
- 'description' => t('Transcoding completed'),
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'indexes' => array(
- 'nid' => array('nid'),
- ),
- 'primary key' => array('vid'),
- );
-
- return $schema;
-}
-
-
-/**
- * Implementation of hook_install().
- */
-function video_ffmpeg_helper_install() {
- // Create tables.
- drupal_install_schema('video_ffmpeg_helper');
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function video_ffmpeg_helper_uninstall() {
- drupal_uninstall_schema('video_ffmpeg_helper');
-} \ No newline at end of file
diff --git a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module b/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module
deleted file mode 100644
index 0adb3de..0000000
--- a/plugins/video_ffmpeg_helper/video_ffmpeg_helper.module
+++ /dev/null
@@ -1,539 +0,0 @@
-<?php
-//$Id$
-/**
- * @file
- * Provide some api for use ffmpeg. Simplify video nodes creation.
- *
- * @author Fabio Varesano <fvaresano at yahoo dot it>
- * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw at gmail dot com>
- * @todo
- * 1. Remove modules and user existing ffmpeg wrapper module
- */
-
-/**
- * Define some constants
-*/
-define('VIDEO_RENDERING_PENDING', 1);
-define('VIDEO_RENDERING_ACTIVE', 5);
-define('VIDEO_RENDERING_COMPLETE', 10);
-define('VIDEO_RENDERING_FAILED', 20);
-
-
-
-function video_ffmpeg_helper_cron() {
- global $base_url;
-
- if(variable_get('video_ffmpeg_helper_auto_cvr_cron', true)) {
- exec("php video_scheduler.php $base_url > /dev/null &");
- }
-}
-
-
-/**
- * Implementatio of hook_perm()
-*/
-function video_ffmpeg_helper_perm() {
- return array('bypass automatic video conversion');
-}
-
-
-/**
- * Implementation of hook_help().
- */
-function video_ffmpeg_helper_help($path, $arg) {
- switch ($path) {
- case 'admin/modules#description':
- return t('Enable ffmpeg support for video module.');
- }
-}
-
-/**
- * Implementation of hook_menu()
- */
-function video_ffmpeg_helper_menu() {
- $items = array();
- $items['admin/settings/video/ffmpeg_helper'] = array(
- 'title' => 'Video ffmpeg Helper',
- 'description' => 'Administer video_ffmpeg_helper module settings',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('video_ffmpeg_helper_admin_settings'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- return $items;
-}
-
-/**
- * Validation for settings form
- */
-function video_ffmpeg_helper_admin_settings_validate($form, &$form_state) {
- if (variable_get('video_image_auto_thumbnail', 0)) {
- if (!_video_ffmpeg_helper_check_exe_path($form_state['values']['video_ffmpeg_helper_ffmpeg_path'])) {
- form_set_error('video_ffmpeg_helper_ffmpeg_path', t('Set correct path for ffmpeg'));
- }
- if (!is_numeric($form_state['values']['video_ffmpeg_helper_auto_thumbnail_seek'])) {
- form_set_error('video_ffmpeg_helper_auto_thumbnail_seek', t('Seek time must be an integer'));
- }
- $options = $form_state['values']['video_ffmpeg_helper_thumbnailer_options'];
- if (!strstr($options, '%videofile') || !strstr($options, '%thumbfile')) {
- form_set_error('video_ffmpeg_helper_thumbnailer_options', t('Thumbnail options must contain mandatory arguments %videofile and %thumbfile'));
- }
- }
-}
-
-
-/**
- * Settings form
- */
-function video_ffmpeg_helper_admin_settings() {
- // let's execute after video_image and video_upload
- if (module_exists('video_image') && variable_get('video_image_auto_thumbnail', 0)) {
- $weight = db_result(db_query("SELECT weight FROM {system} WHERE name='video_image'"));
- } else { // video_image might be disabled.. execute after video_upload
- $weight = db_result(db_query("SELECT weight FROM {system} WHERE name='video_upload'"));
- }
- // update the weight in the system table
- db_query("UPDATE {system} SET weight=".($weight+1)." WHERE name='video_ffmpeg_helper'");
-
- $form['video_ffmpeg_helper_ffmpeg_path'] = array(
- '#type' => 'textfield',
- '#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'),
- );
-
-
- $form['video_ffmpeg_helper_auto_resolution'] = array(
- '#type' => 'checkbox',
- '#title' => t('Enable resolution helper'),
- '#description' => t('Use ffmpeg Helper to automatically get the resolution from the video.'),
- '#default_value' => variable_get('video_ffmpeg_helper_auto_resolution', false),
- );
-
- $form['video_ffmpeg_helper_auto_playtime'] = array(
- '#type' => 'checkbox',
- '#title' => t('Enable playtime helper'),
- '#description' => t('Use ffmpeg Helper to automaticcally get the playtime from the video.'),
- '#default_value' => variable_get('video_ffmpeg_helper_auto_playtime', false),
- );
-
- $form['autothumb'] = array(
- '#type' => 'fieldset',
- '#title' => t('Automatic video thumbnailing'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE
- );
- $form['autothumb']['video_ffmpeg_helper_thumbnailer_options'] = array(
- '#type' => 'textfield',
- '#title' => t('Video thumbnailer options'),
- '#description' => t('Provide the options for the thumbnailer. Available argument values are: ').'<ol><li>'.t('%videofile (the video file to thumbnail)').'<li>'.t('%thumbfile (a newly created temporary file to overwrite with the thumbnail)').'<li>'.t('%seek (seconds to seek into video before extracting image).').'</ol>'.t('Only the first two are mandatory. For example, older versions of ffmpeg should use something like: !old While newer versions should use something like: !new', array('!old' => "<div>-i %videofile -y -an -f mjpeg -ss %seek -t 0.001 %thumbfile</div>", '!new' => '<div>-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile</div>')),
- '#default_value' => variable_get('video_ffmpeg_helper_thumbnailer_options', '-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile'),
- );
- $form['autothumb']['video_ffmpeg_helper_auto_thumbnail_seek'] = array(
- '#type' => 'textfield',
- '#title' => t('Video seek offset for thumbnail'),
- '#description' => t('Time in seconds to seek into video before extracting the thumbnail'),
- '#default_value' => variable_get('video_ffmpeg_helper_auto_thumbnail_seek', 2),
- );
- // automatic video conversion settings
- $form['autoconv'] = array(
- '#type' => 'fieldset',
- '#title' => t('Automatic video conversion'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE
- );
- $form['autoconv']['video_ffmpeg_helper_auto_cvr_cron'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use drupal cron for autoconversion'),
- '#description' => t('Click this if you want to execute the video_scheduler.php from the standard drupal cron. If you want to use distributed encodings you might want to disable this.'),
- '#default_value' => variable_get('video_ffmpeg_helper_auto_cvr_cron', 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 in the video_ffmpeg_helper folder or <a title='User Guide' href='http://video.heidisoft.com/docs/users-guide-26'>click here</a> for more informations."),
- '#default_value' => variable_get('video_ffmpeg_helper_auto_conversion', false),
- );
- $form['autoconv']['video_ffmpeg_helper_auto_cvr_width'] = array(
- '#type' => 'textfield',
- '#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_cvr_width', 400),
- );
- $form['autoconv']['video_ffmpeg_helper_auto_cvr_video_bitrate'] = array(
- '#type' => 'textfield',
- '#title' => t('Video bitrate'),
- '#description' => t('The video bitrate in bit/s of the converted video.'),
- '#size' => 10,
- '#maxlength' => 10,
- '#default_value' => variable_get('video_ffmpeg_helper_auto_cvr_video_bitrate', 200000),
- );
- $form['autoconv']['video_ffmpeg_helper_auto_cvr_audio_bitrate'] = array(
- '#type' => 'textfield',
- '#title' => t('Audio bitrate'),
- '#description' => t('The audio bitrate in bit/s of the converted video.'),
- '#size' => 10,
- '#maxlength' => 10,
- '#default_value' => variable_get('video_ffmpeg_helper_auto_cvr_audio_bitrate', 64000),
- );
- $form['autoconv']['advanced'] = array(
- '#type' => 'fieldset',
- '#title' => t('Advanced settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE
- );
- $form['autoconv']['advanced']['video_ffmpeg_helper_auto_cvr_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', array('fragment' => TRUE)))),
- '#default_value' => variable_get('video_ffmpeg_helper_auto_cvr_options', '-y -i %videofile -f flv -ar 22050 -ab %audiobitrate -s %size -b %videobitrate -qscale 1 %convertfile'),
- );
- return system_settings_form($form);
-}
-
-
-/**
- * Implementation of hook_form_alter()
- */
-function video_ffmpeg_helper_form_alter(&$form, &$form_state, $form_id) {
-
- $node = $form['#node'];
-
- //print_r($form);
- if($form_id == 'video_node_form') {
-
- if (function_exists('_image_check_settings')) {
- _image_check_settings();
- $form['#attributes'] = array("enctype" => "multipart/form-data");
-
- }
-
-
- if($node->vtype == 'upload' && user_access('bypass automatic video conversion') && variable_get('video_ffmpeg_helper_auto_conversion', false)) {
- $form['video']['video_ffmpeg_helper_convertion_bypass'] = array(
- '#type' => 'checkbox',
- '#title' => t('Bypass automatic video conversion'),
- '#description' => t('Check this if you want that your video is submitted as it is, without being converted.'),
- '#default_value' => $node->video_ffmpeg_helper_convertion_bypass, // for node previews
- );
- }
- }
-
-}
-
-
-/**
- * Implementation of hook_nodeapi()
- *
- * NOTE: video_ffmpeg nodeapi is executed after video_player rendering
- */
-function video_ffmpeg_helper_nodeapi(&$node, $op, $teaser) {
- if($node->type == 'video' && $node->vtype == 'upload') {
- switch ($op) {
- case 'load':
- // let's check if we have a valid encoded video
- if(isset($node->serial_data['video_encoded_fid']) &&
- is_numeric($node->serial_data['video_encoded_fid']) &&
- $node->serial_data['video_encoded_fid'] > 0) {
- // this video have an encoded version. let's use it insted of the original one. We can safely do this as video_ffmpeg_helper will be scheduled by Drupal after video and video_upload modules
- $output = array();
- $file = _video_upload_get_file($node->serial_data['video_encoded_fid']);
- $output['current_video_rendered_file'] = $file;
- $output['vidfile'] = file_create_url($file->filepath);
- // set the filesize
- $output['size'] = $file->filesize;
-
- return $output;
- }
- //print $node->serial_data['video_encoded_fid']; die;
-
- 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 'presve':
- break;
-
- case 'update':
- /* delete the already existing batch script, we'll recreate it below */
- if(variable_get('video_ffmpeg_helper_auto_conversion', false)) {
- db_query('DELETE FROM {video_rendering} WHERE vid = %d AND nid = %d', $node->vid, $node->nid);
- }
- /* FALLTHROUGH */
- case 'insert':
- if(variable_get('video_ffmpeg_helper_auto_conversion', false) && $node->new_video_upload_file_fid > 0 && !$node->video_ffmpeg_helper_convertion_bypass) {
- // add rendering job to queue
- _video_ffmpeg_helper_add_rendering($node);
- }
-
- break;
-
- case 'prepare':
- ; // for future uses
- break;
-
- case 'view':
- if($teaser == FALSE) {
- if(_video_ffmpeg_helper_is_being_processed($node)) {
- // if the video is still being processed we display a "rendering in progress" message
- $node->content['video_player']['#value'] = theme('video_ffmpeg_helper_inprogress', $node);
- }
- else if($node->serial_data['video_encoded_fid'] == -1) { // conversion failed
- $node->content['video_player']['#value'] = theme('video_ffmpeg_helper_encoding_failed', $node);
- }
- }
- //print_r($node); die;
- break;
-
- case 'alter':
- ; // for future uses
- break;
-
- case 'delete':
- db_query('DELETE FROM {video_rendering} WHERE vid = %d AND nid = %d', $node->vid, $node->nid);
- if($node->serial_data['video_encoded_fid'] > 0) {
- $file = _video_upload_get_file($node->serial_data['video_encoded_fid']);
- _video_upload_delete_file($file);
- }
- break;
-
- }
- }
-}
-
-
-/**
- * Add a video conversion rendering process to the queue
-*/
-function _video_ffmpeg_helper_add_rendering(&$node) {
- $file = _video_upload_get_file($node->new_video_upload_file_fid);
- //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->filepath, 0, VIDEO_RENDERING_PENDING, 0, 0);
-
- drupal_set_message(t('Video submission queued for processing. Please wait: our servers are preparing your video for web displaying.'));
-
- // let's add the rendering in progress video
- $node->vidfile = variable_get('video_ffmpeg_helper_auto_cvr_busy_video_path', 'busy.flv');
- db_query('UPDATE {video} SET vidfile = "%s" WHERE nid=%d AND vid=%d', $node->vidfile, $node->nid, $node->vid);
-
-}
-
-
-/**
- * Returns true if the video is being encoded or queeded
-*/
-function _video_ffmpeg_helper_is_being_processed($node) {
- $result = db_query("SELECT status FROM {video_rendering} WHERE vid = %d AND nid = %d", $node->vid, $node->nid);
- $status = db_result($result);
- if($status == VIDEO_RENDERING_PENDING || $status == VIDEO_RENDERING_ACTIVE) { // video is still being converted
- return TRUE;
- }
- return FALSE;
-}
-
-
-
-/**
- * Get some informations from the video file
-*/
-function _video_ffmpeg_helper_get_video_info(&$node, $value=null) {
- static $ffmpeg_info;
-
- if (isset($value)) {
- $ffmpeg_info[$node->nid] = $value;
- return;
- }
-
- $fileobj = $node->new_video_upload_file ? $node->new_video_upload_file : _video_upload_get_file($node->new_video_upload_file_fid);
-
- // check if we have some info in the cache for the given node
- if(isset($ffmpeg_info[$fileobj->filename])) {
- return $ffmpeg_info[$fileobj->filename];
- }
-
- // escape file name for safety
- $file = escapeshellarg($fileobj->filepath);
- // create the full command to execute
- $command = variable_get('video_ffmpeg_helper_ffmpeg_path', '/usr/bin/ffmpeg') . ' -i ' . $file;
-
- //execute the command
- ob_start();
- passthru($command." 2>&1", $command_return);
- $command_output = ob_get_contents();
- ob_end_clean();
-
- // cache the result for further calls
- $ffmpeg_info[$node->nid] = $command_output;
-
- return $command_output;
-}
-
-
-/**
- * Return the video resolution
- */
-function _video_ffmpeg_helper_auto_resolution(&$node) {
-
- if(variable_get('video_ffmpeg_helper_auto_resolution', false)) {
-
- // call ffmpeg -i
- $ffmpeg_output = _video_ffmpeg_helper_get_video_info($node);
-
- // get resolution
- $pattern = '/Video: .*, ([0-9]{2,4}x[0-9]{2,4})/';
- preg_match_all($pattern, $ffmpeg_output, $matches, PREG_PATTERN_ORDER);
- $resolution = $matches[1][0];
-
- return explode("x", $resolution);
- }
- return null;
-}
-
-
-/**
- * Return the playtime seconds of a video
-*/
-function _video_ffmpeg_helper_auto_playtime(&$node) {
-
- if(variable_get('video_ffmpeg_helper_auto_playtime', false)) {
-
- // call ffmpeg -i
- $ffmpeg_output = _video_ffmpeg_helper_get_video_info($node);
-
- // get playtime
- $pattern = '/Duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9])/';
- preg_match_all($pattern, $ffmpeg_output, $matches, PREG_PATTERN_ORDER);
- $playtime = $matches[1][0];
-
- // ffmpeg return lenght as 00:00:31.1 Let's get playtime from that
- $hmsmm = explode(":", $playtime);
-
- $tmp = explode(".", $hmsmm[2]);
- $seconds = $tmp[0];
-
- $hours = $hmsmm[0];
- $minutes = $hmsmm[1];
-
- return $seconds + ($hours * 3600) + ($minutes * 60);
- }
-}
-
-/**
- * Generates a thumbnail from the video file
- *
- * @param $node
- * object with node information
- *
- * @return
- * a drupal file object
- */
-function _video_ffmpeg_helper_auto_thumbnail(&$node) {
- if (!$node->new_video_upload_file ||
- ($node->new_video_upload_file && count($_POST) && $_POST['new_video_upload_file_fid'])) {
- // we have already thumbnailed this new upload file
- return NULL;
- }
- if (!$node->new_video_upload_file && $node->current_video_upload_file_fid) { // no new files uploaded. skipping thumnailing stuff
- _video_image_thumbnail_debug(t('No new files to thumbnail'));
- return NULL;
- }
- // gets the newly uploaded file object
- $uploaded_file = $node->new_video_upload_file;
-
- // are we debugging?
- // escape the filename for safety
- $videofile = escapeshellarg($uploaded_file->filepath);
- // let's create a temp filename into the drupal temp directory
- $thumbfile = tempnam(file_directory_temp(), 'tnail-thumb');
- // get ffmpeg configurations
- $seek = variable_get('video_ffmpeg_helper_auto_thumbnail_seek', 2);
- $tnail = variable_get('video_ffmpeg_helper_ffmpeg_path', '/usr/bin/ffmpeg');
- $options = preg_replace(array('/%videofile/', '/%thumbfile/', '/%seek/'), array($videofile, $thumbfile, $seek), variable_get('video_image_thumbnailer_options', '-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile'));
-
- // executes the command
- $command = "$tnail $options";
- ob_start();
- passthru($command." 2>&1", $tnail_return);
- $tnail_output = ob_get_contents();
- ob_end_clean();
- _video_ffmpeg_helper_get_video_info($node, $tnail_output);
-
- _video_image_thumbnail_debug(t('Thumbnailer command: ').$command);
- _video_image_thumbnail_debug(t('Thumbnailer output: ')."<pre>\n$tnail_output\n</pre>");
- if (!file_exists($thumbfile)) {
- $error_param = array(
- '%file' => $thumbfile,
- '%cmd' => $command,
- '%out' => $tnail_output,
- );
- $error_msg = t("error generating thumbnail for video: generated file %file does not exist.<br />Command Executed:<br />%cmd<br />Command Output:<br />%out", $error_param);
- // let's log this
- watchdog('video_ffmpeg_helper',$error_msg);
- return false;
- }
- $file = array(
- 'filename' => $uploaded_file->filename . ".video-thumb.jpg",
- 'filemime' => 'image/jpeg',
- 'filesize' => filesize($thumbfile),
- 'filepath' => $thumbfile,
- 'nid' => $node->nid,
- );
-
- if ($tnail_return) {
- _video_image_thumbnail_debug(t('Failed to thumbnail video'));
- return $false;
- }
- _video_image_thumbnail_debug(t('Successfully thumbnailed video'));
- return (object)$file;
-}
-
-function _video_ffmpeg_helper_check_exe_path($path=NULL) {
- if (!$path) {
- $path = variable_get('video_ffmpeg_helper_ffmpeg_path', '/usr/bin/ffmpeg');
- }
- if (function_exists('is_executable')) {
- $test = 'is_executable';
- } else {
- $test = 'file_exists';
- }
- return $test($path);
-}
-
-/**
- * Displays a "encoding in progress message"
-*/
-function theme_video_ffmpeg_helper_inprogress($node) {
- return '<div class="video-ffmpeg-helper-inprogress">'. t('This video is currently being processed. Please wait.') . '</div>';
-}
-
-
-/**
- * Display an "encoding failed" message"
-*/
-function theme_video_ffmpeg_helper_encoding_failed($node) {
- return '<div class="video-ffmpeg-helper-encoding-failed">'. t('The video conversion process has failed. You might want to submit a simpler video format like <em>mpeg</em> or <em>divx avi</em>.<br />If the problem persists please contact website administrators.') . '</div>';
-}
-
-
-/**
- * Implementation of hook_theme().
- */
-function video_ffmpeg_helper_theme() {
- return array(
- 'video_ffmpeg_helper_encoding_failed' => array(
- 'arguments' => array('node' => NULL),
- ),
- 'video_ffmpeg_helper_inprogress' => array(
- 'arguments' => array('node' => NULL),
- ),
- );
-}
diff --git a/plugins/video_ffmpeg_helper/video_render.php b/plugins/video_ffmpeg_helper/video_render.php
deleted file mode 100644
index 8aae1cb..0000000
--- a/plugins/video_ffmpeg_helper/video_render.php
+++ /dev/null
@@ -1,256 +0,0 @@
-<?php
-//$Id$
-/**
- * @file
- * Renders a video. This script is called concurrently by video_scheduler.php
- * This script has to be launched with "php video_render.php nid vid"
- * If you are not using sites/default/settings.php as your settings file,
- * add an optional parameter for the drupal site url:
- * "php video_render.php nid vid http://example.com/" or
- * "php video_render.php nid vid http://example.org/drupal/"
- *
- * @author Fabio Varesano <fvaresano at yahoo dot it>
- * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
- * @author Glen Marianko Twitter@demoforum <glenm at demoforum dot com>
- * @todo
- */
-
-
-/**
- * video_scheduler.php configuration
-*/
-// set path 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');
-
-// nice value to append at the beginning of the command
-define('VIDEO_RENDERING_NICE', 'nice -n 19');
-
-
-/**
- * video_scheduler.php configuration ends.
- * DO NOT EDIT BELOW THIS LINE
-*/
-
-/**
- * Define some constants
-*/
-define('VIDEO_RENDERING_PENDING', 1);
-define('VIDEO_RENDERING_ACTIVE', 5);
-define('VIDEO_RENDERING_COMPLETE', 10);
-define('VIDEO_RENDERING_FAILED', 20);
-
-if (isset($_SERVER['argv'][3])) {
- $url = parse_url($_SERVER['argv'][3]);
- $_SERVER['SCRIPT_NAME'] = $url['path'];
- $_SERVER['HTTP_HOST'] = $url['host'];
-}
-
-include_once('./includes/bootstrap.inc');
-//module_load_include('/includes/bootstrap.inc', 'video_render', 'includes/bootstrap');
-//
-// 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'])) {
- if($_SERVER['argc'] < 3) { // check for command line arguments
- watchdog('video_render', 'Incorrect parameters to the video_render.php script.', WATCHDOG_ERROR);
- print t('Incorrect parameters');
- }
- else {
- video_render_main();
- }
-}
-else {
- print t('This script is only executable from the command line.');
- die();
-}
-
-print("\n");
-
-function video_render_main() {
-
- // get parameters passed from command line
- $nid = $_SERVER['argv'][1];
- $vid = $_SERVER['argv'][2];
-
- // set the status to active
- _video_render_job_change_status($nid, $vid, VIDEO_RENDERING_ACTIVE);
- // load the job object
- $job = _video_render_load_job($nid, $vid, VIDEO_RENDERING_ACTIVE);
-
- if($job == NULL) {
- watchdog('video_render', 'video_render.php has been called with an invalid job resource. exiting.');
- die;
- }
- $command = _video_render_get_command($job);
-
- //print('executing ' . $command); die;
- watchdog('video_render', '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($job->convfile) || !filesize($job->convfile)) {
- watchdog('video_render', 'video conversion failed. ffmpeg reported the following output: ' . $command_output, WATCHDOG_ERROR);
- _video_render_set_video_encoded_fid($job->nid, $job->vid, -1);
- _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_FAILED);
- }
- else {
- // move the video to the definitive location
- $file = array(
- 'filename' => basename($job->origfile . ".flv"),
- 'filemime' => 'application/octet-stream', // is there something better???
- 'filesize' => filesize($job->convfile),
- 'filepath' => $job->convfile,
- 'nid' => $job->nid,
- );
-
- $file = ((object) $file);
-
- //print_r($file);
- //$dest_dir = variable_get('video_upload_default_path', 'videos') .'/';
- // the above no more works as token supports - use dirname
- $dest_dir = dirname($job->origfile) . '/';
-
- if (file_copy($file, $dest_dir)) {
- //$file->fid = db_next_id('{files}_fid');
- //print_r($file);
- //GMM: fixed added timestamp column for completeness (otherwise 0), D6 FILE_STATUS
- db_query("INSERT INTO {files} (fid, uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, %d, '%s', '%s', '%s', %d, %d, %d)", $file->fid, $job->uid, $file->filename, $file->filepath, $file->filemime, $file->filesize, FILE_STATUS_PERMANENT, time());
-
- // to know other modules of fid
- $file->fid = db_last_insert_id('files', 'fid');
-
- db_query("INSERT INTO {video_upload} (vid, nid, fid) VALUES (%d, %d, %d)", $job->vid, $job->vid, $file->fid);
-
- // update the video table
- db_query('UPDATE {video} SET vidfile = "%s", videox = %d, videoy = %d WHERE nid=%d AND vid=%d', "", $job->calculatedx, $job->calculatedy, $job->nid, $job->vid);
-
- // update the video_encoded_fid in video serial data
- _video_render_set_video_encoded_fid($job->nid, $job->vid, $file->fid);
-
- _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_COMPLETE);
-
- watchdog('video_render', 'successfully converted %orig to %dest', array('%orig' => $job->origfile, '%dest' => $file->filepath));
-
- // delete the temp file
- unlink($job->convfile);
- }
- else {
- // get the username of the process owner
- $ownerarray = posix_getpwuid(posix_getuid());
- $owner=$ownerarray['name'];
- // get the username of the destination folder owner
- $fownerarray = posix_getpwuid(fileowner($dest_dir));
- $fowner=$fownerarray['name'];
- // get destination folder permissions
- $perms = substr(sprintf('%o', fileperms($dest_dir)), -4);
- watchdog('video_render', 'error moving video %vid_file with nid = %nid to %dir the final directory. Check folder permissions.<br />The script was run by %uname .<br />The folder owner is %fowner .<br />The folder permissions are %perms .', array('%vid_file' => $job->origfile, '%nid' => $job->nid, '%dir' => $dest_dir, '%uname' => $owner, '%fowner' => $fowner, '%perms' => $perms), WATCHDOG_ERROR);
-
- _video_render_set_video_encoded_fid($job->nid, $job->vid, -1);
- _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_FAILED);
- }
- }
-}
-
-
-/**
- * Set the video_encoded_fid in the video table
- * We store -1 as video_encoded_fid if the encoding failed
-*/
-function _video_render_set_video_encoded_fid($nid, $vid, $encoded_fid) {
- db_lock_table('video');
- $node = db_fetch_object(db_query("SELECT serialized_data FROM {video} WHERE nid = %d AND vid = %d", $nid, $vid));
- $node->serial_data = unserialize($node->serialized_data);
- //GMM: save fid of previously encoded file
- $old_fid = $node->serial_data['video_encoded_fid'];
- $node->serial_data['video_encoded_fid'] = $encoded_fid;
- $node->serialized_data = serialize($node->serial_data);
- db_query("UPDATE {video} SET serialized_data = '%s' WHERE nid = %d AND vid = %d", $node->serialized_data, $nid, $vid);
- db_unlock_tables();
- // GMM: update status on previously encoded fid to 0 so drupal will delete
- if($old_fid > 0)
- db_query("UPDATE {files} SET status = %d WHERE fid = %d", 0, $old_fid);
-}
-
-
-
-/**
- * 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_cvr_audio_bitrate', 64);
- $videobitrate = variable_get('video_ffmpeg_helper_auto_cvr_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_cvr_options', '-y -i %videofile -f flv -ar 22050 -ab %audiobitrate -s %size -b %videobitrate -qscale 1 %convertfile'));
-
- // set to the converted file output
- $job->convfile = $convfile;
-
- return VIDEO_RENDERING_NICE . " $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_cvr_width', 400);
-
- $height = $def_width * ($job->videoy / $job->videox); // do you remember proportions?? :-)
-
-
- $height = round($height);
- // add one if odd
- if($height % 2) {
- $height++;
- }
-
- $job->calculatedx = $def_width;
- $job->calculatedy = $height;
-
- return $def_width . 'x' . $height;
-}
-
-
-/**
- * Load a job
-*/
-function _video_render_load_job($nid, $vid, $status) {
- $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 AND n.nid = %d AND n.vid = %d', $status, $nid, $vid);
-
- return db_fetch_object($result);
-}
-
-
-/**
- * Change the status to $status of the job having nid=$nid and vid=$vid
-*/
-function _video_render_job_change_status($nid, $vid, $status) {
- $result = db_query('UPDATE {video_rendering} SET status = %d WHERE nid = %d AND vid = %d', $status, $nid, $vid);
-}
-
-?>
diff --git a/plugins/video_ffmpeg_helper/video_scheduler.php b/plugins/video_ffmpeg_helper/video_scheduler.php
deleted file mode 100644
index 1ebbe02..0000000
--- a/plugins/video_ffmpeg_helper/video_scheduler.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-//$Id$
-/**
- * @file
- * Implement video rendering scheduling.
- * If you are not using sites/default/settings.php as your settings file,
- * add an optional parameter for the drupal site url:
- * "php video_scheduler.php http://example.com/" or
- * "php video_scheduler.php http://example.org/drupal/"
- *
- * @author Fabio Varesano <fvaresano at yahoo dot it>
- * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw at gmail dot com>
- * @todo
- */
-
-
-/**
- * video_scheduler.php configuration
-*/
-
-// 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_PENDING', 1);
-define('VIDEO_RENDERING_ACTIVE', 5);
-define('VIDEO_RENDERING_COMPLETE', 10);
-define('VIDEO_RENDERING_FAILED', 20);
-
-if (isset($_SERVER['argv'][1])) {
- $url = parse_url($_SERVER['argv'][1]);
- $_SERVER['SCRIPT_NAME'] = $url['path'];
- $_SERVER['HTTP_HOST'] = $url['host'];
-}
-
-include_once('./includes/bootstrap.inc');
-//module_load_include('/includes/bootstrap.inc', 'video_scheduler', 'includes/bootstrap');
-// 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', 'no video conversion jobs to schedule.', array(), WATCHDOG_DEBUG);
- }
-}
-
-
-/**
- * Starts rendering for a job
-*/
-function video_scheduler_start($job) {
- $url = (isset($_SERVER['argv'][1])) ? escapeshellarg($_SERVER['argv'][1]) : '';
- exec("php video_render.php $job->nid $job->vid $url > /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
-
- // TODO: use db_query_range
- $jobs = array();
- $i = 0;
- $count = db_result(db_query('SELECT COUNT(*) 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));
- while($i < $count && $i < VIDEO_RENDERING_FFMPEG_INSTANCES) {
- $jobs[] = db_fetch_object($result);
- $i++;
- }
-//print_r($jobs);
- return $jobs;
-}
-
-
-
-
-?>
diff --git a/plugins/video_image/video_image.info b/plugins/video_image/video_image.info
deleted file mode 100644
index f158ede..0000000
--- a/plugins/video_image/video_image.info
+++ /dev/null
@@ -1,8 +0,0 @@
-;$Id$
-name = Video Image
-description = Enable thumbnails support for video module.
-dependencies[] = image
-dependencies[] = video
-package = "Video"
-core = 6.x
-
diff --git a/plugins/video_image/video_image.module b/plugins/video_image/video_image.module
deleted file mode 100644
index 8ea5945..0000000
--- a/plugins/video_image/video_image.module
+++ /dev/null
@@ -1,570 +0,0 @@
-<?php
-//$Id$
-/**
- * @file
- * Enable image support for video module.
- *
- * @author Fabio Varesano <fvaresano at yahoo dot it>
- * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw at gmail dot com>
- * @author Glen Marianko Twitter@demoforum <glenm at demoforum dot com>
- * @todo
- * 1. Add jQuery support
- * 2. Add styles to thumbnail
- * 3. Add imagecache support
- * 4. Overlay a play button
- * 5. Capturing video support (To get set of captured thumbnails with time)
- */
-
-
-/**
- * Implementation of hook_help().
- */
-function video_image_help($path, $arg) {
- switch ($path) {
- case 'admin/modules#description':
- return t('Enable thumbnail support for video module.');
- }
-}
-
-/**
- * Implementation of hook_menu()
- */
-function video_image_menu() {
- $items = array();
- $may_cache=true;
- if ($may_cache) {
- $items['admin/settings/video/image'] = array(
- 'title' => 'Video image',
- 'description' => 'Administer video_image module settings',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('video_image_admin_settings'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- }
- return $items;
-}
-
-
-/**
- * Implementation of hook_perm
- */
-//GMM: define positions in perm array to reference later (without misspellings :)
-define('OVERRIDE_IMAGE', 0);
-function video_image_perm() {
- $array = array('override autothumbnailing using uploaded image');
- return $array;
-}
-
-
-/**
- * Settings form
- */
-function video_image_admin_settings() {
- if (module_exists('video_upload') && variable_get('video_image_auto_thumbnail', 0)) {
- $upload_weight = db_result(db_query("SELECT weight FROM {system} WHERE name='video_upload'"));
- db_query("UPDATE {system} SET weight=".($upload_weight+1)." WHERE name='video_image'");
- }
- $form = array();
- $form['video_image_publish_thumbnail'] = array(
- '#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_image_publish_thumbnails(),
- );
- $form['video_image_promote_thumbnail'] = array(
- '#type' => 'checkbox',
- '#title' => t('Promote the thumbnails to the front page'),
- '#default_value' => _video_image_promote_thumbnails(),
- );
- $form['autothumb'] = array(
- '#type' => 'fieldset',
- '#title' => t('Automatic video thumbnailing'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#description' => t('This feature requires the \'video_ffmpeg_helper\' module'),
- );
- $auto_thumb_disable = !module_exists('video_ffmpeg_helper');
- $form['autothumb']['video_image_auto_thumbnail'] = array(
- '#type' => 'checkbox',
- '#title' => t('Auto thumbnail for videos'),
- '#description' => t('If set up correctly, this will auto-generate a thumbnail for each video created.'),
- '#default_value' => variable_get('video_image_auto_thumbnail', false) && !$auto_thumb_disable,
- '#disabled' => $auto_thumb_disable,
- );
- /*
- $form['autothumb']['video_image_auto_thumbnail_only'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use auto-thumbnailer exclusively for video images'),
- '#description' => t('If checked, this will disable the file upload box for the user-supplied thumbnail. Only check this if you have checked to be sure that auto-thumbnailing works. Auto thumbnail must be selected for this to be enabled.'),
- '#default_value' => variable_get('video_image_auto_thumbnail_only', false),
- '#disabled' => !variable_get('video_image_auto_thumbnail', false),
- );
- */
- $form['autothumb']['video_image_auto_thumbnail_debug'] = array(
- '#type' => 'checkbox',
- '#title' => t('Debug automatic thumbnail process'),
- '#default_value' => variable_get('video_image_auto_thumbnail_debug', false),
- '#description' => t('Automatic thumbnailing of videos is dependent on the actual video types. Some video types may not be able to be automatically thumbnailed. Setting this option will allow messages to be show when posting and editing of videos that can be automatically thumbnailed.'),
- '#disabled' => $auto_thumb_disable,
- );
-
-
- return system_settings_form($form);
-}
-
-function video_image_admin_settings_validate($form, &$form_state) {
- if (module_exists('video_ffmpeg_helper')) {
- if ($form_state['values']['video_image_auto_thumbnail']) {
- $path_ok = _video_ffmpeg_helper_check_exe_path();
- if (!$path_ok) {
- drupal_set_message(t('The path for \'ffmpeg\' is not valid. Please check settings on the !ffmpeg_settings_page', array('!ffmpeg_settings_page' => l(t('Video ffmpeg helper settings page'), 'admin/settings/video/ffmpeg_helper'))), 'error');
- }
- }
- }
-}
-
-
-/**
- * Return true if the video support authothumbnailing
-*/
-function video_image_is_autothumbable($node) {
- $info = video_get_type_info($node->vtype);
- $has_hook = module_hook('video_' . $node->vtype, 'v_auto_thumbnail');
- return $has_hook && isset($info[$node->vtype]['#autothumbable']) && $info[$node->vtype]['#autothumbable'];
-}
-
-
-/**
- * Implementation of hook_form_alter()
- */
-function video_image_form_alter(&$form, &$form_state, $form_id) {
-
- if($form_id == 'video_node_form') {
-
- $node = $form['#node'];
- $value = ($node->new_image) ? '#value' : '#default_value';
- $form['iid'] = array('#type' => 'hidden', $value => $node->iid);
-
- if (!is_array($node->tempimage['fids'])) {
- $fids = array('_original' => 0);
- foreach (_image_get_sizes() as $size) {
- $fids[$size['label']] = 0;
- }
- $node->tempimage['fids'] = $fids;
- }
- $form['tempimage']['#tree'] = true;
- foreach ($node->tempimage['fids'] as $label => $fid) {
- $form['tempimage']['fids'][$label] = array('#type' => 'hidden', $value => $fid);
- }
-
- $auto_thumbable = video_image_is_autothumbable($node);
- //GMM: fix permission misspelling
- $perm=video_image_perm();
- if(!$auto_thumbable || user_access($perm[OVERRIDE_IMAGE])) { // let's be sure that image directories are ready
- if (function_exists('_image_check_settings')) {
- _image_check_settings();
- }
- // needed for uploading
- $form['#attributes'] = array("enctype" => "multipart/form-data");
-
-
- $form['image'] = array('#type' => 'fieldset', '#title' => t('Image thumbnails'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => -17, '#description' => t('Upload an image to be used as the thumbnail for this video.'));
-
- $form['image']['image'] = array('#type' => 'file', '#title' => t('Image'));
- }
- if ($node->nid && $auto_thumbable) {
- $form['regenerate_thumbnail'] = array('#type' => 'checkbox', '#title' => t('Auto regenerate thumbnail'), '#default_value' => 0);
- }
- }
-}
-
-
-/**
- * Implementation of hook_nodeapi()
- */
-function video_image_nodeapi(&$node, $op, $teaser) {
- //print_r($op);
- //exit;
- if($node->type == 'video') {
- switch ($op) {
- case 'load':
- //exit;
- return _video_image_load($node);
-
- case 'prepare':
- //exit;
- _video_image_prepare($node);
- break;
-
- case 'presave':
- //exit;
- _video_image_submit($node);
- break;
-
- case 'view':
- //exit;
- _video_image_view($node, $teaser);
- break;
- case 'delete':
- //exit;
- _video_image_delete($node);
- break;
- }
- }
-}
-
-
-/**
- * Renders thumbnail node with a link to the video node to be used on video teasers.
- *
- * @param $image
- * object with image node information
- * @param $video
- * the video node associated with image
- *
- * @return
- * string of content to display
- */
-function theme_video_image_teaser($image, $video) {
-
- $image_html = NULL;
-
- if($image != NULL && $image->type == 'image') {
- $image_html = image_display($image, 'thumbnail', array('class' => 'video_image_teaser'));
- }
- else if($image_node == NULL && $video->serial_data['image_teaser']){ // only for backward compatibility
- $image_html = theme('image', $video->serial_data['image_teaser'], $video->title, $video->title, array('class' => 'video_image_teaser'), FALSE);
- }
-
- if($image) {
- //Create a link with an image in it.
- $output .= l($image_html, "node/$video->nid", array('html' => TRUE));
- $output .= '<br class="video_image_clear" />';
- }
- return $output;
-}
-
-
-/* nodeapi split out hooks */
-function _video_image_load(&$node) {
- $output['iid'] = $node->serial_data['iid'];
- return $output;
-}
-
-function _video_image_prepare(&$node) {
- // let's check that we have a valid image
- //print_r($node);
- //exit;
- if (count($_POST)) {
-
- $validators = array(
- 'file_validate_is_image' => array()
- );
-
- $field_name = file_save_upload('image', $validators);
- if (!$field_name && video_image_is_autothumbable($node)) {
- _video_image_thumbnail_debug(t('video_image_nodeapi: prepare: ready to thumbnail video'));
- $field_name = module_invoke('video_' . $node->vtype, 'v_auto_thumbnail', $node);
- if ($field_name === false && count($_POST)) {
- drupal_set_message(t('The thumbnailing process of your video failed for some reason. Video thumbnail will not be available.'), 'error');
- }
- }
- }
- if ($field_name) {
- $node->tempimage = _video_image_temp_image_store($field_name);
- $node->new_image = TRUE;
- } else if (is_array($_POST['tempimage']) &&
- ($_POST['op'] == 'Preview' || $_POST['op'] == 'Submit')) {
- $node->tempimage = (array)_video_image_temp_image_load(array_values($_POST['tempimage']['fids']));
- }
-}
-
-function _video_image_submit(&$node) {
- //print_r($node);
- //exit;
- // ############# PREPARE #######################
- // ------------- MOVED -------------------------
- if (count($_POST)) {
-
- $validators = array(
- 'file_validate_is_image' => array()
- );
-
- $field_name = file_save_upload('image', $validators);
- if (!$field_name && video_image_is_autothumbable($node)) {
- _video_image_thumbnail_debug(t('video_image_nodeapi: prepare: ready to thumbnail video'));
- $field_name = module_invoke('video_' . $node->vtype, 'v_auto_thumbnail', $node);
- if ($field_name === false && count($_POST)) {
- drupal_set_message(t('The thumbnailing process of your video failed for some reason. Video thumbnail will not be available.'), 'error');
- }
- }
- }
-
- if ($field_name) {
- /*
- if($node->iid){
-
- // Remove all the existing images.
- $result = db_query("SELECT f.fid, f.filepath FROM {image} i INNER JOIN {files} f ON i.fid = f.fid WHERE i.nid = %d", $node->iid);
- while ($file = db_fetch_object($result)) {
- file_delete(file_create_path($file->filepath));
- db_query("DELETE FROM {files} WHERE fid = %d", $file->fid);
- }
- //db_query("DELETE FROM {image} WHERE nid = %d", $node->iid);
- }
- *
- */
- $node->tempimage = _video_image_temp_image_store($field_name);
- $node->new_image = TRUE;
- //print_r($node);
- //die;
- } else if (is_array($_POST['tempimage']) && ($_POST['op'] == 'Preview' || $_POST['op'] == 'Submit')) {
- //print_r($node);
- //exit;
- $node->tempimage = (array)_video_image_temp_image_load(array_values($_POST['tempimage']['fids']));
- }
-
- // ###########################################################################
-
-
- if ($node->regenerate_thumbnail) {
- _video_image_regenerate_thumbnail($node);
- }
- if (is_array($node->tempimage['fids']) && $node->tempimage['fids']['_original']) {
- $image = _video_image_temp_image_load(array_values($node->tempimage['fids']));
- //print_r($image);
- //exit;
-
- //GMM: This DELETE query causes the uploaded video file to disappear
- // especially when using ffmpeg to convert the video - no need to kill the
- // tempimage, since its status is 0 in {files} Drupal cron will nix it
- //db_query("DELETE FROM {files} WHERE fid in (%s)",
- // implode(',', array_values($node->tempimage['fids'])));
-
- // initialize standard node fields
- //print_r($image);
- //exit;
- $image->uid = $node->uid;
- $image->created = time();
- $image->title = t('Video thumbnail for !title', array('!title' => $node->title));
- $image = node_submit($image);
- $image->uid = $node->uid;
- $image->status = _video_image_publish_thumbnails();
- $image->promote = _video_image_promote_thumbnails();
- // This is a messages hack (we don't want to see what happens under the covers)
- _video_image_pause_messages(true);
- if ($node->iid) {
-
- $oldimage = node_load($node->iid);
- $oldimage->images = $image->images;
-
- // delete the old images?
- //GMM: Fix to use the proper variable to trigger current Image module to rebuild derivative images
- // Tested against Image 6.x-1.0-aplha4
- // $oldimage->new_image = 1;
- $oldimage->new_file = true;
- node_save($oldimage);
- $node->iid = $oldimage->nid;
- $node->serial_data['iid'] = $node->iid;
- } else {
- node_save($image);
-
- //print_r($image);
- //exit;
- //image_insert($image);
- $node->iid = $image->nid;
- // store the iid into the serial_data
- $node->serial_data['iid'] = $node->iid;
- //print_r($node);
- //die;
- // needed to set the correct status and promote values even if the user does not have enough permissions. Is there a better solution???
- // db_query('UPDATE {node} SET status = %d, promote = %d WHERE nid = %d AND vid = %d', _video_image_publish_thumbnails(), _video_image_promote_thumbnails(), $image->nid, $image->vid);
- }
- _video_image_pause_messages();
- }
- else {
- $node->serial_data['iid'] = $node->iid;
- }
-}
-
-function _video_image_view(&$node, $teaser) {
- if (is_array($node->tempimage['fids']) && $node->tempimage['fids']['_original']) {
- $image = _video_image_temp_image_load(array_values($node->tempimage['fids']));
- } else if ($node->iid) {
- $image = node_load($node->iid);
- } else {
- $image = NULL; // this is for backward compatibility
- }
-
- if($teaser) {
- $node->content['video_image_thumbnail'] = array('#value' => theme('video_image_teaser', $image, $node));
- }
-}
-
-function _video_image_regenerate_thumbnail(&$node) {
- $field_name = module_invoke('video_' . $node->vtype, 'v_auto_thumbnail', $node);
- if ($field_name) {
- $node->tempimage = _video_image_temp_image_store($field_name);
- $node->new_image = TRUE;
- }
-}
-
-function _video_image_delete(&$node) {
- _video_image_pause_messages(true);
- node_delete(array('nid' => $node->iid));
- _video_image_pause_messages();
-}
-
-/* At times, when doing sub-node processing (creating/deleting thumbnail nodes)
- * we don't really want to show all the messages through to the end user or it
- * gets a little bit confusing (image created messages when creating a video)
- * so we suppress the messages with this procedure.
- */
-function _video_image_pause_messages($snapshot = false) {
- static $messages = null;
- if ($snapshot) {
- $messages = drupal_get_messages();
- } else if (is_array($messages)) {
- $_SESSION['messages'] = $messages;
- $messages = null;
- }
-}
-
-/* debugging framework for troublesome thumbnailing */
-function _video_image_thumbnail_debug($msg) {
- static $debug = NULL;
- if ($debug == NULL) {
- $debug = variable_get('video_image_auto_thumbnail_debug', false);
- }
- if ($debug) {
- $t = debug_backtrace();
- $l = array_shift($t);
- drupal_set_message(basename($l['file'], '.module').': '.$msg);
- }
-}
-
-function _video_image_temp_image_store(&$file) {
- $image = new stdClass();
- $image->images[IMAGE_ORIGINAL] = $file->filepath;
- $image->images =_image_build_derivatives($image);
- $image->type = 'image';
- $image->uid = 1;
- $image->created = time();
- $image->title = t('video image thumbnail');
- // We're good to go.
-
- $image->rebuild_images = FALSE;
- $image->new_file = TRUE;
-
-
- //print_r($image);
- //exit;
- if ($image->images) {
- node_validate($image);
- if (!form_get_errors()) {
- // save the images in the files table
- foreach ($image->images as $l => $f) {
- $info = image_get_info($f);
- $file->fid = db_last_insert_id('files','fid');
- if($l=="_original"){
- db_query("INSERT INTO {files} (fid, filename, filepath, filemime, filesize) VALUES (%d, '%s', '%s', '%s', '%s')",
- $fid, "video_image_temp.$l", $f, $info['mime_type'], $info['file_size']);
- }
- $image->fids[$l] = $file->fid;
- }
- }
- }
- //print_r($image);
- //exit;
- return (array)$image;
-}
-
-/* Create a fake node object that acts like an image node
- * by looking up each file in the array $fids and loading
- * them into the images array.
- */
-function _video_image_temp_image_load($fids) {
- $image = new stdClass();
- $image->type = 'image';
- $image->new_file = 1;
- $fids = implode(',', $fids);
- $results = db_query("SELECT fid, filename, filepath FROM {files} WHERE fid IN (%s)", $fids);
- while ($file = db_fetch_object($results)) {
- $label = substr($file->filename, 17);
- $image->images[$label] = $file->filepath;
- $image->fids[$label] = $file->fid;
- }
- return $image;
-}
-
-/* If the user has set a promote preference, use that, otherwise return
- * if 'promote' is set in the drupal content type settings
- *
- * @return
- * Returns whether we should promote thumbnails or not
- */
-function _video_image_promote_thumbnails() {
- $settings_override = variable_get('video_image_promote_thumbnail', NULL);
- if ($settings_override === NULL) {
- //GMM: Don't default to "promote" if no video or Image option specified
- //confusing to n00bs seeing two nodes promoted for every video node
- $node_options = variable_get('node_options_image', array());
- return in_array('promote', $node_options);
- }
- return $settings_override;
-}
-
-/* If the user has set a publish preference, use that, otherwise return
- * if 'status' is set in the drupal content type settings
- *
- * @return
- * Returns whether we should publish thumbnails or not
- */
-function _video_image_publish_thumbnails() {
- $settings_override = variable_get('video_image_publish_thumbnail', NULL);
- if ($settings_override === NULL) {
- $node_options = variable_get('node_options_image', array('status', 'promote'));
- return in_array('status', $node_options);
- }
- return $settings_override;
-}
-
-
-/**
- * Create an image file object from a given image url
-*/
-function _video_image_get_thumb_file_object($thumbnail_url, $id) {
-
- if($thumbnail_url && $thumbnail_url != '' && $image = image_gd_open($thumbnail_url, 'jpeg')) {
- // save image to temp directory for processing
- $location = file_directory_temp() .'/'. $id .'.jpg';
- image_gd_close($image, $location, 'jpeg');
-
-
- // get info and build a file object
- $filepath = file_create_path($location, file_directory_temp());
- $info = image_get_info($filepath);
-
- $file = new stdClass();
- $file->filepath = realpath($filepath);
- $file->filename = basename($file->filepath);
- $file->filesize = $info['file_size'];
- $file->filemime = $info['mime_type'];
-
- return $file;
- }
-
- return null;
-}
-
-/**
- * Implementation of hook_theme().
- */
-function video_image_theme() {
- return array(
- 'video_image_teaser' => array(
- 'arguments' => array('image' => NULL,'video' => NULL),
- ),
- );
-}
diff --git a/plugins/video_multidownload/video_multidownload.info b/plugins/video_multidownload/video_multidownload.info
deleted file mode 100644
index 5c87e9c..0000000
--- a/plugins/video_multidownload/video_multidownload.info
+++ /dev/null
@@ -1,6 +0,0 @@
-;$Id$
-name = Video Multidownload
-description = Enable multiple file download in video module.
-dependencies[] = video
-package = "Video"
-core = 6.x
diff --git a/plugins/video_multidownload/video_multidownload.module b/plugins/video_multidownload/video_multidownload.module
deleted file mode 100644
index 5cce13b..0000000
--- a/plugins/video_multidownload/video_multidownload.module
+++ /dev/null
@@ -1,393 +0,0 @@
-<?php
-//$Id$
-/**
- * @file
- * Enable multiple file download in video module.
- *
- * @author Fabio Varesano <fvaresano at yahoo dot it>
- * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw at gmail dot com>
- * @todo
- */
-
-
-/**
- * Implementation of hook_help().
- */
-function video_multidownload_help($path, $arg) {
- switch ($path) {
- case 'admin/modules#description':
- return t('Enable multiple file download in video module.');
- }
-}
-
-
-/**
- * Implementation of hook_menu().
- *
- * @param $may_cache
- * boolean indicating whether cacheable menu items should be returned
- *
- * @return
- * array of menu information
- */
-function video_multidownload_menu() {
- $items = array();
-/* TODO
- Non menu code that was placed in hook_menu under the '!$may_cache' block
- so that it could be run during initialization, should now be moved to hook_init.
- Previously we called hook_init twice, once early in the bootstrap process, second
- just after the bootstrap has finished. The first instance is now called boot
- instead of init.
-
- In Drupal 6, there are now two hooks that can be used by modules to execute code
- at the beginning of a page request. hook_boot() replaces hook_boot() in Drupal 5
- and runs on each page request, even for cached pages. hook_boot() now only runs
- for non-cached pages and thus can be used for code that was previously placed in
- hook_menu() with $may_cache = FALSE:
-
- Dynamic menu items under a '!$may_cache' block can often be simplified
- to remove references to arg(n) and use of '%<function-name>' to check
- conditions. See http://drupal.org/node/103114.
-
- The title and description arguments should not have strings wrapped in t(),
- because translation of these happen in a later stage in the menu system.
-*/
- $may_cache=true;
- if ($may_cache) {
- $items['admin/content/video/multidownload'] = array(
- 'title' => 'Multidownload',
- 'description' => 'Administer video_multidownload module settings',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('video_multidownload_settings_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- }
- else {
- if (arg(0) == 'node' && is_numeric(arg(1))) {
- if ($node = node_load(arg(1)) and $node->type == 'video') {
- if(isset($node->disable_multidownload) &&
- !$node->disable_multidownload &&
- ($node->use_play_folder || $node->download_folder!='')
- ) {
- $items['node/'.'%'.'/multidownload'] = array(
- 'title' => 'download other formats',
- 'page callback' => 'video_multidownload_download',
- 'access arguments' => array('access video'),
- 'weight' => 7,
- 'type' => MENU_LOCAL_TASK);
- }
- }
- }
- }
- return $items;
-}
-
-
-/**
- * Implementation of hook_perm().
- */
-function video_multidownload_perm() {
- return array('create multi-file downloads');
-}
-
-
-/**
- * Implementation of hook_settings()
- */
-function video_multidownload_settings_form() {
- $form = array();
-
- $options = array(1 => 'Yes', 0 => 'No');
-
- $form['multifile'] = array('#type' => 'fieldset', '#title' => t('Multi-file download options'), '#description' => t('Allows a list of files to be shown on the download page. The list is usually gotten from a specified folder. This ability is useful for providing different sizes and video types for download.'));
- $form['multifile']['video_multidownload'] = array(
- '#type' => 'radios',
- '#title' => t('Allow Multi-file Downloads'),
- '#options' => $options,
- '#default_value' => variable_get('video_multidownload', 0),
- '#description' => t('This feature can be disabled separately for each node. If turned on make sure you set the permissions so users can use this feature.') . ' ' . l(t('access control'), 'admin/access'));
- $form['multifile']['video_download_ext'] = array(
- '#type' => 'textfield',
- '#title' => t('File extensions to show'),
- '#default_value' => variable_get('video_download_ext', 'mov,wmv,rm,flv,avi,divx,mpg,mpeg,mp4,zip'),
- '#description' => t('The extensions of files to list from the multi-file download folder on the download page. Extensions should be comma seperated with no spaces, for example (mov,wmv,rm).'));
-
- return system_settings_form($form);
-}
-
-
-/**
- * Implementation of hook_form_alter()
- * We use this to add multidownload fields to the video creation form.
- */
-function video_multidownload_form_alter(&$form, &$form_state, $form_id) {
-
- if ($form_id == 'video_node_form' && isset($form['video']) && user_access('create multi-file downloads')) {
-
- $node = $form['#node'];
-
- $form['multi-file'] = array(
- '#type' => 'fieldset',
- '#title' => t('Multiple files in download tab'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#weight' => -18,
- '#description' => t('These options allow you to have multiple files shown on the download page. This is useful for allowing users to download different file sizes and video formats. ') . l(t('More information.'), 'video/help', array('fragment' => 'multi-download'))
- );
- $form['multi-file']['disable_multidownload'] = array(
- '#type' => 'checkbox',
- '#title' => t('Disable multi-file downloads'),
- '#default_value' => isset($node->disable_multidownload) ? $node->disable_multidownload : 1,
- '#description' => t('Disables multi-file downloads for this video only.')
- );
- $form['multi-file']['download_folder'] = array(
- '#type' => 'textfield',
- '#title' => t('Multi-file download folder'),
- '#default_value' => $node->download_folder,
- '#maxlength' => 250,
- '#description' => t('Enter the folder containing your videos. It must be relative from the drupal directory. If the absolute path is "C:\inetpub\drupal\videos\projectfolder\" or "/usr/htdocs/drupal/videos/projectfolder/" then enter something like "videos/projectfolder/".'));
- $form['multi-file']['use_play_folder'] = array(
- '#type' => 'checkbox',
- '#title' => t('Show files in "play" folder'),
- '#default_value' => $node->use_play_folder,
- '#description' => t('Display videos in the same directory as the "play" video. If folder above is entered this will be in addition.'));
- }
-}
-
-
-/**
- * Implementation of hook_nodeapi()
- */
-function video_multidownload_nodeapi(&$node, $op, $teaser) {
- if($node->type == 'video') {
- switch ($op) {
-
- case 'validate':
- //Validate multi-file download values.
- if (user_access('create multi-file downloads')) { //Make sure the user has permission.
- //Checks to make sure either multi-downloads are disabled, or a valid folder is given, or use_play_folder is checked.
- if ($node->disable_multidownload == 0 and !is_dir(getcwd() . '/' . $node->download_folder) and $node->use_play_folder == 0) {
- form_set_error('disable_multidownload', t("Please disable multi-file downloads if you are not going to use the feature."));
- form_set_error('download_folder', t('Download directory does not exist. Make sure it has a trailing forward slash "/".'));
- }
- }
- break;
- }
- }
-}
-
-
-
-function video_multidownload_download() {
- if ($node = node_load(arg(1))) {
- if (variable_get("video_multidownload", 0) == 0 or $node->disable_multidownload == 1) {
-
- }
- else if (arg(3) != '') { //If we are passed an encoded URL redirect to the downloader.
- _video_multidownload_download_goto(arg(3), $node->vid, TRUE);
- }
- else { //Multiple file downloads is turned on.
- $download_error = FALSE; //Initialize and clear the error flag.
- $node->file_array = array(); //Initialize the final file array.
- global $base_url;
- $full_download_folder = getcwd() . '/' . $node->download_folder; //Get absolute path to folder.
- //If the download folder is set and valid scan it for files.
- if ($node->download_folder != '' and file_exists($full_download_folder)) {
- $scan_download_folder = _video_multidownload_scandir($full_download_folder); //Get array of file names in the directory.
- $scan_download_folder['local_dir'] = $full_download_folder; //For getting filesize.
- $scan_download_folder['dir_stub'] = $node->download_folder; //To put in the URL.
- $folder_array[] = $scan_download_folder;
-
- }
- //If option is set to use "play" folder and it exists, scan it for files.
- $play_dir_stub = str_replace(basename($node->vidfile), "", $node->vidfile); //Remove the filename from the play file to get directory.
- $play_dir = getcwd() . '/' . $play_dir_stub; //Get the local directory path where the file is kept.
- if ($node->use_play_folder == 1 and file_exists($play_dir) and $play_dir_stub != '/') { //Make sure play stub won't allow scanning base drupal directory.
- $scan_play_folder = _video_multidownload_scandir($play_dir);
- $scan_play_folder['local_dir'] = $play_dir; //For getting filesize.
- $scan_play_folder['dir_stub'] = $play_dir_stub; //To put in the URL.
- $folder_array[] = $scan_play_folder;
- }
-
- if (count($folder_array) > 0) { //Make sure we have a folder to scan.
- foreach ($folder_array as $dir_scan) { //Scan through one or both folders results.
- foreach ($dir_scan as $file) { //Go through each file in the directory.
- if (is_file($dir_scan['local_dir'] . "/" . $file)) { //Make sure it's a valid file.
- //Checks the new file with the files already in the array to eliminate dupes.
- $match = false;
- foreach ($node->file_array as $file_array_file) {
- if ($file_array_file['file'] == $file) { //If the file is already in the array.
- $match = TRUE;
- }
- } //If we get here with $match still set FALSE we don't have a dupe.
-
- $file_ext = substr($file, strrpos($file, '.') + 1); //Get the file extension.
- $ext_array = explode(',', variable_get('video_download_ext', 'mov,wmv,avi'));
-
- if (!$match and in_array($file_ext, $ext_array)) { //Only add file if it's not already in the array and it's extension shouldn't be hidden.
- $file_array_size[] = filesize($dir_scan['local_dir'] . $file); //Create an array of the file sizes for sorting.
-
- global $base_url;
- $file_url = $base_url . '/' . $dir_scan['dir_stub'] . $file; //Generate absolute URL to video.
- $file_url = str_replace(' ', '%20', $file_url); //Replace any spaces in filename.
- $encoded_url = base64_encode($file_url); //Encode URL to base64 MIME value so it can be passed in URL.
- $encoded_url = str_replace('/', '-', $encoded_url); //Replace "/" with "-" so it doesn't mess up the URL.
-
- $node->file_array[] = array( 'file' => $file
- , 'type' => $file_ext
- , 'size' => filesize($dir_scan['local_dir'] . $file)
- , 'encoded_url' => $encoded_url
- );
- }
- } //Close the valid file check.
- } //Close the directory scan.
- } //Close scan location array.
-
- if (count($node->file_array) > 0) { //Make sure atleast 1 file was found.
- array_multisort($file_array_size, SORT_ASC, $node->file_array); //Sort based of file size.
-
- }
- else { //Else if no files were found in the directory.
- $download_error = TRUE;
- }
- }
- else { //Else if we have no valid folders to scan.
- $download_error = TRUE;
- }
-
- //If there was no error send the files array to the theme function for display.
- if($download_error == FALSE) {
- print theme('video_multidownload_download', $node); //Print to the screen from the theme_video_download function.
- }
- else { //Else if there is an error download the play file.
- _video_download_goto($node->vidfile, $node->vid);
- }
-
- } //Close multi-file downloads is turned on.
- }
-}
-
-
-/**
- * Outputs the HTML for the download page when multi-file download are turned on.
- *
- * @param $node
- * object with node information
- *
- * @return
- * string of content to display
- */
-function theme_video_multidownload_download($node) {
- $output = '';
- //Replace some common file types with full name and links.
- $find = array('mov', 'wmv', 'rm', 'avi', 'zip', 'divx', 'flv', 'ogg');
- $replace = array('<a href="http://www.apple.com/quicktime" title="'. t('QuickTime Homepage') . '">' . t('Quicktime') . '</a>'
- , '<a href="http://www.microsoft.com/windowsmedia" title="'. t('Windows Media Homepage') . '">' . t('Windows Media') . '</a>'
- , '<a href="http://www.real.com" title="'. t('Real Media Homepage') . '">' . t('Real Media') . '</a>'
- , '<a href="http://en.wikipedia.org/wiki/AVI" title="'. t('AVI Information at wikipedia.org') . '">' . t('AVI') . '</a>'
- , '<a href="http://en.wikipedia.org/wiki/ZIP_file_format" title="'. t('ZIP Information at wikipedia.org') . '">' . t('ZIP') . '</a>'
- , '<a href="http://www.divx.com" title="'. t('Divx Homepage') . '">' . t('DIVX') . '</a>'
- , '<a href="http://www.macromedia.com/go/getflashplayer" title="'. t('Macromedia Flash Homepage') . '">' .t('Flash FLV') . '</a>'
- , '<a href="http://www.theora.org/theorafaq.html" title="'. t('Ogg Theora FAQ at theora.org') . '">'.t('Ogg Theora FAQ') .'</a>, <a href="http://en.wikipedia.org/wiki/Wikipedia:Media_help_(Ogg)" title="'. t('Ogg Theora media help at Wikipedia') . '">' . t('Ogg Theora help') . '</a>'
- );
- $output .= '<br /><div class="videodownload">'; //Enclose all HTML in "videodownload" class.
- foreach($node->file_array as $file) { //Goes through the array of video files and gets them ready for display.
- $file_type = str_replace($find, $replace, $file['type']); //Match and replace common file types.
- $link = l($file['file'], "node/$node->nid/multidownload/" . $file['encoded_url']); //Create link to download file.
- $file_array_table[] = array($link, format_size($file['size']), $file_type); //Create table row.
- }
- $headers = array(t('File Link'), t('File Size'), t('File Type'));
- $output .= theme_table($headers, $file_array_table); //Create the table of files.
- $output .= '</div>'; //Close the "videodownload" class.
-
- //Adds a breadcrumb back to view on the download page. This may not be needed but some better breadcrumbs are.
- $breadcrumb = drupal_get_breadcrumb();
- $breadcrumb[] = l(t('View'), "node/$node->nid");
- drupal_set_breadcrumb($breadcrumb);
-
- drupal_set_title(t('Downloading').' '. theme('placeholder', $node->title));
- return theme("page", $output);
-}
-
-
-
-/**
- * Scans a directory and returns an array of all the filenames in the directory.
- * This function is only necessary to maintain PHP 4 support.
- *
- * @param $dir
- * The directory. Can be an absolute path or relative from the current working directory.
- *
- * @return
- * array of filenames.
- */
-function _video_multidownload_scandir($dir) {
- //Try a few different ways to open the directory.
- if (is_dir($dir)) {
- $dir_open = opendir($dir);
- }
- else if (is_dir($new_dir = getcwd() . $dir)) {
- $dir_open = opendir($new_dir);
- }
- else if (is_dir($new_dir = getcwd() . '/' . $dir)) {
- $dir_open = opendir($new_dir);
- }
- else { //If directory does not exist.
- return FALSE;
- }
- if (!$dir_open) { //If opendir returned false then return false.
- return FALSE;
- }
- //If it makes it this far $dir_open should be valid.
- while (($dir_content = readdir($dir_open)) !== FALSE) {
- $files[] = $dir_content;
- }
- return $files;
-}
-
-
-/**
- * Forward user directly to the file for downloading
- *
- * @param $input_url
- * string should be either a base64 encoded absolute URL, relative URL, or absolute URL.
- *
- * @param $vid
- * integer node version ID of the node to have it's download counter updated.
- *
- * @param $base64_encoded
- * boolean value determines whether the $input is base64 encoded.
- *
- * @return
- * Nothing
- */
-function _video_multidownload_download_goto($input_url, $vid, $base64_encoded) {
- if (user_access('download video') && $base64_encoded) {
-
- $encoded_url = str_replace('-', '/', $input_url); //Replace "-" to "/" for MIME base64.
- $location = base64_decode($encoded_url);
-
- if (variable_get('video_downloadcounter', 1)) {
- db_query("UPDATE {video} SET download_counter = download_counter + 1 where vid = '%d'", $vid); //Increment download counter.
- }
-
- header("Location: $location"); //Redirect to the video files URL.
- }
- else { //If the user does not have access to download videos.
- drupal_set_message(t('You do not have permission to download videos.'), 'error');
- $node = node_load(array('vid' => $vid)); //Load a node with the $vid so we can get the nid.
- drupal_goto("node/$node->nid"); //Use the nid we just loaded to go back to the node page.
- }
-}
-
-/**
- * Implementation of hook_theme().
- */
-function video_multidownload_theme() {
- return array(
- 'video_multidownload_download' => array(
- 'arguments' => array('node' => NULL),
- ),
- );
-}
diff --git a/plugins/video_optmetadata/video_optmetadata.info b/plugins/video_optmetadata/video_optmetadata.info
deleted file mode 100644
index 7d6bf7f..0000000
--- a/plugins/video_optmetadata/video_optmetadata.info
+++ /dev/null
@@ -1,7 +0,0 @@
-;$Id$
-name = Video Opt Metadata
-description = Enable addition of optional metadata on video nodes created by video module. Optional metadata are Video Bitrate, Audio Bitrate, Audio Sampling Rate and Audio Channels.
-dependencies[] = video
-package = "Video"
-core = 6.x
-
diff --git a/plugins/video_optmetadata/video_optmetadata.module b/plugins/video_optmetadata/video_optmetadata.module
deleted file mode 100644
index 1bf1d69..0000000
--- a/plugins/video_optmetadata/video_optmetadata.module
+++ /dev/null
@@ -1,146 +0,0 @@
-<?php
-//$Id$
-/**
- * @file
- * Enable addition of optional metadata on video nodes created by video module.
- *
- * @author Fabio Varesano <fvaresano at yahoo dot it>
- * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw at gmail dot com>
- * @todo
- */
-
-
-/**
- * Implementation of hook_help().
- */
-function video_optmetadata_help($path, $arg) {
- switch ($path) {
- case 'admin/modules#description':
- return t('Enable addition of optional metadata on video nodes created by video module. Optional metadata are Video Bitrate, Audio Bitrate, Audio Sampling Rate and Audio Channels.');
- }
-}
-
-
-/**
- * Implementation of hook_perm().
- */
-function video_optmetadata_perm() {
- return array('insert optional metadata');
-}
-
-
-
-/**
- * Implementation of hook_form_alter()
- * We use this to add some fields to the video creation form.
- * In those fields users will be able to insert some video metadatas.
- */
-function video_optmetadata_form_alter(&$form, &$form_state, $form_id) {
-
- if($form_id == 'video_node_form' && isset($form['video']) && user_access('insert optional metadata')) {
-
- // get node object
- $node = $form['#node'];
- // Optional Video Metadata. We display this group expanded only if displaying of optional metadata is enabled.
- $form['metadata'] = array(
- '#type' => 'fieldset',
- '#title' => t('Optional Metadata'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#weight' => -16,
- '#description' => t('Insert here the metadata informations.')
- );
- $form['metadata']['video_bitrate'] = array(
- '#type' => 'textfield',
- '#title' => t('Video Bitrate'),
- '#length' => 11,
- '#maxlength' => 11,
- '#default_value' => $node->video_bitrate,
- '#description' => t('Video bitrate in kbits/sec.')
- );
- $form['metadata']['audio_bitrate'] = array(
- '#type' => 'textfield',
- '#title' => t('Audio Bitrate'),
- '#length' => 11,
- '#maxlength' => 11,
- '#default_value' => $node->audio_bitrate,
- '#description' => t('Audio bitrate in kbits/sec.')
- );
- $form['metadata']['audio_sampling_rate'] = array(
- '#type' => 'select',
- '#title' => t('Audio Sampling Rate'),
- '#options' => array(0 => 'none', 8000 => '8 kHz', 11025 => '11 kHz', 16000 => '16 kHz', 22050 => '22 kHz', 32000 => '32 kHz', 44100 => '44.1 kHz', 48000 => '48 kHz', 96000 => '96 kHz', 192400 => '192 kHz'),
- '#default_value' => $node->audio_sampling_rate,
- '#description' => t('Integer value of audio sampling rate in Hz.')
- );
- $form['metadata']['audio_channels'] = array(
- '#type' => 'select',
- '#title' => t('Audio Channels'),
- '#options' => array('' => 'none', '5.1' => t('5.1'), 'stereo' => t('Stereo'), 'mono' => t('Mono')),
- '#default_value' => $node->audio_channels
- );
- // Ends Video Optional Metadata
- }
-}
-
-
-/**
- * Implementation of hook_nodeapi()
- */
-function video_optmetadata_nodeapi(&$node, $op, $teaser) {
- if($node->type == 'video') {
- switch ($op) {
- case 'view':
- //Add the HTML formatted output of the optional video metadata to the bottom.
- $node->body .= theme('video_metadata', $node);
- break;
- }
- }
-}
-
-/**
- * Display optional metadata (Video and Audio bitrate,..) on the view page.
- *
- * @param $node
- * object with node information
- *
- * @return
- * string of content to display
- $node->video_bitrate, $node->audio_bitrate, $node->audio_sampling_rate, $node->audio_channels,
- */
-function theme_video_metadata($node) {
- //Make sure atleast one fields had data.
- if ($node->video_bitrate != 0 or $node->audio_bitrate != 0 or $node->audio_sampling_rate != 0 or $node->audio_channels != 0) {
- $output = "\n\n<div class=\"video_metadata\">\n";
- $output .= ' <div class="title"><h2>'.t('Video Metadata')."</h2></div>\n";
- if($node->video_bitrate != 0) {
- $fields[] = array('title' => t('Video Bitrate') . ':', 'body' => $node->video_bitrate . ' ' . t('kbits/sec'));
- }
- if($node->audio_bitrate != 0) {
- $fields[] = array('title' => t('Audio Bitrate') . ':', 'body' => $node->audio_bitrate . ' ' . t('kbits/sec'));
- }
- if($node->audio_sampling_rate != 0) {
- $fields[] = array('title' => t('Audio Sampling Rate') . ':', 'body' => $node->audio_sampling_rate . ' ' . t('Hz'));
- }
- if($node->audio_channels != '') {
- $fields[] = array('title' => t('Audio Channels') . ':', 'body' => $node->audio_channels);
- }
- $output .= theme('video_fields', $fields); //Generate the fields HTML.
- $output .= '</div>'; //Closing div video_metadata
- }
- else { //If all the fields are blank then display nothing.
- $output = '';
- }
- return $output;
-}
-
-/**
- * Implementation of hook_theme().
- */
-function video_optmetadata_theme() {
- return array(
- 'video_metadata' => array(
- 'arguments' => array('node' => NULL),
- ),
- );
-} \ No newline at end of file
diff --git a/plugins/video_params/video_params.info b/plugins/video_params/video_params.info
deleted file mode 100644
index 612462e..0000000
--- a/plugins/video_params/video_params.info
+++ /dev/null
@@ -1,7 +0,0 @@
-;$Id$
-name = Video Params
-description = Enable addition of html params to object generated by video module. Useful if you need to use swf videos which needs params to be passed.
-dependencies[] = video
-package = "Video"
-core = 6.x
-
diff --git a/plugins/video_params/video_params.module b/plugins/video_params/video_params.module
deleted file mode 100644
index ee19a5c..0000000
--- a/plugins/video_params/video_params.module
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-//$Id$
-/**
- * @file
- * Enable addition of params to object generated by video module
- *
- * @author Fabio Varesano <fvaresano at yahoo dot it>
- * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw at gmail dot com>
- * @todo
- */
-
-
-
-/**
- * Implementation of hook_help().
- */
-function video_params_help($path, $arg) {
- switch ($path) {
- case 'admin/modules#description':
- return t('Enable addition of html params to object generated by video module. Useful if you need to use swf videos which needs params to be passed.');
- }
-}
-
-
-/**
- * Implementation of hook_perm().
- */
-function video_params_perm() {
- return array('insert object params');
-}
-
-
-
-
-/**
- * Implementation of hook_form_alter()
- * We use this to add a text area to the video creation form.
- * In the text area the user will be able to insert his param value association.
- */
-function video_params_form_alter(&$form, &$form_state, $form_id) {
-
- if($form_id == 'video_node_form' && isset($form['video']) && user_access('insert object params')) {
-
- // get node object
- $node = $form['#node'];
-
- //We must convert the array data back to something that can go in the textarea.
- $textarea = '';
- if(is_array($node->serial_data['object_parameters'])) {
- foreach ($node->serial_data['object_parameters'] as $param => $value) {
- $textarea .= $param . '=' . $value . "\n";
- }
- $textarea = substr($textarea, 0, -1); //Remove the last newline "\n" from the end.
- }
- $form['parameters'] = array('#type' => 'fieldset', '#title' => t('HTML object parameters'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => -17);
- $form['parameters']['object_parameters'] = array(
- '#title' => t('Embedded object parameters'),
- '#type' => 'textarea',
- '#rows' => 5,
- '#default_value' => $textarea,
- '#description' => t('Enter the values that you would like to be embedded in &#60;param name="param_1" value="value_1" /&#62; tags. Each parameter should be on a seperate line with an equal sign between the parameter and its assigned value. Like param=value for example.')
- );
- }
-}
-
-
-/**
- * Implementation of hook_nodeapi()
- */
-function video_params_nodeapi(&$node, $op, $teaser) {
- if($node->type == 'video') {
- switch ($op) {
- case 'submit':
- //Process the data in the object_parameters textarea.
- if ($node->object_parameters != '') { //Make sure the textarea was not empty.
- $lines = explode("\r\n", $node->object_parameters); //Make an array of each line from the textarea.
- foreach ($lines as $line) { //Loop through each line.
- $array = explode('=', $line); //Break apart at the "=" sign. $line should be in format param=value
- $node->serial_data['object_parameters'][$array[0]] = $array[1]; //Assign the "param" as the key and "value" as the value.
- }
- }
- break;
- }
- }
-}
-
-
-/**
- * Implementation of hook_v_get_param() - video module specific hook
- */
-function video_params_v_get_params(&$node) {
-
- $serial_data = $node->serial_data;
-
- if(is_array($serial_data) && array_key_exists('object_parameters', $serial_data) && !empty($serial_data['object_parameters'])) {
- return $serial_data['object_parameters'];
- }
- else {
- return NULL;
- }
-}
-
-
-
-
-
diff --git a/plugins/zencoder.inc b/plugins/zencoder.inc
new file mode 100644
index 0000000..29d6b7c
--- /dev/null
+++ b/plugins/zencoder.inc
@@ -0,0 +1,307 @@
+<?php
+//$Id$
+
+/**
+ * @file
+ * Provide a api for video conversion and auto thumbnailing using ffmpeg.
+ *
+ * @author Heshan Wanigasooriya <heshan at heidisoft.com, heshanmw at gmail dot com>
+ * TODO: add common settings from video module configurations and extend it from ffmpeg.inc
+ * since we need to have executable path of ffmpeg to ffmpeg.inc we need to have it
+ */
+
+/**
+ * Define some constants
+ */
+defined('VIDEO_RENDERING_PENDING')
+ or define('VIDEO_RENDERING_PENDING', 1);
+defined('VIDEO_RENDERING_ACTIVE')
+ or define('VIDEO_RENDERING_ACTIVE', 5);
+defined('VIDEO_RENDERING_COMPLETE')
+ or define('VIDEO_RENDERING_COMPLETE', 10);
+defined('VIDEO_RENDERING_FAILED')
+ or define('VIDEO_RENDERING_FAILED', 20);
+
+// nice value to append at the beginning of the command
+defined('VIDEO_RENDERING_NICE')
+ or define('VIDEO_RENDERING_NICE', 'nice -n 19');
+
+// curl related data
+defined('HTTP_CONNECT_TIMEOUT')
+ or define('HTTP_CONNECT_TIMEOUT', 600);
+defined('HTTP_LOW_SPEED_LIMIT')
+ or define('HTTP_LOW_SPEED_LIMIT', 256);
+defined('HTTP_LOW_SPEED_TIMEOUT')
+ or define('HTTP_LOW_SPEED_TIMEOUT', 600);
+
+
+// TODO : add cron API to video module
+function zencoder_cron() {
+ global $base_url;
+
+ if(variable_get('video_zencoder_helper_auto_cvr_cron', true)) {
+ exec("php video_scheduler.php $base_url > /dev/null &");
+ }
+}
+
+
+/**
+ * Get some informations from the video file
+ */
+function zencoder_get_video_info($vidfile) {
+ static $zencoder_info;
+ $fid = $vidfile['fid'];
+ // $command_output = cache_get($fid);
+ // if(empty($command_output)) {
+ // escape file name for safety
+ $file = escapeshellarg($vidfile['filepath']);
+ // create the full command to execute
+ $command = variable_get('video_transcoder_path', '/usr/bin/ffmpeg') . ' -i ' . $file;
+
+ //execute the command
+ ob_start();
+ passthru($command." 2>&1", $command_return);
+ $command_output = ob_get_contents();
+ ob_end_clean();
+
+ // cache the result for further calls
+ // $zencoder_info[$vidfile['fid']] = $command_output;
+ // cache_set($vidfile['fid'], $command_output);
+ // }
+
+ return $command_output;
+}
+
+
+/**
+ * Return the video resolution
+ */
+function zencoder_auto_resolution(&$node) {
+
+ if(!variable_get('video_zencoder_helper_auto_resolution', false)) {
+
+ // call ffmpeg -i
+ $zencoder_output = zencoder_get_video_info($node);
+
+ // get resolution
+ $pattern = '/Video: .*, ([0-9]{2,4}x[0-9]{2,4})/';
+ preg_match_all($pattern, $zencoder_output, $matches, PREG_PATTERN_ORDER);
+ $resolution = $matches[1][0];
+
+ return explode("x", $resolution);
+ }
+ return null;
+}
+
+
+/**
+ * Return the playtime seconds of a video
+ */
+function zencoder_auto_playtime($file) {
+
+ if(!variable_get('video_zencoder_helper_auto_playtime', false)) {
+
+ // call ffmpeg -i
+ $zencoder_output = zencoder_get_video_info($file);
+
+ // get playtime
+ $pattern = '/Duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9])/';
+ preg_match_all($pattern, $zencoder_output, $matches, PREG_PATTERN_ORDER);
+ $playtime = $matches[1][0];
+
+ // ffmpeg return lenght as 00:00:31.1 Let's get playtime from that
+ $hmsmm = explode(":", $playtime);
+
+ $tmp = explode(".", $hmsmm[2]);
+ $seconds = $tmp[0];
+
+ $hours = $hmsmm[0];
+ $minutes = $hmsmm[1];
+
+ return $seconds + ($hours * 3600) + ($minutes * 60);
+ }
+}
+
+/**
+ * Generates a thumbnail from the video file
+ * Implementing hook_auto_thumbnail on inc
+ *
+ * @param $vidfile
+ * object with element information
+ *
+ * @return
+ * a drupal file objects
+ */
+function zencoder_auto_thumbnail($vidfile) {
+ global $user;
+ $uploaded_file = $vidfile;
+ $fid = $uploaded_file["fid"];
+
+ // are we debugging?
+ // escape the filename for safety
+ $videofile = escapeshellarg($uploaded_file['filepath']);
+ $thumb_path = variable_get('video_thumb_path', 'video_thumbs');
+ //files will save in files/video_thumbs/#fileId folder
+ $tmp = file_directory_path(). '/' . $thumb_path . '/' . $fid;
+ // Ensure the destination directory exists and is writable.
+ $directories = explode('/', $tmp);
+ // array_pop($directories); // Remove the file itself.
+ // Get the file system directory.
+ $file_system = file_directory_path();
+ foreach ($directories as $directory) {
+ $full_path = isset($full_path) ? $full_path . '/' . $directory : $directory;
+ // Don't check directories outside the file system path.
+ if (strpos($full_path, $file_system) === 0) {
+ field_file_check_directory($full_path, FILE_CREATE_DIRECTORY);
+ }
+ }
+ $count = variable_get('no_of_video_thumbs', 5);
+ $duration = zencoder_auto_playtime($vidfile);
+ $files = NULL;
+ for($i = 1; $i <= $count; $i++) {
+ // get ffmpeg configurations
+ $seek = ($duration/$count) * $i;
+ $thumbfile = $tmp . "/video-thumb-for-$fid-$i.png";
+ //skip files already exists, this will save ffmpeg traffic
+ if (!is_file($thumbfile)) {
+ $tnail = variable_get('video_transcoder_path', '/usr/bin/ffmpeg');
+ $options = preg_replace(array('/%videofile/', '/%thumbfile/', '/%seek/'), array($videofile, $thumbfile, $seek), variable_get('video_zencoder_thumbnailer_options', '-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile'));
+ // $options = preg_replace(array('/%videofile/', '/%tmp/', '/%id/', '/%interval/'), array($videofile, $tmp, $i, ($duration/$count)), variable_get('video_image_thumbnailer_options', '-ss %id*%interval -i %videofile -vframes 1 %thumbfile'));
+ // ffmpeg -ss $i*$interval -i intro.mov -vframes 1 -s 320x240 thumb_$i.jpg
+ //ffmpeg -i superstunt_8uiarzrh.mp4 -r 0.1 -ss 00:00:5 -f image2 img/images%02d.png
+ ////ffmpeg -i superstunt_8uiarzrh.mp4 -r 0.05 -ss 00:00:5 -f image2 img/images%1d.jpg
+ // executes the command
+ $command = "$tnail $options";
+ ob_start();
+ passthru($command." 2>&1", $tnail_return);
+ $tnail_output = ob_get_contents();
+ ob_end_clean();
+ if (!file_exists($thumbfile)) {
+ $error_param = array(
+ '%file' => $thumbfile,
+ '%cmd' => $command,
+ '%out' => $tnail_output,
+ );
+ $error_msg = t("error generating thumbnail for video: generated file %file does not exist.<br />Command Executed:<br />%cmd<br />Command Output:<br />%out", $error_param);
+ // let's log this
+ watchdog('video_ffmpeg',$error_msg, array(), WATCHDOG_ERROR);
+ }
+ }
+ // Begin building file object.
+ //TODO : use file_munge_filename()
+ $file = new stdClass();
+ $file->uid = $user->uid;
+ $file->status = FILE_STATUS_TEMPORARY;
+ $file->filename = trim("video-thumb-for-$fid-$i.png");
+ $file->filepath = $thumbfile;
+ $file->filemime = file_get_mimetype("video-thumb-for-$fid-$i.png");
+ $file->filesize = filesize($thumbfile);
+ $file->timestamp = time();
+ $files[] = $file;
+ }
+ return $files;
+}
+
+/**
+ * Implementing hook_chcek_exepath() on inc
+ * To check the the path is executable or not
+ * @param <type> path to check
+ * @return bool TRUE/FALSE
+ */
+function zencoder_check_exe_path($path=NULL) {
+ if (!$path) {
+ $path = variable_get('video_transcoder_path', '/usr/bin/ffmpeg');
+ }
+ if (function_exists('is_executable')) {
+ $test = 'is_executable';
+ } else {
+ $test = 'file_exists';
+ }
+ return $test($path);
+}
+
+/**
+ * Implementing hook_auto_convert();
+ * @param <type> $job
+ */
+function zencoder_auto_convert(&$job) {
+ $videofile = escapeshellarg($job->filepath); // escape file name for safety
+ $convfile = tempnam(file_directory_temp(), 'video-rendering');
+ $audiobitrate = variable_get('video_zencoder_helper_auto_cvr_audio_bitrate', 64);
+ $videobitrate = variable_get('video_zencoder_helper_auto_cvr_video_bitrate', 200);
+ $size = _video_render_get_size();
+ $converter = variable_get('video_transcoder_path', '/usr/bin/ffmpeg');
+
+ $options = preg_replace(array('/%videofile/', '/%convertfile/', '/%audiobitrate/', '/%size/', '/%videobitrate/'),
+ array($videofile, $convfile, $audiobitrate, $size, $videobitrate),
+ variable_get('video_zencoder_helper_auto_cvr_options',
+ '-y -i %videofile -f flv -ar 22050 -ab %audiobitrate -s %size -b %videobitrate -qscale 1 %convertfile'));
+
+ // set to the converted file output
+ $job->convfile = $convfile;
+
+ $command = VIDEO_RENDERING_NICE . " $converter $options";
+
+ //print('executing ' . $command); die;
+ watchdog('video_render', 'executing: ' . $command, array(), WATCHDOG_DEBUG);
+// watchdog('video_render', 'Starting : ' . time());
+ //execute the command
+ ob_start();
+ passthru($command." 2>&1", $command_return);
+ $command_output = ob_get_contents();
+ ob_end_clean();
+// watchdog('video_render', 'Completed');
+ //print $command_output;
+
+ if (!file_exists($job->convfile) || !filesize($job->convfile)) {
+ watchdog('video_render', 'video conversion failed. ffmpeg reported the following output: ' . $command_output, array(), WATCHDOG_ERROR);
+ // _video_render_set_video_encoded_fid($job->nid, $job->vid, -1);
+ // _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_FAILED);
+ }
+ else {
+ $file_name = basename($job->filename . ".flv");
+ $file = new stdClass();
+ $file->uid = $job->uid;
+ $file->status = FILE_STATUS_PERMANENT;
+ $file->filename = basename($file_name);
+ $file->filepath = $job->convfile;
+ $file->filemime = file_get_mimetype($file_name);
+ $file->filesize = filesize($job->convfile);
+ $file->timestamp = time();
+
+ $job->converted = $file;
+ }
+}
+
+
+/**
+ * Calculate the converted video size basing on the width set on administration.
+ * Aspect ration is maintained.
+ */
+//function _video_render_get_size() {
+// return variable_get('video_zencoder_width', 640) . 'x' . variable_get('video_zencoder_height', 480);
+//}
+
+
+function _video_curl_post($url, $fields, &$output) {
+
+ $options = array(
+ CURLOPT_POST => TRUE,
+ CURLOPT_POSTFIELDS => $fields,
+ CURLOPT_CONNECTTIMEOUT => HTTP_CONNECT_TIMEOUT,
+ CURLOPT_LOW_SPEED_LIMIT => HTTP_LOW_SPEED_LIMIT,
+ CURLOPT_LOW_SPEED_TIME => HTTP_LOW_SPEED_TIMEOUT,
+ CURLOPT_RETURNTRANSFER => TRUE
+ );
+
+ $ch = curl_init($url);
+ curl_setopt_array($ch, $options);
+ $output = curl_exec($ch);
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ curl_close($ch);
+
+ return $http_code;
+}
+
+/** S3 API functions **/
+/** ---------------- **/