aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/video_image/video_image.module73
1 files changed, 35 insertions, 38 deletions
diff --git a/plugins/video_image/video_image.module b/plugins/video_image/video_image.module
index 3e16f7d..dbd22ee 100644
--- a/plugins/video_image/video_image.module
+++ b/plugins/video_image/video_image.module
@@ -48,12 +48,16 @@ function video_image_admin_settings_validate($form_id, &$form_values, &$form) {
} else {
$test = 'file_exists';
}
- if (!$test($form_values['video_image_ffmpeg_path'])) {
- form_set_error('video_image_ffmpeg_path', t('Set correct path for ffmpeg'));
+ if (!$test($form_values['video_image_thumbnailer_path'])) {
+ form_set_error('video_image_thumbnailer_path', t('Set correct path for thumbnailer'));
}
if (!is_numeric($form_values['video_image_auto_thumbnail_seek'])) {
form_set_error('video_image_auto_thumbnail_seek', t('Seek time must be an integer'));
}
+ $options = $form_values['video_image_thumbnailer_options'];
+ if (!strstr($options, '%videofile') || !strstr($options, '%thumbfile')) {
+ form_set_error('video_image_thumbnailer_options', t('Thumbnail options must contain mandatory arguments %videofile and %thumbfile'));
+ }
}
}
@@ -85,8 +89,8 @@ function video_image_admin_settings() {
);
$form['autothumb']['video_image_auto_thumbnail'] = array(
'#type' => 'checkbox',
- '#title' => t('Auto thumbnail for videos (using ffmpeg)'),
- '#description' => t('This requires setting the path to the ffmpeg executable below. If set up correctly, this will auto-generate a thumbnail for each video created.'),
+ '#title' => t('Auto thumbnail for videos'),
+ '#description' => t('This requires setting the path to the thumbnailer executable below. If set up correctly, this will auto-generate a thumbnail for each video created.'),
'#default_value' => variable_get('video_image_auto_thumbnail', false),
);
$form['autothumb']['video_image_auto_thumbnail_only'] = array(
@@ -96,18 +100,24 @@ function video_image_admin_settings() {
'#default_value' => variable_get('video_image_auto_thumbnail_only', false),
'#disabled' => !variable_get('video_image_auto_thumbnail', false),
);
+ $form['autothumb']['video_image_thumbnailer_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Video thumbnailer executable path'),
+ '#description' => t('Set the full path to the thumbnailer executable here to enable automatic thumbnailing of videos'),
+ '#default_value' => variable_get('video_image_thumbnailer_path', '/usr/bin/ffmpeg'),
+ );
+ $form['autothumb']['video_image_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_image_thumbnailer_options', '-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile'),
+ );
$form['autothumb']['video_image_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_image_auto_thumbnail_seek', 2),
);
- $form['autothumb']['video_image_ffmpeg_path'] = array(
- '#type' => 'textfield',
- '#title' => t('ffmpeg executable path'),
- '#description' => t('Set the full path to the ffmpeg executable here to enable automatic thumbnailing of videos'),
- '#default_value' => variable_get('video_image_ffmpeg_path', '/usr/bin/ffmpeg'),
- );
$form['autothumb']['video_image_auto_thumbnail_debug'] = array(
'#type' => 'checkbox',
'#title' => t('Debug auto-thumbnail process'),
@@ -253,7 +263,7 @@ function theme_video_image_body($node) {
return $output;
}
-/* Generates a thumbnail from the video file using ffmpeg
+/* Generates a thumbnail from the video file
*
* @param $node
* object with node information
@@ -274,48 +284,35 @@ function _video_image_auto_thumbnail(&$node) {
}
$debug = variable_get('video_image_auto_thumbnail_debug', false);
$videofile = escapeshellarg($_SESSION['video_upload_file']->filepath);
- $filepath = tempnam(file_directory_temp(), 'ffmpeg-thumb');
+ $thumbfile = tempnam(file_directory_temp(), 'tnail-thumb');
$seek = variable_get('video_image_auto_thumbnail_seek', 2);
- $ffmpeg = variable_get('video_image_path_to_ffmpeg', '/usr/bin/ffmpeg');
+ $tnail = variable_get('video_image_thumbnailer_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'));
- /* try the -vframes option first (newer versions of ffmpeg support this)
- * we use passthru so we can get the return value of ffmpeg to determine
- * if it was successful or not (return 0 == success)
- */
- $command = "$ffmpeg -i $videofile -an -y -f mjpeg -ss $seek -vframes 1 $filepath";
+ $command = "$tnail $options";
ob_start();
- passthru($command." 2>&1", $ffmpeg_return);
- $ffmpeg_output = ob_get_contents();
+ passthru($command." 2>&1", $tnail_return);
+ $tnail_output = ob_get_contents();
ob_end_clean();
- /* if we failed, we can try again, using the -t option instead of -vframes
- * older versions of ffmpeg don't support -vframes only -t
- */
- if ($return) {
- $command = "$ffmpeg -i $videofile -y -an -f mjpeg -ss $seek -t 0.001 $filepath";
- ob_start();
- passthru($command." 2>&1", $ffmpeg_return);
- $ffmpeg_output = ob_get_contents();
- ob_end_clean();
- }
if ($debug) {
- drupal_set_message(t('ffmpeg command: ').$command);
- drupal_set_message(t('ffmpeg output: ')."<pre>\n$ffmpeg_output\n</pre>");
+ drupal_set_message(t('Thumbnailer command: ').$command);
+ drupal_set_message(t('Thumbnailer output: ')."<pre>\n$tnail_output\n</pre>");
}
- if (!file_exists($filepath)) {
- drupal_set_message(t('video_image_auto_thumbnail: file %file does not exist', array('%file' => $filepath)), 'error');
+ if (!file_exists($thumbfile)) {
+ drupal_set_message(t('video_image_auto_thumbnail: file %file does not exist', array('%file' => $thumbfile)), 'error');
}
$file = array(
'filename' => $_SESSION['video_upload_file']->filename . ".video-thumb.jpg",
'filemime' => 'image/jpeg',
- 'filesize' => filesize($filepath),
- 'filepath' => $filepath,
+ 'filesize' => filesize($thumbfile),
+ 'filepath' => $thumbfile,
'nid' => $node->nid,
);
$_SESSION['video_upload_file']->thumbnailed = TRUE;
if ($debug) {
- if ($ffmpeg_return) {
- drupal_set_message(t('ffmpeg failed to thumbnail video'));
+ if ($tnail_return) {
+ drupal_set_message(t('Failed to thumbnail video'));
} else {
drupal_set_message(t('Successfully thumbnailed video'));
}