You are here

public function TranscoderAbstractionFactoryZencoder::setOptions in Video 7.2

Set options is to set transcoding settings before send to the transcoder.

Overrides TranscoderAbstractionFactory::setOptions

File

transcoders/TranscoderAbstractionFactoryZencoder.inc, line 47
File containing class TranscoderAbstractionFactoryZencoder

Class

TranscoderAbstractionFactoryZencoder
Class that handles Zencoder transcoding.

Code

public function setOptions(array $options) {
  foreach ($options as $key => $value) {
    if (empty($value) || $value === 'none') {
      continue;
    }
    switch ($key) {
      case 'pixel_format':
      case 'video_preset':
      case 'default':
        break;
      case 'video_extension':
        $this->options['output']['format'] = $value;
        break;
      case 'wxh':
        $this->options['output']['size'] = $value;
        break;
      case 'video_quality':
        $this->options['output']['quality'] = intval($value);
        break;
      case 'video_speed':
        $this->options['output']['speed'] = intval($value);
        break;
      case 'video_upscale':
        $this->options['output']['upscale'] = $value;
        break;
      case 'one_pass':
        $this->options['output']['one_pass'] = $value == 1;
        break;
      case 'video_aspectmode':
        $this->options['output']['aspect_mode'] = $value;
        break;
      case 'bitrate_cap':
        $this->options['output']['decoder_bitrate_cap'] = intval($value);
        break;
      case 'buffer_size':
        $this->options['output']['decoder_buffer_size'] = intval($value);
        break;
      default:
        if (strncmp('video_watermark_', $key, 16) === 0) {
          break;
        }
        $this->options['output'][$key] = $value;
        break;
    }
  }

  // set notifications
  $this->options['output']['notifications']['format'] = 'json';
  $this->options['output']['notifications']['url'] = $this->postbackurl;

  // thumbnails
  if ($this->options['output']['thumbnails']['number'] > 0) {
    $this->options['output']['thumbnails'] = array(
      'format' => $this->options['output']['thumbnails']['format'],
      'number' => $this->options['output']['thumbnails']['number'],
      'size' => variable_get('video_thumbnail_size', '320x240'),
      'prefix' => 'thumbnail-' . $this->settings['input']['fid'],
    );
  }
  else {
    unset($this->options['output']['thumbnails']);
  }

  // watermark
  if (!empty($options['video_watermark_enabled']) && !empty($options['video_watermark_fid'])) {
    $file = file_load($options['video_watermark_fid']);
    $audioonly = !empty($options['video_watermark_onlyforaudio']);
    $isaudio = strncmp($this->settings['input']['filemime'], 'audio/', 6) === 0;
    if (!empty($file) && (!$audioonly || $isaudio)) {
      $wm = array(
        'url' => file_create_url($file->uri),
      );
      if (isset($options['video_watermark_y']) && $options['video_watermark_y'] !== '') {
        $wm['y'] = $options['video_watermark_y'];
      }
      if (isset($options['video_watermark_x']) && $options['video_watermark_x'] !== '') {
        $wm['x'] = $options['video_watermark_x'];
      }
      if (isset($options['video_watermark_height']) && $options['video_watermark_height'] !== '') {
        $wm['height'] = $options['video_watermark_height'];
      }
      if (isset($options['video_watermark_width']) && $options['video_watermark_width'] !== '') {
        $wm['width'] = $options['video_watermark_width'];
      }
      $this->options['output']['watermarks'] = array(
        $wm,
      );
    }
  }
  return TRUE;
}