You are here

function video_convert_process in Video 6.4

Same name and namespace in other branches
  1. 6.5 video_widget.inc \video_convert_process()

Adds a video to the video rendering table.

If auto converting, it will convert your video to flv right now. We are passing the element by reference just in case we ever want to add more to the element during this process.

Parameters

array $element Form element to get the video file from.:

1 call to video_convert_process()
video_widget_process in ./video_widget.inc
Video_widget_process for API handlers for any video types.

File

./video_widget.inc, line 219
Common widget functions

Code

function video_convert_process(&$element) {
  $file = $element['#value'];

  // If the dimensions #value is empty, it is probably because the user
  // clicked the Save button directly and did not choose dimensions.
  // Take the default dimensions.
  if (empty($file['data']['dimensions']) && isset($element['data']['dimensions'])) {
    $file['data']['dimensions'] = $element['data']['dimensions']['#default_value'];
  }
  if (!empty($file['fid']) && empty($file['data']['bypass_autoconversion'])) {
    $convert = false;
    $fid = $file['fid'];

    //setup our conversion class and check for the fid existence.
    module_load_include('inc', 'video', '/includes/conversion');
    $video_conversion = new video_conversion();

    // Lets verify that we haven't added this video already.  Multiple validation fails will cause this to be ran more than once
    if (!($video = $video_conversion
      ->load_job($fid))) {

      // Video has not been added to the queue yet so lets add it.
      $video = array(
        'fid' => $fid,
        'dimensions' => $file['data']['dimensions'],
      );
      if (!$video_conversion
        ->create_job($video)) {
        drupal_set_message(t('Something went wrong with your video job creation.  Please check your recent log entries for further debugging.'), 'error');
      }
      $convert = true;

      //lets queue our node status to unpublished.
      $element['#unpublish'] = true;
    }
    elseif ($video->video_status != VIDEO_RENDERING_COMPLETE) {

      //lets queue our node status to unpublished.
      $element['#unpublish'] = true;
    }

    // Our video should be in the database pending, lets see if we need to convert it now.
    // Check if we are going from unselected to selected or if this is a new video and we have checked the checkbox
    $convert_video_on_save = false;
    $element_data_convert_on_save = '';
    $file_date_convet_on_save = '';
    $convert_on_save = variable_get('video_convert_on_save', FALSE);
    if (isset($element['data']['convert_video_on_save']['#value'])) {
      $element_data_convert_on_save = $element['data']['convert_video_on_save']['#value'];
    }
    if (isset($file['data']['convert_video_on_save'])) {
      $file_date_convet_on_save = $file['data']['convert_video_on_save'];
    }
    $convert_video_on_save = $element_data_convert_on_save || $file_date_convet_on_save;
    if ((!isset($element['#default_value']['data']['convert_video_on_save']) || !$element['#default_value']['data']['convert_video_on_save']) && $convert_video_on_save || $convert && $convert_video_on_save || $convert_on_save) {
      $return = $video_conversion
        ->process($fid);
      if ($return === FALSE) {
        drupal_set_message(t('Something went wrong with your video conversion.  Please check your recent log entries for further debugging.'), 'error');
      }
      elseif ($return === TRUE) {

        //we are always unpublished until we are converted.
        unset($element['#unpublish']);
        drupal_set_message(t('Successfully converted your video.'));
      }
    }
    elseif ($convert) {
      drupal_set_message(t('Video submission queued for processing. Please wait: our servers are preparing your video for display.'));
    }
  }
}