You are here

function video_render_main in Video 6.3

Same name and namespace in other branches
  1. 5 plugins/video_ffmpeg_helper/video_render.php \video_render_main()
  2. 6 plugins/video_ffmpeg_helper/video_render.php \video_render_main()
  3. 6.2 plugins/video_ffmpeg_helper/video_render.php \video_render_main()

Video Rendering Process

1 call to video_render_main()
video_scheduler_start in ./video_scheduler.php
Starts rendering for a job

File

./video_scheduler.php, line 119
Implement video rendering scheduling. If you are not using sites/default/settings.php as your settings file, add an optional parameter for the drupal site url: "php video_scheduler.php http://example.com/" or "php video_scheduler.php…

Code

function video_render_main($job_fid) {

  // get parameters passed from command line
  $fid = $job_fid;
  $job = NULL;

  // set the status to active
  _video_render_job_change_status($fid, VIDEO_RENDERING_ACTIVE);

  // load the job object
  $job = _video_render_load_job($fid);
  if (empty($job)) {
    watchdog('video_render', 'video_render.php has been called with an invalid job resource. exiting.', array(), WATCHDOG_ERROR);
    die;
  }

  // get file object
  _video_render_get_converted_file($job);
  $file = $job->converted;
  if (empty($file)) {
    watchdog('video_render', 'converted file is an empty file.', array(), WATCHDOG_ERROR);
    _video_render_job_change_status($fid, VIDEO_RENDERING_FAILED);
    die;
  }
  $tmpfile = $file->filepath;

  // the above no more works as token supports - use dirname
  $dest_dir = dirname($job->filepath) . '/';
  if (file_copy($file, $dest_dir)) {

    //update the file table entry and copy file content to new one
    $file->fid = $fid;

    //update file with new
    drupal_write_record('files', $file, 'fid');

    //add new file entry
    drupal_write_record('files', $job);

    // TODO : add data of rendering
    _video_render_job_change_status($fid, VIDEO_RENDERING_COMPLETE);

    // clear all cacahe data
    // cache_clear_all();
    // drupal_flush_all_caches();
    cache_clear_all("*", 'cache_content', true);
    watchdog('video_render', 'successfully converted %orig to %dest', array(
      '%orig' => $job->filepath,
      '%dest' => $file->filepath,
    ), WATCHDOG_INFO);

    // delete the temp file
    //    unlink($tmpfile);
  }
  else {
    _video_render_job_change_status($fid, VIDEO_RENDERING_FAILED);

    // get the username of the process owner
    $ownerarray = posix_getpwuid(posix_getuid());
    $owner = $ownerarray['name'];

    // get the username of the destination folder owner
    $fownerarray = posix_getpwuid(fileowner($dest_dir));
    $fowner = $fownerarray['name'];

    // get destination folder permissions
    $perms = substr(sprintf('%o', fileperms($dest_dir)), -4);
    watchdog('video_render', 'error moving video %vid_file with nid = %nid to %dir the final directory. Check folder permissions.<br />The script was run by %uname .<br />The folder owner is %fowner .<br />The folder permissions are %perms .', array(
      '%vid_file' => $job->origfile,
      '%nid' => $job->nid,
      '%dir' => $dest_dir,
      '%uname' => $owner,
      '%fowner' => $fowner,
      '%perms' => $perms,
    ), WATCHDOG_ERROR);
  }
}