You are here

public function TranscoderAbstractionFactoryZencoder::extractFrames in Video 7.2

For new videos, this function is never called, because all thumbnails are extracted and saved to the databases during the post back handler in TranscoderAbstractionFactoryZencoder::processPostback().

Overrides TranscoderFactoryInterface::extractFrames

File

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

Class

TranscoderAbstractionFactoryZencoder
Class that handles Zencoder transcoding.

Code

public function extractFrames($destinationScheme, $format) {

  // Check if the job has been completed.
  // If the job has not been completed, don't bother checking for
  // thumbnails
  $fid = $this->settings['input']['fid'];
  $job = video_jobs::load($fid);
  if (empty($job)) {
    return array();
  }

  // No thumbnails available yet
  if ($job->video_status != VIDEO_RENDERING_COMPLETE) {
    return array();
  }
  $path = variable_get('video_thumbnail_path', 'videos/thumbnails') . '/' . $fid;

  // Get the file system directory.
  $dsturibase = $destinationScheme . '://' . $path . '/';
  file_prepare_directory($dsturibase, FILE_CREATE_DIRECTORY);
  $dstwrapper = file_stream_wrapper_get_instance_by_scheme($destinationScheme);

  // Find the old base url setting. If it is not present, don't check for legacy thumbnails
  $base_url = variable_get('video_zencoder_base_url');
  if (empty($base_url)) {
    return array();
  }

  // Where to copy the thumbnails from.
  $final_path = variable_get('video_zencoder_use_full_path', FALSE) ? drupal_realpath(file_uri_scheme($this->settings['input']['uri']) . '://' . $path) : '/' . $path;
  $srcuribase = variable_get('video_zencoder_base_url') . $final_path . '/';
  $thumbs = array();

  // Total thumbs to generate
  $no_of_thumbnails = variable_get('video_thumbnail_count', 5);
  for ($i = 0; $i < $no_of_thumbnails; $i++) {
    $filename = file_munge_filename('thumbnail-' . $fid . '_' . sprintf('%04d', $i) . '.png', '', TRUE);
    $dsturi = $dsturibase . $filename;

    // Download file from S3, if available
    if (!file_exists($dsturi)) {
      $srcuri = $srcuribase . $filename;
      if (!file_exists($srcuri)) {
        watchdog('zencoder', 'Error downloading thumbnail for video %filename: %thumbpath does not exist.', array(
          '%filename' => $this->settings['input']['filename'],
          '%thumbpath' => $srcuri,
        ), WATCHDOG_ERROR);
        break;
      }
      $this
        ->moveFile($srcuri, $dsturi);

      // Delete the source, it is no longer needed
      drupal_unlink($srcuri);
    }
    $thumb = new stdClass();
    $thumb->status = 0;
    $thumb->filename = $filename;
    $thumb->uri = $dsturi;
    $thumb->filemime = $dstwrapper
      ->getMimeType($dsturi);
    $thumbs[] = $thumb;
  }
  return !empty($thumbs) ? $thumbs : FALSE;
}