aboutsummaryrefslogtreecommitdiff
path: root/types/uploadfield/uploadfield_thumb.inc
blob: 74aeb80416fc040a550e074f80f93e44fcb6ac42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
//$Id$

/**
 * @file
 * Enable image support for video module.
 *
 * @author Heshan Wanigasooriya <heshan at heidisoft dot com, heshanmw at gmail dot com>
 */

function video_auto_thumb_process (&$element) {
//developed for ffmpeg support
  $file = $element['#value'];
//  $field = content_fields($element['#field_name'], $element['#type_name']);
  if (isset($element['preview']) && $file['fid'] != 0) {
  // TODO : change this to use any transcode to generate thumbnails
    $transcoder = variable_get('vid_convertor', 'ffmpeg');
    module_load_include('inc', 'video', '/plugins/' . $transcoder);
    $function = variable_get('vid_convertor', 'ffmpeg') . '_auto_thumbnail';
    if (function_exists($function)) {
    //    $thumbs = ffmpeg_auto_thumbnail($file);
      $thumbs = $function($file);
    }
    else {
      drupal_set_message(t('Transcoder not configured properly'), 'error');
    }
    $default_thumb = '';
    $rnd_img = rand(1, variable_get('no_of_video_thumbs', 5));
    $default_thumb = $thumbs[$rnd_img]->filepath;

    if(is_array($thumbs)) {
      foreach($thumbs as $fid => $img) {
        $thumbss[$img->filepath] = theme('uploadfield_image', $img, '', '', array('width' => '50'), FALSE);
      }
    }
  }

  $element['data']['video_thumb'] = array(
      '#type' => 'radios',
      '#title' => t('Video Thumbnails'),
      '#options' => $thumbss,
      '#default_value' => !empty($file['data']['video_thumb']) ? $file['data']['video_thumb'] : $default_thumb,
      //      '#description' => t('Pleaes choose a thumbnail from above'),
      '#weight' => 10,
      '#attributes' => array('class' => 'video-thumbnails'),
  );
 }