From 11b728bf4afa17fba43ced33e6c6a3408cc22cb9 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 6 Dec 2023 10:34:39 +0900 Subject: [PATCH] Fix video aspect ratio when ffprobe returns rotation data in side_data_list https://xetown.com/questions/1789336 --- modules/file/file.controller.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index bb2dece03..17c8ad602 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -1379,17 +1379,26 @@ class FileController extends File return $file_info; } - // Get video size and duration + // Check if video needs to be rotated + $rotate = false; if (isset($stream_info['video']['tags']['rotate']) && in_array($stream_info['video']['tags']['rotate'], [90, 270])) { - $file_info['width'] = (int)$stream_info['video']['height']; - $file_info['height'] = (int)$stream_info['video']['width']; + $rotate = true; } - else + elseif (isset($stream_info['video']['side_data_list']) && is_array($stream_info['video']['side_data_list'])) { - $file_info['width'] = (int)$stream_info['video']['width']; - $file_info['height'] = (int)$stream_info['video']['height']; + foreach ($stream_info['video']['side_data_list'] as $side_data) + { + if (isset($side_data['rotation']) && in_array(abs($side_data['rotation']), [90, 270])) + { + $rotate = true; + } + } } + + // Get video size and duration + $file_info['width'] = intval($rotate ? $stream_info['video']['height'] : $stream_info['video']['width']); + $file_info['height'] = intval($rotate ? $stream_info['video']['width'] : $stream_info['video']['height']); $file_info['duration'] = round($stream_info['video']['duration']); $adjusted = [ 'width' => $file_info['width'],