You are here

class video_conversion in Video 6.4

Same name and namespace in other branches
  1. 7 includes/conversion.inc \video_conversion

Hierarchy

Expanded class hierarchy of video_conversion

1 string reference to 'video_conversion'
video_conversion::render in includes/conversion.inc

File

includes/conversion.inc, line 17

View source
class video_conversion {
  protected $transcoder;
  public function __construct() {
    module_load_include('inc', 'video', '/includes/transcoder');
    $this->transcoder = new video_transcoder();
  }

  /**
   * Our main function to call when converting queued up jobs.
   */
  public function run_queue() {
    if ($videos = $this
      ->load_job_queue()) {
      foreach ($videos as $video) {
        $this
          ->process($video);
      }

      //clear cache once completed the conversion to update the file paths
      cache_clear_all('*', 'cache_content', true);
    }
  }

  /**
   * Select videos from our queue
   *
   * @return
   *   An array containing all the videos to be proccessed.
   */
  private function load_job_queue() {

    // @TODO : allow only limited jobs to process
    return $this->transcoder
      ->load_job_queue();
  }

  /**
   * Process the video through ffmpeg.
   *
   * @param $video
   *   This can either be the file object or the file id (fid)
   *
   * @return
   *   TRUE of FALSE if video was converted successfully.
   */
  public function process($video) {
    if (is_object($video) && isset($video->fid)) {
      $return = $this
        ->render($video);
    }
    else {
      $video_object = $this
        ->load_job($video);
      $return = $this
        ->render($video_object);
    }
    return $return;
  }
  private function render($video) {
    if (!is_object($video)) {
      watchdog('video_conversion', 'Video object is not present', array(), WATCHDOG_ERROR);
      return FALSE;
    }

    // Make sure this video is pending or do nothing.
    if ($video->video_status == VIDEO_RENDERING_PENDING) {
      return $this->transcoder
        ->convert_video($video);
    }
    return NULL;
  }

  /**
   * Load a converted video based on the file id ($fid)
   *
   * @todo: Need to figure something out here for multiple files (HTML 5)
   * @param $fid
   *   Integer of the file id to be loaded.
   */
  public function load_completed_job($video) {
    return $this->transcoder
      ->load_completed_job($video);
  }
  public function create_job($video) {
    return $this->transcoder
      ->create_job($video);
  }
  public function update_job($video) {
    return $this->transcoder
      ->update_job($video);
  }
  public function delete_job($video) {
    return $this->transcoder
      ->delete_job($video);
  }

  /**
   * Load a file based on the file id ($fid)
   *
   * @param $fid
   *   Integer of the file id to be loaded.
   */
  public function load_job($fid) {
    return $this->transcoder
      ->load_job($fid);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
video_conversion::$transcoder protected property
video_conversion::create_job public function
video_conversion::delete_job public function
video_conversion::load_completed_job public function Load a converted video based on the file id ($fid)
video_conversion::load_job public function Load a file based on the file id ($fid)
video_conversion::load_job_queue private function Select videos from our queue
video_conversion::process public function Process the video through ffmpeg.
video_conversion::render private function
video_conversion::run_queue public function Our main function to call when converting queued up jobs.
video_conversion::update_job public function
video_conversion::__construct public function