diff options
-rw-r--r-- | transcoders/video_ffmpeg.inc | 29 | ||||
-rw-r--r-- | video.css (renamed from image.css) | 0 | ||||
-rw-r--r-- | video.field.inc | 90 | ||||
-rw-r--r-- | video.module | 17 | ||||
-rw-r--r-- | video.theme.inc | 67 |
5 files changed, 125 insertions, 78 deletions
diff --git a/transcoders/video_ffmpeg.inc b/transcoders/video_ffmpeg.inc index 601f0f6..7a048f3 100644 --- a/transcoders/video_ffmpeg.inc +++ b/transcoders/video_ffmpeg.inc @@ -53,25 +53,15 @@ 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']; - - // Ensure the destination directory exists and is writable. - $directories = explode('/', $final_thumb_path); + $final_thumb_path = file_default_scheme() . '://' . $video_thumb_path . '/' . $video['fid']; // Get the file system directory. - $file_system = file_default_scheme() . ':/'; - 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); - } - } - + file_prepare_directory($final_thumb_path, FILE_CREATE_DIRECTORY); // Total thumbs to generate $total_thumbs = variable_get('video_thumbs', 5); - $videofile = escapeshellarg($video['filepath']); + $videofile = file_load($video['fid']); + $videopath = escapeshellarg($videofile->uri); //get the playtime from the current transcoder - $duration = $this->get_playtime($video['filepath']); + $duration = $this->get_playtime($videofile->uri); $files = NULL; for ($i = 1; $i <= $total_thumbs; $i++) { @@ -81,7 +71,7 @@ class video_ffmpeg implements transcoder_interface { //skip files already exists, this will save ffmpeg traffic if (!is_file($thumbfile)) { //setup the command to be passed to the transcoder. - $options = $this->params['cmd_path'] . ' ' . t($this->params['thumb_command'], array('!videofile' => $videofile, '!seek' => $seek, '!thumbfile' => $thumbfile)); + $options = $this->params['cmd_path'] . ' ' . t($this->params['thumb_command'], array('!videofile' => $videopath, '!seek' => $seek, '!thumbfile' => $thumbfile)); // Generate the thumbnail from the video. $command_output = $this->run_command($options); if (!file_exists($thumbfile)) { @@ -428,10 +418,13 @@ class video_ffmpeg implements transcoder_interface { } public function load_job_queue() { + return; $total_videos = variable_get('video_ffmpeg_instances', 5); $videos = array(); - $result = db_query_range('SELECT f.*, vf.vid, vf.nid, vf.dimensions, vf.status as video_status FROM {video_files} vf LEFT JOIN {files} f ON vf.fid = f.fid WHERE vf.status = %d AND f.status = %d ORDER BY f.timestamp', - VIDEO_RENDERING_PENDING, FILE_STATUS_PERMANENT, 0, $total_videos); + $result = db_query_range('SELECT f.*, vf.vid, vf.nid, vf.dimensions, vf.status as video_status + FROM {video_files} vf LEFT JOIN {files} f ON vf.fid = f.fid + WHERE vf.status = :vstatus AND f.status = :fstatus ORDER BY f.timestamp', + array(':vstatus' => VIDEO_RENDERING_PENDING, ':fstatus' => FILE_STATUS_PERMANENT), 0, $total_videos, array()); while ($row = db_fetch_object($result)) { $videos[] = $row; diff --git a/video.field.inc b/video.field.inc index 93696c5..6e35c9e 100644 --- a/video.field.inc +++ b/video.field.inc @@ -17,14 +17,17 @@ function video_field_info() { 'description' => t('This field stores the ID of an video file as an integer value.'), 'settings' => array( 'uri_scheme' => variable_get('file_default_scheme', 'public'), + 'autoconversion' => 0, + 'autothumbnail' => 'no', 'default_video_thumbnail' => 0, + 'preview_video_thumb_style' => 'medium', ), 'instance_settings' => array( 'file_extensions' => 'mp4 ogg avi mov wmv flv', 'file_directory' => '', 'max_filesize' => '', - 'default_dimensions' => '', - 'default_player_dimensions' => '', + 'default_dimensions' => '640x350', + 'default_player_dimensions' => '640x350' ), 'default_widget' => 'video_upload', 'default_formatter' => 'video', @@ -57,12 +60,31 @@ function video_field_settings_form($field, $instance) { * Implements hook_field_instance_settings_form(). */ function video_field_instance_settings_form($field, $instance) { + $widget = $instance['widget']; + $instance_settings = $instance['settings']; $settings = $instance['settings']; - // Use the file field instance settings form as a basis. $form = file_field_instance_settings_form($field, $instance); // Remove the description option. unset($form['description_field']); + // add settings by widget type + switch ($instance['widget']['type']) { + case 'video_upload': + break; + case 'video_ftp': + $form['ftp_path'] = array( + '#type' => 'textfield', + '#title' => t('FTP Filepath'), + '#default_value' => !empty($widget['ftp_path']) ? $widget['ftp_path'] : 'ftpvideos', + '#description' => t('The subdirectory within the "<em>files/</em>" directory where you have upload the videos for attachment. Once the video is attached it will be moved from this directory to the main files directory.'), + '#required' => TRUE, + '#weight' => 3, + ); + break; + } + //default settings + $default = video_default_instance_settings($settings); + $form = $default + $form; return $form; } @@ -141,7 +163,6 @@ function video_field_widget_info() { 'field types' => array('video'), 'settings' => array( 'progress_indicator' => 'throbber', - 'preview_image_style' => 'thumbnail', ), 'behaviors' => array( 'multiple values' => FIELD_BEHAVIOR_CUSTOM, @@ -153,7 +174,6 @@ function video_field_widget_info() { 'field types' => array('video'), 'settings' => array( 'progress_indicator' => 'throbber', - 'preview_image_style' => 'thumbnail', ), 'behaviors' => array( 'multiple values' => FIELD_BEHAVIOR_CUSTOM, @@ -167,27 +187,9 @@ function video_field_widget_info() { * Implements hook_field_widget_settings_form(). */ function video_field_widget_settings_form($field, $instance) { - $widget = $instance['widget']; - $settings = $widget['settings']; // Use the file widget settings form. $form = file_field_widget_settings_form($field, $instance); - switch ($instance['widget']['type']) { - case 'video_upload': - break; - case 'video_ftp': - $form['ftp_path'] = array( - '#type' => 'textfield', - '#title' => t('FTP Filepath'), - '#default_value' => !empty($widget['ftp_path']) ? $widget['ftp_path'] : 'ftpvideos', - '#description' => t('The subdirectory within the "<em>files/</em>" directory where you have upload the videos for attachment. Once the video is attached it will be moved from this directory to the main files directory.'), - '#required' => TRUE, - '#weight' => 3, - ); - break; - } - //default settings - $default = video_default_widget_settings($settings); - $form = $default + $form; + return $form; } @@ -203,11 +205,6 @@ function video_field_widget_form(&$form, &$form_state, $field, $instance, $langc $settings = $instance['settings']; foreach (element_children($elements) as $delta) { - // Add upload resolution validation. - if ($settings['max_resolution'] || $settings['min_resolution']) { - $elements[$delta]['#upload_validators']['file_validate_image_resolution'] = array($settings['max_resolution'], $settings['min_resolution']); - } - // If not using custom extension validation, ensure this is an image. $supported_extensions = array('mp4', 'ogg', 'avi', 'mov', 'wmv', 'flv'); $extensions = isset($elements[$delta]['#upload_validators']['file_validate_extensions'][0]) ? $elements[$delta]['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions); @@ -237,25 +234,34 @@ function video_field_widget_form(&$form, &$form_state, $field, $instance, $langc function video_field_widget_process($element, &$form_state, $form) { $item = $element['#value']; $item['fid'] = $element['fid']['#value']; - $field = field_widget_field($element, $form_state); - - $element['#theme'] = 'theme_video_widget'; + $instance = field_widget_instance($element, $form_state); + $settings = $field['settings']; + $element['#theme'] = 'video_widget'; $element['#attached']['css'][] = drupal_get_path('module', 'image') . '/video.css'; - - $field_name = $element['#field_name']; - $delta = $element['#delta']; -// $field = content_fields($element['#field_name'], $element['#type_name']); - - if (isset($element['preview']) && $element['#value']['fid'] != 0) { - $element['preview']['#value'] = theme('video_widget_preview', $element['#value']); + // preview the video thumbnail +// if (isset($element['preview']) && $element['#value']['fid'] != 0) { +// $element['preview']['#value'] = theme('video_widget_preview', $element['#value']); +// } + // Add the image preview. + if ($settings['default_video_thumbnail'] && $element['#value']['fid'] != 0) { + $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)), + ); } - // Title is not necessary for each individual field. - if ($field['cardinality'] < 0) { + if ($field['cardinality'] != 1) { unset($element['#title']); } - + // add file elements by widget type + switch ($instance['widget']['type']) { + case 'video_upload': + break; + case 'video_ftp': + break; + } // Create our thumbnails video_thumb_process($element, $form_state); diff --git a/video.module b/video.module index 2cc0cdf..398e093 100644 --- a/video.module +++ b/video.module @@ -142,6 +142,10 @@ function video_theme() { 'arguments' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE), 'file' => 'video.theme.inc', ); + $theme['video_widget'] = array( + 'render element' => 'element', + 'file' => 'video.theme.inc', + ); $theme['video_widget_preview'] = array( 'arguments' => array('item' => TRUE), 'file' => 'video.theme.inc', @@ -456,7 +460,7 @@ function video_widget_element_settings(&$element, &$form_state) { $field = field_widget_field($element, $form_state); $instance = field_widget_instance($element, $form_state); - $settings = $instance['widget']['settings']; + $settings = $instance['settings']; // Check if using the default width and replace tokens. $default_dimensions = user_access('override player dimensions'); $description = t('Set your video dimensions. This will create your player with these dimensions.'); @@ -782,7 +786,7 @@ function video_get_player($element) { } } -function video_default_widget_settings($widget) { +function video_default_instance_settings($widget) { $form = array(); // Default video settings. $form['default_dimensions'] = array( @@ -839,6 +843,15 @@ function video_default_field_settings($settings) { '#upload_location' => 'public://default_video_thumbnail/', '#weight' => 19, ); + $form['preview_video_thumb_style'] = array( + '#title' => t('Preview thumbnail style'), + '#type' => 'select', + '#options' => image_style_options(FALSE), + '#empty_option' => '<' . t('no preview') . '>', + '#default_value' => !empty($settings['preview_video_thumb_style']) ? $settings['preview_video_thumb_style'] : '', + '#description' => t('The preview image will be shown while editing the content.'), + '#weight' => 20, + ); return $form; } diff --git a/video.theme.inc b/video.theme.inc index 4910460..521022a 100644 --- a/video.theme.inc +++ b/video.theme.inc @@ -1,4 +1,5 @@ <?php + //$Id$ /** * @@ -6,18 +7,17 @@ * Theme functions for the video module. * */ - function theme_video_thumbnails($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) { - $file = (array)$file; + $file = (array) $file; // return $file['filepath']; if (!is_file($file['filepath'])) { - return '<!-- File not found: '. $file['filepath'] .' -->'; + return '<!-- File not found: ' . $file['filepath'] . ' -->'; } if ($getsize) { // Use cached width and height if available. if (!empty($file['data']['width']) && !empty($file['data']['height'])) { - $attributes['width'] = $file['data']['width']; + $attributes['width'] = $file['data']['width']; $attributes['height'] = $file['data']['height']; } // Otherwise pull the width and height from the file. @@ -44,11 +44,14 @@ function theme_video_thumbnails($file, $alt = '', $title = '', $attributes = NUL $url = file_create_url($file['filepath']) . $query_string; $attributes['src'] = $url; $attributes = drupal_attributes($attributes); - return '<span></span><img '. $attributes .' />'; + return '<span></span><img ' . $attributes . ' />'; } function theme_video_widget_preview($item) { - return theme('filefield_widget_preview', $item); + $output .= '<div class="image-preview">'; + $output .= drupal_render($item['preview']); + $output .= '</div>'; + return $item; } function theme_video_widget_video_thumb($item = NULL) { @@ -61,20 +64,19 @@ function theme_video_widget_video_thumb($item = NULL) { * @see uploadfield_theme(). */ function theme_video_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE, $imagecache = FALSE) { - $file = (array)$file; + $file = (array) $file; //if this is imagecache skip this as the file might not be created yet if (!$imagecache && !is_file($file['filepath'])) { - return '<!-- File not found: '. str_replace("--", "-", $file['filepath']) .'" -->'; + return '<!-- File not found: ' . str_replace("--", "-", $file['filepath']) . '" -->'; } if ($getsize && $imagecache && ($image = image_get_info($file['filepath']))) { $attributes['width'] = $image['width']; $attributes['height'] = $image['height']; - } - elseif ($getsize) { - // Use cached width and height if available. + } elseif ($getsize) { + // Use cached width and height if available. if (!empty($file['data']['width']) && !empty($file['data']['height'])) { - $attributes['width'] = $file['data']['width']; + $attributes['width'] = $file['data']['width']; $attributes['height'] = $file['data']['height']; } // Otherwise pull the width and height from the file. @@ -101,7 +103,7 @@ function theme_video_image($file, $alt = '', $title = '', $attributes = NULL, $g $url = file_create_url($file['filepath']) . $query_string; $attributes['src'] = $url; $attributes = drupal_attributes($attributes); - return '<img '. $attributes .' />'; + return '<img ' . $attributes . ' />'; } /** @@ -116,15 +118,15 @@ function theme_video_image($file, $alt = '', $title = '', $attributes = NULL, $g function theme_video_widget($variables) { $element = $variables['element']; $output = ''; - $output .= '<div class="image-widget form-managed-file clearfix">'; + $output .= '<div class="video-widget form-managed-file clearfix">'; if (isset($element['preview'])) { - $output .= '<div class="image-preview">'; + $output .= '<div class="video-preview">'; $output .= drupal_render($element['preview']); $output .= '</div>'; } - $output .= '<div class="image-widget-data">'; + $output .= '<div class="video-widget-data">'; if ($element['fid']['#value'] != 0) { $element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> '; } @@ -134,3 +136,36 @@ function theme_video_widget($variables) { return $output; } + +/** + * Returns HTML for an image using a specific image style. + * + * @param $variables + * An associative array containing: + * - style_name: The name of the style to be used to alter the original image. + * - path: The path of the image file relative to the Drupal files directory. + * This function does not work with images outside the files directory nor + * with remotely hosted images. + * - alt: The alternative text for text-based browsers. + * - title: The title text is displayed when the image is hovered in some + * popular browsers. + * - attributes: Associative array of attributes to be placed in the img tag. + * - getsize: If set to TRUE, the image's dimension are fetched and added as + * width/height attributes. + * + * @ingroup themeable + */ +function theme_video_thumb_style($variables) { + $style_name = $variables['style_name']; + $path = $variables['path']; + + // theme_image() can only honor the $getsize parameter with local file paths. + // The derivative image is not created until it has been requested so the file + // may not yet exist, in this case we just fallback to the URL. + $style_path = image_style_path($style_name, $path); + if (!file_exists($style_path)) { + $style_path = image_style_url($style_name, $path); + } + $variables['path'] = $style_path; + return theme('image', $variables); +}
\ No newline at end of file |