You are here

public function PHPVideoToolkit::setVideoDimensions in Video 7.2

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

Sets the video output dimensions (in pixels)

@access public

Parameters

mixed $width If an integer height also has to be specified, otherwise you can use one of the class constants: PHPVideoToolkit::SIZE_SAS = Same as input source PHPVideoToolkit::SIZE_SQCIF = 128 x 96 PHPVideoToolkit::SIZE_QCIF = 176 x 144 PHPVideoToolkit::SIZE_CIF = 352 x 288 PHPVideoToolkit::SIZE_4CIF = 704 x 576 PHPVideoToolkit::SIZE_QQVGA = 160 x 120 PHPVideoToolkit::SIZE_QVGA = 320 x 240 PHPVideoToolkit::SIZE_VGA = 640 x 480 PHPVideoToolkit::SIZE_SVGA = 800 x 600 PHPVideoToolkit::SIZE_XGA = 1024 x 768 PHPVideoToolkit::SIZE_UXGA = 1600 x 1200 PHPVideoToolkit::SIZE_QXGA = 2048 x 1536 PHPVideoToolkit::SIZE_SXGA = 1280 x 1024 PHPVideoToolkit::SIZE_QSXGA = 2560 x 2048 PHPVideoToolkit::SIZE_HSXGA = 5120 x 4096 PHPVideoToolkit::SIZE_WVGA = 852 x 480 PHPVideoToolkit::SIZE_WXGA = 1366 x 768 PHPVideoToolkit::SIZE_WSXGA = 1600 x 1024 PHPVideoToolkit::SIZE_WUXGA = 1920 x 1200 PHPVideoToolkit::SIZE_WOXGA = 2560 x 1600 PHPVideoToolkit::SIZE_WQSXGA = 3200 x 2048 PHPVideoToolkit::SIZE_WQUXGA = 3840 x 2400 PHPVideoToolkit::SIZE_WHSXGA = 6400 x 4096 PHPVideoToolkit::SIZE_WHUXGA = 7680 x 4800 PHPVideoToolkit::SIZE_CGA = 320 x 200 PHPVideoToolkit::SIZE_EGA = 640 x 350 PHPVideoToolkit::SIZE_HD480 = 852 x 480 PHPVideoToolkit::SIZE_HD720 = 1280 x 720 PHPVideoToolkit::SIZE_HD1080 = 1920 x 1080

integer $height:

Return value

boolean

1 call to PHPVideoToolkit::setVideoDimensions()
PHPVideoToolkit::execute in libraries/phpvideotoolkit/phpvideotoolkit.php5.php
Commits all the commands and executes the ffmpeg procedure. This will also attempt to validate any outputted files in order to provide some level of stop and check system.

File

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

Class

PHPVideoToolkit

Code

public function setVideoDimensions($width = PHPVideoToolkit::SIZE_SAS, $height = NULL) {
  if ($height === NULL || $height === TRUE) {

    //				validate input
    if (!in_array($width, array(
      self::SIZE_SAS,
      self::SIZE_SQCIF,
      self::SIZE_QCIF,
      self::SIZE_CIF,
      self::SIZE_4CIF,
      self::SIZE_QQVGA,
      self::SIZE_QVGA,
      self::SIZE_VGA,
      self::SIZE_SVGA,
      self::SIZE_XGA,
      self::SIZE_UXGA,
      self::SIZE_QXGA,
      self::SIZE_SXGA,
      self::SIZE_QSXGA,
      self::SIZE_HSXGA,
      self::SIZE_WVGA,
      self::SIZE_WXGA,
      self::SIZE_WSXGA,
      self::SIZE_WUXGA,
      self::SIZE_WOXGA,
      self::SIZE_WQSXGA,
      self::SIZE_WQUXGA,
      self::SIZE_WHSXGA,
      self::SIZE_WHUXGA,
      self::SIZE_CGA,
      self::SIZE_EGA,
      self::SIZE_HD480,
      self::SIZE_HD720,
      self::SIZE_HD1080,
    ))) {
      return $this
        ->_raiseError('setVideoOutputDimensions_valid_format', array(
        'format' => $format,
      ));

      // <-				exits
    }
    if ($width === self::SIZE_SAS) {

      // 					and override is made so no command is added in the hope that ffmpeg will just output the source
      if ($height === TRUE) {
        return TRUE;
      }

      // 					get the file info
      $info = $this
        ->getFileInfo();
      if (isset($info['video']) === FALSE || isset($info['video']['dimensions']) === FALSE) {
        return $this
          ->_raiseError('setVideoOutputDimensions_sas_dim');
      }
      else {
        $w = $info['video']['dimensions']['width'];
        $h = $info['video']['dimensions']['height'];
        $hor_pad = $this
          ->checkVideoSize($w, $this->width_multiple);
        $ver_pad = $this
          ->checkVideoSize($h, $this->height_multiple);
        $width = $w . 'x' . $h;
      }
    }
  }
  else {
    $height_split = explode(' ', $height);

    // 				check that the width and height are even
    if ($width % 2 !== 0 || $height_split[0] % 2 !== 0) {
      return $this
        ->_raiseError('setVideoOutputDimensions_valid_integer');

      // <-				exits
    }
    $hor_pad = $this
      ->checkVideoSize($width, $this->width_multiple);
    $ver_pad = $this
      ->checkVideoSize($height_split[0], $this->height_multiple);
    $width = $width . 'x' . $height_split[0];
  }
  $this
    ->addCommand('-s', $width);
  if (isset($height_split) && count($height_split) > 1) {
    $commands = $height_split;
    array_shift($commands);
    $commands = implode(' ', $commands);
    preg_match_all('/-(\\S*)\\s(\\S*)/', $commands, $matches);
    foreach ($matches[0] as $match) {
      $command = explode(' ', $match);
      if (count($command) == 2) {
        $command[0] = preg_replace('/\\"/', '', $command[0]);
        $command[1] = preg_replace('/\\"/', '', $command[1]);
        $this
          ->addCommand($command[0], $command[1]);
      }
    }
  }
  if ($hor_pad) {
    $this
      ->addCommand('-padleft', $hor_pad);
    $this
      ->addCommand('-padright', $hor_pad);
  }
  if ($ver_pad) {
    $this
      ->addCommand('-padtop', $ver_pad);
    $this
      ->addCommand('-padbottom', $ver_pad);
  }
  return TRUE;
}