aboutsummaryrefslogtreecommitdiff
path: root/video.admin.inc
blob: 1d246afa47ec98de1c2e0f9d27335badeb467abc (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
// $Id$

/**
 * @file
 * Provides the administration settings for the Flowplayer Drupal module.
 */

/**
 * Settings Form
 *
 * @return
 *   string of form content or error message
 */
function video_admin_settings() {
  global $base_url;

  $form = array();

  $form['menu'] = array(
      '#type' => 'fieldset',
      '#title' => t('General Behavior'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE
  );

  //  $form['menu']['video_displaydownloadmenutab'] = array(
  //    '#type' => 'checkbox',
  //    '#title' => t('Display download menu tab'),
  //    '#default_value' => variable_get('video_displaydownloadmenutab', 1),
  //    '#description' => t('Toggle display of menu tab to download video from the node page.')
  //  );
  //  $form['menu']['video_displaydownloadlink'] = array(
  //    '#type' => 'checkbox',
  //    '#title' => t('Display download link'),
  //    '#default_value' => variable_get('video_displaydownloadlink', 1),
  //    '#description' => t('Toggle display of "download" link (below the node content in most themes).')
  //  );
  //  $form['menu']['video_displayplaytime'] = array(
  //      '#type' => 'checkbox',
  //      '#title' => t('Display playtime'),
  //      '#default_value' => variable_get('video_displayplaytime', 1),
  //      '#description' => t('Toggle the display of the playtime for a video.')
  //  );
  //  $form['menu']['video_displayfilesize'] = array(
  //      '#type' => 'checkbox',
  //      '#title' => t('Display filesize'),
  //      '#default_value' => variable_get('video_displayfilesize', 1),
  //      '#description' => t('Toggle the display of the filesize for a video.')
  //  );
  $form['menu']['video_autoplay'] = array(
      '#type' => 'checkbox',
      '#title' => t('Automatically start video on page load'),
      '#default_value' => variable_get('video_autoplay', TRUE),
      '#description' => t('Start the video when the page and video loads')
  );

  $form['menu']['video_autobuffering'] = array(
      '#type' => 'checkbox',
      '#title' => t('Automatically start video buffering'),
      '#default_value' => variable_get('video_autobuffering', TRUE),
      '#description' => t('Start buffering video when the page and video loads')
  );

  $form['player'] = array(
      '#type' => 'fieldset',
      '#title' => t('Video Extra Players'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE
  );
  $form['player']['video_cortado'] = array(
      '#type' => 'textfield',
      '#title' => t('Path to OGG Cortado Player'),
      '#default_value' => variable_get('video_cortado', $base_url . '/cortado.jar'),
      '#description' => t('Copy your cortado.jar file to Drupal root and keep the setting un-changed.')
  );

  $form['player']['mp4_play_in_flowplayer'] = array(
      '#type' => 'checkbox',
      '#title' => t('Play HQ MP4 files in Flash Player'),
      '#default_value' => variable_get('mp4_play_in_flowplayer', FALSE),
      '#description' => t('Play HQ MP4 files in Flash player.')
  );


  //
  $gateways = _video_transcoder_types();
  //  print_r($gateways);
  //  $gateway_options = array();
  //  foreach( $gateways as $gateway) {
  //    $obj = new stdClass();
  //    $obj->option = array($gateway => _smsgateway_invoke( 'name', $gateway));
  //    $gateway_options[] = $obj;
  //  }


  $form['tranccoder'] = array(
      '#type' => 'fieldset',
      '#title' => t('Video Transcoder'),
      '#collapsible' => FALSE,
      '#collapsed' => FALSE
  );

  // TODO : write a common function to pick as help
  $help_transcoders = array();
  $help_transcoders[] = l('FFMPEG Default module', 'http://drupal.org/node/722506');
  $help_transcoders[] = l('FFMPEG Wrapper module', 'http://drupal.org/project/ffmpeg_wrapper');
  $help_transcoders[] = l('ZENCODER Online Transcoder', 'http://zencoder.tv/');
  
  $form['tranccoder']['vid_convertor'] = array(
      '#type' => 'radios',
      '#title' => t('Video transcoder'),
      '#default_value' => variable_get('vid_convertor', 'ffmpeg'),
      '#options' => $gateways,
      '#description' => t('Video transcoder will help you to video conversion
          and automatic thumbnail generaion. You must install !ffmpeg_wrapper
          module to enable ffmpeg_wrapper support. !list',
              array('!ffmpeg_wrapper' => l('ffmpeg_wrapper module', 'http://drupal.org/project/ffmpeg_wrapper'),
                    '!list' => theme('item_list', $help_transcoders)))
              );
  $form['tranccoder']['video_transcoder_path'] = array(
      '#type' => 'textfield',
      '#title' => t('Path to Video Transcoder'),
      '#description' => t('Path to executable, you can skip this if your usign ffmpeg_wrapper module support.'),
      '#default_value' => variable_get('video_transcoder_path', '/usr/bin/ffmpeg'),
  );
  $form['tranccoder']['no_of_video_thumbs'] = array(
        '#type' => 'textfield',
        '#title' => t('No of video thumbnails'),
        '#description' => t('No of thumbnails extracting from video'),
        '#default_value' => variable_get('no_of_video_thumbs', 5),
    );

  // ffmpeg wapper settings
  $video_converter = variable_get('vid_convertor', 'ffmpeg');
  if($video_converter == 'ffmpeg') {

    $form['conv'] = array(
        '#type' => 'fieldset',
        '#title' => t('FFmpeg video conversion settings.'),
        '#collapsible' => FALSE,
        '#collapsed' => FALSE
    );
    
    //auto thumb videos
    $form['conv']['autothumb'] = array(
        '#type' => 'fieldset',
        '#title' => t('Automatic video thumbnailing'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE
    );
    $form['conv']['autothumb']['video_thumb_path'] = array(
        '#type' => 'textfield',
        '#title' => t('Path to Video Thumbnails'),
        '#description' => t('Path to save video thumbnails extracted from video'),
        '#default_value' => variable_get('video_thumb_path', 'video_thumbs'),
    );
    $form['conv']['autothumb']['advanced'] = array(
        '#type' => 'fieldset',
        '#title' => t('Advanced settings'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE
    );
    $form['conv']['autothumb']['advanced']['video_ffmpeg_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)').'</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 -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile</div>", '!new' => '<div>-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile</div>')),
        '#default_value' => variable_get('video_ffmpeg_thumbnailer_options', '-i %videofile -an -y -f mjpeg -ss %seek -vframes 1 %thumbfile'),
    );


    // automatic video conversion settings
    $form['conv']['autoconv'] = array(
        '#type' => 'fieldset',
        '#title' => t('Automatic video conversion'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE
    );
    $form['conv']['autoconv']['video_ffmpeg_width'] = array(
        '#type' => 'textfield',
        '#title' => t('Destination video Width'),
        '#size' => 10,
        '#maxlength' => 10,
        '#default_value' => variable_get('video_ffmpeg_width', 640),
    );
    $form['conv']['autoconv']['video_ffmpeg_height'] = array(
        '#type' => 'textfield',
        '#title' => t('Destination video height'),
        '#size' => 10,
        '#maxlength' => 10,
        '#default_value' => variable_get('video_ffmpeg_height', 480),
    );
    $form['conv']['autoconv']['video_ffmpeg_helper_auto_cvr_video_bitrate'] = array(
        '#type' => 'textfield',
        '#title' => t('Video bitrate'),
        '#description' => t('The video bitrate in bit/s of the converted video.'),
        '#size' => 10,
        '#maxlength' => 10,
        '#default_value' => variable_get('video_ffmpeg_helper_auto_cvr_video_bitrate', 200000),
    );
    $form['conv']['autoconv']['video_ffmpeg_helper_auto_cvr_audio_bitrate'] = array(
        '#type' => 'textfield',
        '#title' => t('Audio bitrate'),
        '#description' => t('The audio bitrate in bit/s of the converted video.'),
        '#size' => 10,
        '#maxlength' => 10,
        '#default_value' => variable_get('video_ffmpeg_helper_auto_cvr_audio_bitrate', 64000),
    );
    $form['conv']['autoconv']['advanced'] = array(
        '#type' => 'fieldset',
        '#title' => t('Advanced settings'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE
    );
    $form['conv']['autoconv']['advanced']['video_ffmpeg_helper_auto_cvr_options'] = array(
        '#type' => 'textfield',
        '#title' => t('Video converter options'),
        '#description' => t('Provide the ffmpeg options to configure the video conversion.  Available argument values are: ').'<ul>'.
        '<li>'.t('%videofile (the video file to convert)').
        '<li>'.t('%convertfile (a newly created file to store the converted file)').
        '<li>'.t('%size (video resolution of the converted file)').
        '</ul>'.
        t('For further informations refer to the !ffmpegdoc', array('!ffmpegdoc' => l(t('Official FFMpeg documentation.'), 'http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html', array('fragment' => TRUE)))),
        '#default_value' => variable_get('video_ffmpeg_helper_auto_cvr_options', '-y -i %videofile -f flv -ar 22050 -ab %audiobitrate -s %size -b %videobitrate -qscale 1 %convertfile'),
    );

  }
  else if($video_converter == 'ffmpeg_wrapper') {
    global $conf;
    if(module_exists('ffmpeg_wrapper'))
      $form['ffmpeg'] = ffmpeg_wrapper_configuration_form($conf);
  }
  else if($video_converter == 'zencoder') {
      $form['zencoder'] = array(
          '#type' => 'fieldset',
          '#title' => t("ZENCODER configuration"),
          '#description' => t('Settings for the zencoder module.',
          array('!link' => l(t('S3 test'), 'admin/build/s3_ap1/test'))),
          '#element_validate' => array('video_admin_settings_validate'),
      );

      $form['zencoder']['zencoder_api_key'] = array(
          '#type' => 'textfield',
          '#title' => t('Zencoder Key'),
          '#default_value' => variable_get('zencoder_api_key', ""),
          '#description' => t("Zencoder key."),
      );

      $form['zencoder']['zencoder_api_skey'] = array(
          '#type' => 'textfield',
          '#title' => t('Zencoder Secret Key'),
          '#default_value' => variable_get('zencoder_api_skey', ""),
          '#description' => t("Zencoder secret key."),
      );
    }

  return system_settings_form($form);
}

/**
 * Form API callback to validate the upload settings form.
 *
 * Keeps the use from showing the play tab or the play link
 * if they have chosen to display the video in the node body.
 *
 *
 */
function video_admin_settings_validate($form, &$form_state) {
// check ffmpeg_wrapper installed or not
  if ($form_state['values']['vid_convertor'] == 'ffmpeg_wrapper' && !module_exists('ffmpeg_wrapper')) {
    form_set_error('vid_convertor', t('You do not have installed the !ffmpeg_wrapper module to enable using its plugin, please install it.' , array('!ffmpeg_wrapper' => l('ffmpeg_wrapper', 'http://drupal.org/project/ffmpeg_wrapper'))));
  }
}

/**
 * Ensure that specified convertor is included.
 */
function _video_transcoder( $gateway) {
  $path = drupal_get_path('module', 'video') . '/plugins';
  $files = file_scan_directory($path, '^'. $gateway .'\.inc$');
  foreach ($files as $filename => $file) {
    include_once($filename);
  }
}

/**
 *
 * @staticvar <type> $transcoders
 * @return <type> get installed types of video
 */
function _video_transcoder_types() {
  static $transcoders;

  if (!isset($transcoders)) {
    $transcoders = array();
    $path = drupal_get_path('module', 'video') .'/plugins';
    $files = file_scan_directory($path, '^.*\.inc$');
    foreach ($files as $filename => $file) {
      include_once($filename);
      $transcoders[$file->name] = $file->name;
    }
  }
  return $transcoders;
}

?>