Skip to content

Commit

Permalink
support rotated video dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Jan 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 151cc7b commit 07ad5f1
Showing 4 changed files with 42 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/Helpers/Video.php
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion tests/Unit/FileTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Finller\Media\Helpers\File;
use Finller\Media\Helpers\Video;
use Illuminate\Http\UploadedFile;

it('get the correct name from Uploaded file', function () {
@@ -10,4 +11,4 @@
$name = File::name($file);

expect($name)->toBe('foo');
});
});
25 changes: 25 additions & 0 deletions tests/Unit/VideoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Finller\Media\Helpers\File;
use Finller\Media\Helpers\Video;
use Illuminate\Http\UploadedFile;

it('get the correct dimention from a non rotated video', function () {

$file = $this->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);
});
Binary file added tests/files/videos/90rotation.mp4
Binary file not shown.

0 comments on commit 07ad5f1

Please sign in to comment.