public function video_ffmpeg::dimensions in Video 7
Same name and namespace in other branches
- 6.4 transcoders/video_ffmpeg.inc \video_ffmpeg::dimensions()
1 call to video_ffmpeg::dimensions()
- video_ffmpeg::convert_video in transcoders/video_ffmpeg.inc
File
- transcoders/video_ffmpeg.inc, line 539
Class
- video_ffmpeg
Code
public function dimensions($video) {
$aspect_ratio = _video_aspect_ratio(drupal_realpath($video->uri));
$ratio = $aspect_ratio['ratio'];
$width = $aspect_ratio['width'];
$height = $aspect_ratio['height'];
$wxh = explode('x', $video->dimensions);
$output_width = $wxh[0];
$output_height = $wxh[1];
$output_ratio = number_format($output_width / $output_height, 4);
if ($output_ratio != $ratio && $width && $height) {
$options = array();
if ($ratio < $output_width / $output_height) {
$end_width = $output_height * $ratio;
$end_height = $output_height;
}
else {
$end_height = $output_width / $ratio;
$end_width = $output_width;
}
if ($end_width == $output_width) {
$padding = round($output_height - $end_height);
$pad1 = $pad2 = floor($padding / 2);
if ($pad1 % 2 !== 0) {
$pad1++;
$pad2--;
}
if (variable_get('video_ffmpeg_pad_method', 0)) {
$options[] = '-vf "pad=' . round($output_width) . ':' . round($output_height) . ':0:' . $pad1 . '"';
}
else {
$options[] = '-padtop ' . $pad1;
$options[] = '-padbottom ' . $pad2;
}
}
else {
$padding = round($output_width - $end_width);
$pad1 = $pad2 = floor($padding / 2);
if ($pad1 % 2 !== 0) {
$pad1++;
$pad2--;
}
if (variable_get('video_ffmpeg_pad_method', 0)) {
$options[] = '-vf "pad=' . round($output_width) . ':' . round($output_height) . ':' . $pad1 . ':0"';
}
else {
$options[] = '-padleft ' . $pad1;
$options[] = '-padright ' . $pad2;
}
}
$end_width = round($end_width) % 2 !== 0 ? round($end_width) + 1 : round($end_width);
$end_height = round($end_height) % 2 !== 0 ? round($end_height) + 1 : round($end_height);
array_unshift($options, $end_width . 'x' . $end_height);
return implode(' ', $options);
}
else {
return $video->dimensions;
}
}