You are here

public function video_zencoder::generate_thumbnails in Video 6.4

Same name and namespace in other branches
  1. 6.5 plugins/video_zencoder/transcoders/video_zencoder.inc \video_zencoder::generate_thumbnails()
  2. 7 modules/video_zencoder/transcoders/video_zencoder.inc \video_zencoder::generate_thumbnails()

Overrides transcoder_interface::generate_thumbnails

File

plugins/video_zencoder/transcoders/video_zencoder.inc, line 18

Class

video_zencoder

Code

public function generate_thumbnails($video) {
  global $user;
  $job = $this
    ->load_job($video['fid']);
  $complete = $job && $job->video_status == VIDEO_RENDERING_COMPLETE;
  $final_thumb_path = video_thumb_path($video);
  $number_of_thumbs = $complete ? variable_get('video_thumbs', 5) : 1;
  $files = array();
  for ($i = 0; $i < $number_of_thumbs; $i++) {
    $filename = $video['fid'] . '_' . sprintf('%04d', $i) . '.png';
    $thumbfile = $final_thumb_path . '/' . $filename;
    if (!$complete) {
      $default = drupal_get_path('module', 'video') . '/images/no-thumb.png';
      $thumbfile = video_thumb_path(NULL, FALSE) . '/no-thumb.png';

      // The default file is shared between videos
      if (!is_file($thumbfile)) {
        file_copy($default, $thumbfile, FILE_EXISTS_REPLACE);
      }
    }
    elseif (!is_file($thumbfile)) {
      break;
    }

    // Begin building the file object.
    $file = new stdClass();
    $file->uid = $user->uid;
    $file->status = FILE_STATUS_TEMPORARY;
    $file->filename = $filename;
    $file->filepath = $thumbfile;
    $file->filemime = 'image/png';
    $file->filesize = filesize($thumbfile);
    $file->timestamp = time();
    $files[] = $file;
  }
  return $files;
}