diff --git a/src/Helpers/Video.php b/src/Helpers/Video.php index 903c8aa..1dd09ea 100644 --- a/src/Helpers/Video.php +++ b/src/Helpers/Video.php @@ -16,11 +16,21 @@ public static function dimension(string $path): Dimension 'ffprobe.binaries' => config('laravel-ffmpeg.ffprobe.binaries'), ]); - return $file - ->streams($path) - ->videos() - ->first() - ->getDimensions(); + $stream = $file + ->streams($path) + ->videos() + ->first(); + + $dimension = $stream->getDimensions(); + + /** @var int */ + $rotation = data_get($stream->get('side_data_list'), '0.rotation', 0); + + if((abs($rotation) / 90) % 2 === 1){ + $dimension = new Dimension($dimension->getHeight(), $dimension->getWidth()); + } + + return $dimension; } public static function ratio(string $path, bool $forceStandards = true): AspectRatio diff --git a/tests/Unit/FileTest.php b/tests/Unit/FileTest.php index d742651..d211885 100644 --- a/tests/Unit/FileTest.php +++ b/tests/Unit/FileTest.php @@ -1,6 +1,7 @@ toBe('foo'); -}); +}); \ No newline at end of file diff --git a/tests/Unit/VideoTest.php b/tests/Unit/VideoTest.php new file mode 100644 index 0000000..2d2f1d6 --- /dev/null +++ b/tests/Unit/VideoTest.php @@ -0,0 +1,25 @@ +getTestFile('videos/horizontal.mp4'); + + $dimension = Video::dimension($file); + + expect($dimension->getHeight())->toBe(720); + expect($dimension->getWidth())->toBe(1280); +}); + +it('get the correct dimention from a rotated video', function () { + + $file = $this->getTestFile('videos/90rotation.mp4'); + + $dimension = Video::dimension($file); + + expect($dimension->getHeight())->toBe(1920); + expect($dimension->getWidth())->toBe(1080); +}); \ No newline at end of file diff --git a/tests/files/videos/90rotation.mp4 b/tests/files/videos/90rotation.mp4 new file mode 100644 index 0000000..13bfe21 Binary files /dev/null and b/tests/files/videos/90rotation.mp4 differ