You are here

function video_render_main in Video 6.2

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.3 video_scheduler.php \video_render_main()
1 call to video_render_main()
video_render.php in plugins/video_ffmpeg_helper/video_render.php
Renders a video. This script is called concurrently by video_scheduler.php This script has to be launched with "php video_render.php nid vid" If you are not using sites/default/settings.php as your settings file, add an optional parameter…

File

plugins/video_ffmpeg_helper/video_render.php, line 79
Renders a video. This script is called concurrently by video_scheduler.php This script has to be launched with "php video_render.php nid vid" If you are not using sites/default/settings.php as your settings file, add an optional parameter…

Code

function video_render_main() {

  // get parameters passed from command line
  $nid = $_SERVER['argv'][1];
  $vid = $_SERVER['argv'][2];

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

  // load the job object
  $job = _video_render_load_job($nid, $vid, VIDEO_RENDERING_ACTIVE);
  if ($job == NULL) {
    watchdog('video_render', 'video_render.php has been called with an invalid job resource. exiting.');
    die;
  }
  $command = _video_render_get_command($job);

  //print('executing ' . $command); die;
  watchdog('video_render', 'executing: ' . $command);

  //execute the command
  ob_start();
  passthru($command . " 2>&1", $command_return);
  $command_output = ob_get_contents();
  ob_end_clean();

  //print $command_output;
  if (!file_exists($job->convfile) || !filesize($job->convfile)) {
    watchdog('video_render', 'video conversion failed. ffmpeg reported the following output: ' . $command_output, WATCHDOG_ERROR);
    _video_render_set_video_encoded_fid($job->nid, $job->vid, -1);
    _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_FAILED);
  }
  else {

    // move the video to the definitive location
    $file = array(
      'filename' => basename($job->origfile . ".flv"),
      'filemime' => 'application/octet-stream',
      // is there something better???
      'filesize' => filesize($job->convfile),
      'filepath' => $job->convfile,
      'nid' => $job->nid,
    );
    $file = (object) $file;

    //print_r($file);

    //$dest_dir = variable_get('video_upload_default_path', 'videos') .'/';

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

      //$file->fid = db_next_id('{files}_fid');

      //print_r($file);

      //GMM: fixed added timestamp column for completeness (otherwise 0), D6 FILE_STATUS
      if (!$file->fid) {
        db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $job->uid, $file->filename, $file->filepath, $file->filemime, $file->filesize, FILE_STATUS_PERMANENT, time());
      }
      else {
        db_query("INSERT INTO {files} (fid, uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, %d, '%s', '%s', '%s', %d, %d, %d)", $file->fid, $job->uid, $file->filename, $file->filepath, $file->filemime, $file->filesize, FILE_STATUS_PERMANENT, time());
      }

      // to know other modules of fid
      $file->fid = db_last_insert_id('files', 'fid');
      db_query("INSERT INTO {video_upload} (vid, nid, fid) VALUES (%d, %d, %d)", $job->vid, $job->vid, $file->fid);

      // update the video table
      db_query('UPDATE {video} SET vidfile = \'%s\', videox = %d, videoy = %d WHERE nid=%d AND vid=%d', "", $job->calculatedx, $job->calculatedy, $job->nid, $job->vid);

      // update the video_encoded_fid in video serial data
      _video_render_set_video_encoded_fid($job->nid, $job->vid, $file->fid);
      _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_COMPLETE);
      watchdog('video_render', 'successfully converted %orig to %dest', array(
        '%orig' => $job->origfile,
        '%dest' => $file->filepath,
      ));

      // delete the temp file
      unlink($job->convfile);
    }
    else {

      // 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);
      _video_render_set_video_encoded_fid($job->nid, $job->vid, -1);
      _video_render_job_change_status($job->nid, $job->vid, VIDEO_RENDERING_FAILED);
    }
  }
}