You are here

public function video_localcommand::getDimensionParameters in Video 6.5

Function determines the dimensions you want and compares with the actual wxh of the video.

If they are not exact or the aspect ratio does not match, we then figure out how much padding we should add. We will either add a black bar on the top/bottom or on the left/right.

The output width and height are divisible by two

1 call to video_localcommand::getDimensionParameters()
video_localcommand::convert_video in transcoders/video_localcommand.inc
Convert the given video.

File

transcoders/video_localcommand.inc, line 411

Class

video_localcommand

Code

public function getDimensionParameters(stdClass $video, array $sourcedimensions) {
  $wxh = explode('x', $video->dimensions, 2);
  $outputwidth = intval($wxh[0]);
  $outputheight = intval($wxh[1]);
  $outputratio = _video_aspect_ratio($outputwidth, $outputheight);
  $options = new stdClass();
  $options->paddingleft = 0;
  $options->paddingright = 0;
  $options->paddingtop = 0;
  $options->paddingbottom = 0;
  $options->width = intval(round($outputwidth / 2) * 2);
  $options->height = intval(round($outputheight / 2) * 2);
  $options->paddingwidth = $options->width;
  $options->paddingheight = $options->height;
  $filewidth = $sourcedimensions['width'];
  $fileheight = $sourcedimensions['height'];
  $fileratio = _video_aspect_ratio($filewidth, $fileheight);

  // If the input ratio is not equal to the output ratio
  if ($outputratio != $fileratio && $filewidth && $fileheight) {
    if ($fileratio < $outputratio) {

      // The input file is narrower than the output file
      // Change the output width proportionally
      $options->width = intval(round($filewidth * $outputheight / $fileheight / 2) * 2);

      // Determine left and right padding
      $padding = $outputwidth - $options->width;
      $options->paddingleft = intval(floor($padding / 2));
      $options->paddingright = intval(ceil($padding / 2));
    }
    else {

      // The input file is wider than the output file
      // Change the output height proportionally
      $options->height = intval(round($fileheight * $outputwidth / $filewidth / 2) * 2);

      // Determine top and bottom padding
      $padding = $outputheight - $options->height;
      $options->paddingtop = intval(floor($padding / 2));
      $options->paddingbottom = intval(ceil($padding / 2));
    }
  }
  return $options;
}