aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Varesano <fax8@13637.no-reply.drupal.org>2006-11-29 09:06:04 +0000
committerFabio Varesano <fax8@13637.no-reply.drupal.org>2006-11-29 09:06:04 +0000
commit245c16fb76a8192987158a072d9fee88cffc1bad (patch)
treefd1b1ea1630d85d4acc13efe42f9e31af19c25f3
parent1965e6716fe93bdcd14d0d0a24bd8d39fd67dddb (diff)
downloadvideo-245c16fb76a8192987158a072d9fee88cffc1bad.tar.gz
video-245c16fb76a8192987158a072d9fee88cffc1bad.tar.bz2
Patch #99540 by vhmauery (http://drupal.org/user/28957):
Add support for older versions of ffmpeg
-rw-r--r--plugins/video_image/video_image.module41
1 files changed, 31 insertions, 10 deletions
diff --git a/plugins/video_image/video_image.module b/plugins/video_image/video_image.module
index d8c5496..3e16f7d 100644
--- a/plugins/video_image/video_image.module
+++ b/plugins/video_image/video_image.module
@@ -272,18 +272,35 @@ function _video_image_auto_thumbnail(&$node) {
}
return null;
}
+ $debug = variable_get('video_image_auto_thumbnail_debug', false);
$videofile = escapeshellarg($_SESSION['video_upload_file']->filepath);
-
$filepath = tempnam(file_directory_temp(), 'ffmpeg-thumb');
$seek = variable_get('video_image_auto_thumbnail_seek', 2);
$ffmpeg = variable_get('video_image_path_to_ffmpeg', '/usr/bin/ffmpeg');
- $command = "$ffmpeg -i $videofile -y -f mjpeg -ss $seek -vframes 1 -an $filepath";
- if (variable_get('video_image_auto_thumbnail_debug', false)) {
- drupal_set_message(t('ffmpeg command: ').$command);
+
+ /* 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";
+ ob_start();
+ passthru($command." 2>&1", $ffmpeg_return);
+ $ffmpeg_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();
}
- $ffmpeg_output = shell_exec($command." 2>&1");
- if (variable_get('video_image_auto_thumbnail_debug', false)) {
- drupal_set_message(t('ffmpeg output: ').$ffmpeg_output);
+ if ($debug) {
+ drupal_set_message(t('ffmpeg command: ').$command);
+ drupal_set_message(t('ffmpeg output: ')."<pre>\n$ffmpeg_output\n</pre>");
}
if (!file_exists($filepath)) {
drupal_set_message(t('video_image_auto_thumbnail: file %file does not exist', array('%file' => $filepath)), 'error');
@@ -294,10 +311,14 @@ function _video_image_auto_thumbnail(&$node) {
'filesize' => filesize($filepath),
'filepath' => $filepath,
'nid' => $node->nid,
- );
+ );
$_SESSION['video_upload_file']->thumbnailed = TRUE;
- if (variable_get('video_image_auto_thumbnail_debug', false)) {
- drupal_set_message(t('Successfully thumbnailed video'));
+ if ($debug) {
+ if ($ffmpeg_return) {
+ drupal_set_message(t('ffmpeg failed to thumbnail video'));
+ } else {
+ drupal_set_message(t('Successfully thumbnailed video'));
+ }
}
return (object)$file;
}