You are here

public function PHPVideoToolkit::setOutput in Video 7.2

Same name and namespace in other branches
  1. 7 libraries/phpvideotoolkit/phpvideotoolkit.php5.php \PHPVideoToolkit::setOutput()

Sets the output.

@access public

Parameters

string $output_directory The directory to output the command output to:

string $output_name The filename to output to.: (Note; if you are outputting frames from a video then you will need to add an extra item to the output_name. The output name you set is required to contain '%d'. '%d' is replaced by the image number. Thus entering setting output_name $output_name='img%d.jpg' will output 'img1.jpg', 'img2.jpg', etc... However 'img%03d.jpg' generates `img001.jpg', `img002.jpg', etc...)

boolean $overwrite_mode Accepts one of the following class constants: - PHPVideoToolkit::OVERWRITE_FAIL - This produces an error if there is a file conflict and the processing is halted. - PHPVideoToolkit::OVERWRITE_PRESERVE - This continues with the processing but no file overwrite takes place. The processed file is left in the temp directory for you to manually move. - PHPVideoToolkit::OVERWRITE_EXISTING - This will replace any existing files with the freshly processed ones. - PHPVideoToolkit::OVERWRITE_UNIQUE - This will appended every output with a unique hash so that the filesystem is preserved.

Return value

boolean FALSE on error encountered, TRUE otherwise

File

libraries/phpvideotoolkit/phpvideotoolkit.php5.php, line 2269
Libary to access FFmpeg

Class

PHPVideoToolkit

Code

public function setOutput($output_directory, $output_name, $overwrite_mode = PHPVideoToolkit::OVERWRITE_FAIL) {

  //			check if directoy exists
  if (!is_dir($output_directory)) {
    return $this
      ->_raiseError('setOutput_output_dir_404', array(
      'dir' => $output_directory,
    ));

    // <-			exits
  }

  //			check if directory is writeable
  if (!is_writable($output_directory)) {
    return $this
      ->_raiseError('setOutput_output_dir_writable', array(
      'dir' => $output_directory,
    ));

    // <-			exits
  }
  $process_name = '';

  //			check to see if a output delimiter is set
  $has_d = preg_match('/\\%([0-9]+)d/', $output_name) || strpos($output_name, '%d') !== FALSE;
  if ($has_d) {
    return $this
      ->_raiseError('setOutput_%d_depreciated');

    // <-			exits
  }
  else {

    //				determine if the extension is an image. If it is then we will be extracting frames so check for %d
    $output_name_info = pathinfo($output_name);
    $is_image = in_array(strtolower($output_name_info['extension']), array(
      'jpg',
      'jpeg',
      'png',
    ));
    $is_gif = strtolower($output_name_info['extension']) === 'gif';

    //				NOTE: for now we'll just stick to the common image formats, SUBNOTE: gif is ignore because ffmpeg can create animated gifs
    if ($this->_single_frame_extraction !== NULL && strpos($output_name, '%timecode') === FALSE && !(preg_match('/\\%index/', $output_name) || strpos($output_name, '%index') !== FALSE) && $is_image) {

      // return $this->_raiseError('setOutput_%_missing');
      // <-				exits
    }
    $process_name = '.' . $output_name_info['extension'];
    if ($is_image || $this->_single_frame_extraction !== NULL && $is_gif) {
      $process_name = '-%12d' . $process_name;
    }
  }

  //			set the output address
  $this->_output_address = $output_directory . $output_name;

  // 			set the processing address in the temp folder so it does not conflict with any other conversions
  $this->_process_address = $this->_tmp_directory . $this
    ->unique() . $process_name;
  $this->_overwrite_mode = $overwrite_mode;
  return TRUE;
}