You are here

public function video_zencoder_api::create in Video 6.5

Same name and namespace in other branches
  1. 6.4 plugins/video_zencoder/video_zencoder.lib.inc \video_zencoder_api::create()
  2. 7 modules/video_zencoder/includes/zencoder.inc \video_zencoder_api::create()

create transcoding job on Zencoder.com

File

plugins/video_zencoder/video_zencoder.lib.inc, line 39
Class file to handle amazon s3 transfers.

Class

video_zencoder_api

Code

public function create(stdClass $video) {
  if ($this->zencoder == NULL) {
    return FALSE;
  }

  // The video may be stored in the private file store using an absolute path, so remove the first slash if there is one.
  $filepath = ltrim($video->filepath, '/');

  // dimensions
  $dimensions = explode('x', $video->dimensions);

  // Notifications
  $notifications = array(
    array(
      'format' => 'json',
      'url' => variable_get('video_zencoder_postback', url('postback/jobs', array(
        'absolute' => TRUE,
      ))),
    ),
  );

  // S3 permissions
  $public = !variable_get('amazon_s3_private', FALSE);

  // Common output URL prefix
  $output_url_prefix = 's3://' . $video->bucket . '/' . dirname(dirname($filepath)) . '/converted/' . pathinfo($video->filepath, PATHINFO_FILENAME);

  // construct the output array with the presets
  $zc_outputs = array();
  foreach ($video->presets as $preset) {
    $settings = $preset
      ->getSettings();
    if (array_key_exists('additional_settings', $settings)) {
      $settings = array_merge($settings, $settings['additional_settings']);
      unset($settings['additional_settings']);
    }
    $settings['label'] = 'VIDEO_' . $video->fid . '_' . $preset->id;
    $settings['url'] = $output_url_prefix . $preset->filenamesuffix . '.' . $preset->extension;
    $settings['public'] = $public;
    $settings['width'] = intval($dimensions[0]);
    $settings['height'] = intval($dimensions[1]);
    $settings['notifications'] = $notifications;
    $zc_outputs[] = $settings;
  }

  // Add thumbnails
  if (empty($zc_outputs)) {
    $zc_outputs[0] = array();
  }
  $zc_outputs[0]['thumbnails'] = array(
    'number' => intval(variable_get('video_thumbs', 5)),
    'size' => variable_get('video_thumbs_size', '160x120'),
    // The video may be stored in the private file store using an absolute path, so remove the first slash if there is one.
    'base_url' => 's3://' . $video->bucket . '/' . ltrim(video_thumb_path($video, TRUE), '/'),
    'prefix' => $video->fid,
  );
  try {
    return $this->zencoder->jobs
      ->create(array(
      'api_key' => $this->access_key,
      'input' => 's3://' . $video->bucket . '/' . $filepath,
      'outputs' => $zc_outputs,
    ));
  } catch (Services_Zencoder_Exception $e) {
    watchdog('zencoder', 'Zencoder reports errors while converting %file:<br/>!errorlist', array(
      '%file' => $video->filename,
      '!errorlist' => theme('item_list', $e
        ->getErrors()),
    ), WATCHDOG_ERROR);
    return FALSE;
  }
}