diff options
author | Heshan Wanigasooriya <heshanmw@gmail.com> | 2011-01-09 14:21:01 +0000 |
---|---|---|
committer | Heshan Wanigasooriya <heshanmw@gmail.com> | 2011-01-09 14:21:01 +0000 |
commit | 0e1abe9e84fc2b2c72af1f5f740ea378e6881f8f (patch) | |
tree | 3d37cd603ca75651a0a892f02a2664e9d1bc0432 | |
parent | e06647587abf3e384a6461c93031f07d35b74098 (diff) | |
download | video-0e1abe9e84fc2b2c72af1f5f740ea378e6881f8f.tar.gz video-0e1abe9e84fc2b2c72af1f5f740ea378e6881f8f.tar.bz2 |
finished the thumbanail creating with the video module when its automatically selected.
-rw-r--r-- | transcoders/video_ffmpeg.inc | 25 | ||||
-rw-r--r-- | video.css | 6 | ||||
-rw-r--r-- | video.field.inc | 13 | ||||
-rw-r--r-- | video.module | 30 |
4 files changed, 39 insertions, 35 deletions
diff --git a/transcoders/video_ffmpeg.inc b/transcoders/video_ffmpeg.inc index 7a048f3..b971096 100644 --- a/transcoders/video_ffmpeg.inc +++ b/transcoders/video_ffmpeg.inc @@ -53,28 +53,29 @@ class video_ffmpeg implements transcoder_interface { global $user; // Setup our thmbnail path. $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); - $final_thumb_path = file_default_scheme() . '://' . $video_thumb_path . '/' . $video['fid']; // Get the file system directory. - file_prepare_directory($final_thumb_path, FILE_CREATE_DIRECTORY); + $schema_thumb_path = file_default_scheme() . '://' . $video_thumb_path . '/' . $video['fid']; + file_prepare_directory($schema_thumb_path, FILE_CREATE_DIRECTORY); // Total thumbs to generate $total_thumbs = variable_get('video_thumbs', 5); $videofile = file_load($video['fid']); - $videopath = escapeshellarg($videofile->uri); + //get the actual video file path from the stream wrappers + $videopath = (drupal_realpath($videofile->uri)); //get the playtime from the current transcoder - $duration = $this->get_playtime($videofile->uri); + $duration = $this->get_playtime($videopath); $files = NULL; for ($i = 1; $i <= $total_thumbs; $i++) { $seek = ($duration / $total_thumbs) * $i - 1; //adding minus one to prevent seek times equaling the last second of the video - $filename = "/video-thumb-for-" . $video['fid'] . "-$i.jpg"; - $thumbfile = $final_thumb_path . $filename; + $filename = file_munge_filename("/video-thumb-for-" . $video['fid'] . "-$i.jpg", '', TRUE); + $thumbfile = $schema_thumb_path . $filename; //skip files already exists, this will save ffmpeg traffic - if (!is_file($thumbfile)) { + if (!is_file(drupal_realpath($thumbfile))) { //setup the command to be passed to the transcoder. - $options = $this->params['cmd_path'] . ' ' . t($this->params['thumb_command'], array('!videofile' => $videopath, '!seek' => $seek, '!thumbfile' => $thumbfile)); + $options = $this->params['cmd_path'] . ' ' . t($this->params['thumb_command'], array('!videofile' => $videopath, '!seek' => $seek, '!thumbfile' => drupal_realpath($thumbfile))); // Generate the thumbnail from the video. $command_output = $this->run_command($options); - if (!file_exists($thumbfile)) { + if (!file_exists(drupal_realpath($thumbfile))) { $error_param = array('%file' => $thumbfile, '%cmd' => $options, '%out' => $command_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); // Log the error message. @@ -86,11 +87,11 @@ class video_ffmpeg implements transcoder_interface { // @TODO : use file_munge_filename() $file = new stdClass(); $file->uid = $user->uid; - $file->status = FILE_STATUS_TEMPORARY; + $file->status = 0; $file->filename = trim($filename); - $file->filepath = $thumbfile; + $file->uri = $thumbfile; $file->filemime = file_get_mimetype($filename); - $file->filesize = filesize($thumbfile); + $file->filesize = filesize(drupal_realpath($thumbfile)); $file->timestamp = time(); $files[] = $file; } @@ -3,13 +3,13 @@ /** * Image upload widget. */ -div.image-preview { +div.video-preview { float: left; /* LTR */ padding: 0 10px 10px 0; /* LTR */ } -div.image-widget-data { +div.video-widget-data { float: left; /* LTR */ } -div.image-widget-data input.text-field { +div.video-widget-data input.text-field { width: auto; } diff --git a/video.field.inc b/video.field.inc index 6e35c9e..9d9eeda 100644 --- a/video.field.inc +++ b/video.field.inc @@ -20,11 +20,11 @@ function video_field_info() { 'autoconversion' => 0, 'autothumbnail' => 'no', 'default_video_thumbnail' => 0, - 'preview_video_thumb_style' => 'medium', + 'preview_video_thumb_style' => 'thumbnail', ), 'instance_settings' => array( 'file_extensions' => 'mp4 ogg avi mov wmv flv', - 'file_directory' => '', + 'file_directory' => 'video', 'max_filesize' => '', 'default_dimensions' => '640x350', 'default_player_dimensions' => '640x350' @@ -245,11 +245,12 @@ function video_field_widget_process($element, &$form_state, $form) { // } // Add the image preview. if ($settings['default_video_thumbnail'] && $element['#value']['fid'] != 0) { + $element['preview'] = array(); $default_thumbnail = file_load($settings['default_video_thumbnail']); - $element['preview'] = array( - '#type' => 'markup', - '#markup' => theme('image_style', array('style_name' => $settings['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)), - ); +// $element['preview'] = array( +// '#type' => 'markup', +// '#markup' => theme('image_style', array('style_name' => $settings['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)), +// ); } // Title is not necessary for each individual field. if ($field['cardinality'] != 1) { diff --git a/video.module b/video.module index 398e093..4bb7ad0 100644 --- a/video.module +++ b/video.module @@ -280,13 +280,13 @@ function video_thumb_process(&$element, &$form_state) { $transcoder = new video_transcoder; if ($thumbs = $transcoder->generate_thumbnails($file)) { $rnd_img = rand(0, variable_get('video_thumbs', 5) - 1); - $default_thumb = $thumbs[$rnd_img]->filepath; + $default_thumb = $thumbs[$rnd_img]->uri; if (is_array($thumbs)) { foreach ($thumbs as $fid => $img) { // if file object contain url then use file name to identify object - $key = $img->filepath; - $thumbss[$key] = theme('video_thumbnails', $img, '', '', array('width' => '50'), FALSE); + $key = $img->uri; + $thumbss[$key] = theme('image_style', array('style_name' => $field['settings']['preview_video_thumb_style'], 'path' => $img->uri)); } } } @@ -298,7 +298,7 @@ function video_thumb_process(&$element, &$form_state) { '#options' => $thumbss, '#default_value' => !empty($file['data']['video_thumb']) ? $file['data']['video_thumb'] : $default_thumb, '#weight' => 10, - '#attributes' => array('class' => 'video-thumbnails', 'onchange' => 'videoftp_thumbnail_change()', 'rel' => 'video_large_thumbnail-' . $delta), + '#attributes' => array('class' => array('video-thumbnails'), 'onchange' => 'videoftp_thumbnail_change()', 'rel' => 'video_large_thumbnail-' . $delta), ); } else { $gen_fail = TRUE; @@ -324,15 +324,16 @@ function video_thumb_process(&$element, &$form_state) { // Setup our large thumbnail that is on the left. // @todo Add smaller video preview instead of thumbnail? - if (isset($file['data']['video_thumb']) && !empty($file['data']['video_thumb'])) { - $large_thumb = array('filepath' => $file['data']['video_thumb']); - } elseif (!empty($field['settings']['default_video_thumb'])) { - $large_thumb = $field['settings']['default_video_thumb']; - } else { - $large_thumb = array('filepath' => $default_thumb); - } - // @todo Integrate the thumbnails with imagecache. - $element['preview']['#suffix'] = '<div class="video_large_thumbnail-' . $delta . '">' . theme('video_thumbnails', $large_thumb, '', '', array('width' => '150'), FALSE) . '</div>'; +// if (isset($file['data']['video_thumb']) && !empty($file['data']['video_thumb'])) { +// $large_thumb = array('filepath' => $file['data']['video_thumb']); +// } elseif (!empty($field['settings']['default_video_thumb'])) { +// $large_thumb = $field['settings']['default_video_thumb']; +// } else { +// $large_thumb = array('filepath' => $default_thumb); +// } +// $default_thumbnail = file_load($settings['default_video_thumbnail']); +// // @todo Integrate the thumbnails with imagecache. +// $element['preview']['#suffix'] = '<div class="video_large_thumbnail-' . $delta . '">' . theme('image_style', array('style_name' => $settings['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)) . '</div>'; } } @@ -470,7 +471,8 @@ function video_widget_element_settings(&$element, &$form_state) { // Lets figure out our dimensions for our video and add astericks next to our options. $options = video_explode("\n", variable_get("video_metadata_dimensions", video_default_dimensions())); if ($field['settings']['autoconversion'] && isset($element['preview']) && $file['fid'] != 0 && $default_dimensions) { - $video_info = _video_dimensions_options($options, $file['filepath']); + $file_object = file_load($file['fid']); + $video_info = _video_dimensions_options($options, drupal_realpath($file_object->uri)); $description = t('Set your video dimensions. This will create your player and transcode your video with these dimensions. Your video size is !size, if you choose a higher resolution, this could cause video distortion. |