You are here

video.install in Video 6.5

Provides installation functions for video.module.

@author Heshan Wanigasooriya <heshan at heidisoft dot com> <heshanmw at gmail dot com>

File

video.install
View source
<?php

/**
 * @file
 * Provides installation functions for video.module.
 *
 * @author Heshan Wanigasooriya <heshan at heidisoft dot com>
 *                              <heshanmw at gmail dot com>
 */

/**
 * Implementation of hook_schema().
 */
function video_schema() {
  $schema = array();
  $schema['video_files'] = array(
    'description' => t('Store video transcoding queue'),
    'fields' => array(
      'vid' => array(
        'description' => t('Video id'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'fid' => array(
        'description' => t('Original file id'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'description' => t('Node id'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => t('Status of the transcoding'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'dimensions' => array(
        'type' => 'varchar',
        'length' => '255',
        'default' => '',
        'description' => t('The dimensions of the video.'),
      ),
      'started' => array(
        'description' => t('Started transcodings'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'completed' => array(
        'description' => t('Transcoding completed'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'data' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'A serialized array of converted files. Use of this field is discouraged and it will likely disappear in a future version of Drupal.',
      ),
    ),
    'indexes' => array(
      'status' => array(
        'status',
      ),
      'file' => array(
        'fid',
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );
  $schema['video_preset'] = array(
    'description' => t('Stores basic preset information'),
    'fields' => array(
      'id' => array(
        'description' => t('Preset identifier'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'type' => 'varchar',
        'description' => t('Preset name'),
        'length' => 50,
        'default' => '',
        'not null' => TRUE,
      ),
      'help' => array(
        'type' => 'varchar',
        'description' => t('Help text'),
        'length' => 200,
        'default' => '',
        'not null' => TRUE,
      ),
      'extension' => array(
        'type' => 'char',
        'description' => t('File extension'),
        'length' => 5,
        'default' => '',
        'not null' => TRUE,
      ),
      'filenamesuffix' => array(
        'type' => 'varchar',
        'description' => t('File name suffix'),
        'length' => 15,
        'default' => '',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $schema['video_preset_settings'] = array(
    'description' => t('Stores preset settings per transcoder'),
    'fields' => array(
      'presetid' => array(
        'description' => t('Preset identifier'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'transcoder' => array(
        'type' => 'varchar',
        'length' => 30,
        'default' => '',
        'description' => t('The unique key of the transcoder'),
        'not null' => TRUE,
      ),
      'data' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => t('The serialized settings'),
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'presetid',
      'transcoder',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function video_install() {
  $t = get_t();
  drupal_install_schema('video');
  $paddingtext = '-vf "pad=!paddingwidth:!paddingheight:!paddingleft:!paddingtop:000000"';
  $presetids = array();
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'Flash', 'flv', '', $t('Creates files that play in any Flash player, including older versions.'));
  $presetids['hq_flash'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['hq_flash'], 'video_localcommand', serialize(array(
    'commands' => array(
      '!cmd_path -y -i !videofile -s !widthx!height -r 15 -b 250 -ar 22050 -ab 48 ' . $paddingtext . ' !convertfile',
    ),
    'useflvtool2' => 1,
  )));
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'HTML5 MP4', 'mp4', '', $t('Creates files that natively play in Internet Explorer 9+ and Google Chrome using HTML5 and in any other browser using Flash.'));
  $presetids['html5_mp4'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['html5_mp4'], 'video_localcommand', serialize(array(
    'commands' => array(
      '!cmd_path -strict experimental -y -i !videofile -pass 1 -s !widthx!height -b 500k -threads 0 -vcodec libx264 ' . $paddingtext . ' -vpre slow_firstpass -an !convertfile',
      '!cmd_path -strict experimental -y -i !videofile -pass 2 -s !widthx!height -b 500k -threads 0 -vcodec libx264 ' . $paddingtext . ' -vpre slow -acodec aac -ab 128k !convertfile',
    ),
    'useqtfaststart' => variable_get('video_ffmpeg_enable_faststart', FALSE) ? 1 : 0,
  )));
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'HTML5 Ogg Theora / Vorbis', 'ogv', '', $t('Creates files that natively play in Firefox using HTML5.'));
  $presetids['html5_ogv'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['html5_ogv'], 'video_localcommand', serialize(array(
    'commands' => array(
      'ffmpeg2theora --videobitrate 500 --max_size !widthx!height --output !convertfile !videofile',
    ),
  )));
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'HTML5 WebM', 'webm', '', $t('Creates files that natively play in Google Chrome using HTML5.'));
  $presetids['html5_webm'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['html5_webm'], 'video_localcommand', serialize(array(
    'commands' => array(
      '!cmd_path -strict experimental -y -i !videofile -pass 1 -s !widthx!height -b 500k -threads 0 -vcodec libvpx -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -f webm ' . $paddingtext . ' -an -y NUL',
      '!cmd_path -strict experimental -y -i !videofile -pass 2 -s !widthx!height -b 500k -threads 0 -vcodec libvpx -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -f webm ' . $paddingtext . ' -acodec libvorbis -ac 2 -y !convertfile',
    ),
  )));
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'iPhone MOV', 'mov', '', $t('Creates files that natively play on the iPhone using HTML5.'));
  $presetids['iphone_mov'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['iphone_mov'], 'video_localcommand', serialize(array(
    'commands' => array(
      '!cmd_path -strict experimental -y -i !videofile -s !widthx!height -f mp4 -vcodec mpeg4 -maxrate 1000k -b 700k -qmin 3 -qmax 5 -bufsize 4096k -g 300 -acodec aac -ab 192k ' . $paddingtext . ' !convertfile',
    ),
    'useqtfaststart' => 1,
  )));
  variable_set('vid_preset', array(
    $presetids['hq_flash'],
    $presetids['html5_mp4'],
  ));
}

/**
 * Implementation of hook_uninstall().
 */
function video_uninstall() {
  drupal_uninstall_schema('video');

  // Delete all variables that begin with the namespaced "video_*"
  $result = db_query('SELECT name FROM {variable} WHERE name LIKE "video_%%"');
  while ($var = db_fetch_array($result)) {
    variable_del($var['name']);
  }
  variable_del('vid_filesystem');
  variable_del('vid_convertor');
  variable_del('vid_preset');
}

/**
 * Implementation of hook_requirements().
 */
function video_requirements($phase) {
  if ($phase != 'runtime') {
    return array();
  }
  $transcoder = video_get_transcoder();
  if ($transcoder != NULL) {
    return $transcoder
      ->requirements();
  }
  return array();
}

/**
 * Implementation of hook_update_N().
 *
 * Dropping video_rendering table and creating video_files
 */
function video_update_6405() {
  $ret = array();
  if (db_table_exists('video_rendering')) {
    db_drop_table($ret, 'video_rendering');
  }
  if (db_table_exists('video_files')) {
    db_drop_table($ret, 'video_files');
  }
  $table = array(
    'description' => t('Store video transcoding queue'),
    'fields' => array(
      'vid' => array(
        'description' => t('Video id'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'fid' => array(
        'description' => t('Original file id'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'description' => t('Node id'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'filename' => array(
        'type' => 'varchar',
        'length' => '255',
        'default' => '',
        'description' => t('The filename of the video.'),
      ),
      'filepath' => array(
        'type' => 'varchar',
        'length' => '255',
        'default' => '',
        'description' => t('The filepath of the video.'),
      ),
      'filemime' => array(
        'type' => 'varchar',
        'length' => '255',
        'default' => '',
        'description' => t('The filemime of the video.'),
      ),
      'filesize' => array(
        'description' => t('Filesize of the video.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'dimensions' => array(
        'type' => 'varchar',
        'length' => '255',
        'default' => '',
        'description' => t('The dimensions of the video.'),
      ),
      'status' => array(
        'description' => t('Status of the transcoding'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'started' => array(
        'description' => t('Started transcodings'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'completed' => array(
        'description' => t('Transcoding completed'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'status' => array(
        'status',
      ),
      'file' => array(
        'fid',
      ),
    ),
    'primary key' => array(
      'vid',
    ),
  );
  db_create_table($ret, 'video_files', $table);
  return $ret;
}

/**
 * Implementation of hook_update_N().
 */
function video_update_6406() {
  drupal_set_message(t('The system has reset your thumbnail and FFmpeg command settings to their original state. If you made adjustments to these commands, you will have to reset them.'));

  // Lets reset our FFmpeg system command variables.
  variable_set('video_ffmpeg_thumbnailer_options', '-i !videofile -an -y -f mjpeg -ss !seek -vframes 1 !thumbfile');
  variable_set('video_ffmpeg_helper_auto_cvr_options', '-y -i !videofile -f flv -ar 22050 -ab !audiobitrate -s !size -b !videobitrate -qscale 1 !convertfile');
  return array();
}

/**
 * Implementation of hook_update_N().
 */
function video_update_6407() {
  $ret = array();

  // drop un wanted fields in video files
  db_drop_field($ret, 'video_files', 'filesize');
  db_drop_field($ret, 'video_files', 'filename');
  db_drop_field($ret, 'video_files', 'filepath');
  db_drop_field($ret, 'video_files', 'filemime');
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_add_column($ret, 'video_files', 'data', 'longtext', array(
        'null' => TRUE,
      ));
      break;
    case 'pgsql':
      db_add_column($ret, 'video_files', 'data', 'text', array(
        'null' => TRUE,
      ));
      break;
  }
  return $ret;
}

/**
 * Implementation of hook_update_N().
 *
 * Create the video_preset_settings table and populate with legacy
 * preset settings.
 */
function video_update_6500() {
  $table1 = array(
    'description' => t('Stores basic preset information'),
    'fields' => array(
      'id' => array(
        'description' => t('Preset identifier'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'type' => 'varchar',
        'description' => t('Preset name'),
        'length' => 50,
        'default' => '',
        'not null' => TRUE,
      ),
      'help' => array(
        'type' => 'varchar',
        'description' => t('Help text'),
        'length' => 200,
        'default' => '',
        'not null' => TRUE,
      ),
      'extension' => array(
        'type' => 'char',
        'description' => t('File extension'),
        'length' => 5,
        'default' => '',
        'not null' => TRUE,
      ),
      'filenamesuffix' => array(
        'type' => 'varchar',
        'description' => t('File name suffix'),
        'length' => 15,
        'default' => '',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique indexes' => array(
      'extension' => array(
        'extension',
        'filenamesuffix',
      ),
    ),
  );
  $table2 = array(
    'description' => t('Stores preset settings per transcoder'),
    'fields' => array(
      'presetid' => array(
        'description' => t('Preset identifier'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'transcoder' => array(
        'type' => 'varchar',
        'length' => 30,
        'default' => '',
        'description' => t('The unique key of the transcoder'),
        'not null' => TRUE,
      ),
      'data' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => t('The serialized settings'),
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'presetid',
      'transcoder',
    ),
  );
  $ret = array();
  db_create_table($ret, 'video_preset', $table1);
  db_create_table($ret, 'video_preset_settings', $table2);
  $presetids = array();
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'Flash', 'flv', '', t('Creates files that play in any Flash player, including older versions.'));
  $presetids['hq_flash'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['hq_flash'], 'video_localcommand', serialize(array(
    'commands' => array(
      '!cmd_path -y -i !videofile -s !widthx!height -r 15 -b 250 -ar 22050 -ab 48 ' . $paddingtext . ' !convertfile',
    ),
    'useflvtool2' => 1,
  )));
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'HTML5 MP4', 'mp4', '', t('Creates files that natively play in Internet Explorer 9+ and Google Chrome using HTML5 and in any other browser using Flash.'));
  $presetids['html5_mp4'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['html5_mp4'], 'video_localcommand', serialize(array(
    'commands' => array(
      '!cmd_path -strict experimental -y -i !videofile -pass 1 -s !widthx!height -b 500k -threads 0 -vcodec libx264 ' . $paddingtext . ' -vpre slow_firstpass -an !convertfile',
      '!cmd_path -strict experimental -y -i !videofile -pass 2 -s !widthx!height -b 500k -threads 0 -vcodec libx264 ' . $paddingtext . ' -vpre slow -acodec aac -ab 128k !convertfile',
    ),
    'useqtfaststart' => variable_get('video_ffmpeg_enable_faststart', FALSE) ? 1 : 0,
  )));
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'HTML5 Ogg Theora / Vorbis', 'ogv', '', t('Creates files that natively play in Firefox using HTML5.'));
  $presetids['html5_ogv'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['html5_ogv'], 'video_localcommand', serialize(array(
    'commands' => array(
      'ffmpeg2theora --videobitrate 500 --max_size !widthx!height --output !convertfile !videofile',
    ),
  )));
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'HTML5 WebM', 'webm', '', t('Creates files that natively play in Google Chrome using HTML5.'));
  $presetids['html5_webm'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['html5_webm'], 'video_localcommand', serialize(array(
    'commands' => array(
      '!cmd_path -strict experimental -y -i !videofile -pass 1 -s !widthx!height -b 500k -threads 0 -vcodec libvpx -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -f webm ' . $paddingtext . ' -an -y NUL',
      '!cmd_path -strict experimental -y -i !videofile -pass 2 -s !widthx!height -b 500k -threads 0 -vcodec libvpx -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -f webm ' . $paddingtext . ' -acodec libvorbis -ac 2 -y !convertfile',
    ),
  )));
  db_query('INSERT INTO {video_preset} SET name="%s", extension="%s", filenamesuffix="%s", help="%s"', 'iPhone MOV', 'mov', '', t('Creates files that natively play on the iPhone using HTML5.'));
  $presetids['iphone_mov'] = db_last_insert_id('video_preset', 'id');
  db_query('INSERT INTO {video_preset_settings} SET presetid=%d, transcoder="%s", data = "%s"', $presetids['iphone_mov'], 'video_localcommand', serialize(array(
    'commands' => array(
      '!cmd_path -strict experimental -y -i !videofile -s !widthx!height -f mp4 -vcodec mpeg4 -maxrate 1000k -b 700k -qmin 3 -qmax 5 -bufsize 4096k -g 300 -acodec aac -ab 192k ' . $paddingtext . ' !convertfile',
    ),
    'useqtfaststart' => 1,
  )));

  // Transform vid_preset variable to something that does not have a 0 as potential value
  $presets = variable_get('vid_preset', array(
    'hq_flash',
  ));
  $newpresets = array();
  foreach ($presets as $presetkey) {
    if (isset($presetids[$presetkey])) {
      $newpresets[] = $presetids[$presetkey];
    }
  }
  variable_set('vid_preset', $newpresets);

  // Change video_ffmpeg to video_localcommand
  if (variable_get('vid_convertor', 'video_ffmpeg') == 'video_ffmpeg') {
    variable_set('vid_convertor', 'video_localcommand');
  }
  variable_set('video_queue_batchsize', variable_get('video_ffmpeg_instances', 5));
  variable_set('video_localcommand_nice_enable', variable_get('video_ffmpeg_nice_enable', FALSE));
  variable_set('video_localcommand_thumbnailer_options', variable_get('video_ffmpeg_thumbnailer_options', '-i !videofile -an -y -f mjpeg -ss !seek -vframes 1 !thumbfile'));
  variable_set('video_localcommand_qtfaststart_cmd', variable_get('video_ffmpeg_faststart_cmd', '/usr/bin/qt-faststart'));
  variable_set('video_localcommand_log_commands', variable_get('video_ffmpeg_log_commands', TRUE));

  // Rename metadata settings
  variable_set('video_dimensions', variable_get('video_metadata_dimensions', video_default_dimensions()));
  variable_set('video_flvtool2_path', variable_get('video_metadata_path', '/usr/bin/flvtool2'));

  // Remove old settings
  variable_del('vid_metadata');
  variable_del('video_metadata');
  variable_del('video_metadata_dimensions');
  variable_del('video_metadata_path');
  variable_del('video_ffmpeg_enable_faststart');
  variable_del('video_ffmpeg_pad_method');
  variable_del('video_ffmpeg_instances');
  variable_del('video_ffmpeg_nice_enable');
  variable_del('video_ffmpeg_thumbnailer_options');
  variable_del('video_ffmpeg_faststart_cmd');
  variable_del('video_ffmpeg_log_commands');
  return $ret;
}

Functions

Namesort descending Description
video_install Implementation of hook_install().
video_requirements Implementation of hook_requirements().
video_schema Implementation of hook_schema().
video_uninstall Implementation of hook_uninstall().
video_update_6405 Implementation of hook_update_N().
video_update_6406 Implementation of hook_update_N().
video_update_6407 Implementation of hook_update_N().
video_update_6500 Implementation of hook_update_N().