Skip to content

Commit 9d9f267

Browse files
committed
fix video duration
1 parent b8bf5e1 commit 9d9f267

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

src/FFMpeg/Video.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,9 @@ public function duration(string $input): float
6161
{
6262
$metadata = $this->metadata($input);
6363

64-
if ($stream = $metadata['streams'][0] ?? null) {
65-
66-
// @phpstan-ignore-next-line
67-
$duration = (float) data_get($stream, 'duration');
64+
$duration = (float) data_get($metadata, 'format.duration');
6865

69-
return $duration * 1_000;
70-
}
71-
72-
throw VideoStreamNotFoundException::atPath($input);
66+
return $duration * 1_000;
7367
}
7468

7569
/**

tests/Feature/Converters/MediaMp4ConverterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
expect($conversion)->toBeInstanceOf(MediaConversion::class);
2323
expect($conversion->width)->toBe(10);
2424
expect($conversion->extension)->toBe('mp4');
25+
expect(round($conversion->duration))->toBe(2763.0);
2526

2627
});
2728

tests/Feature/Converters/MediaWebmConverterTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
expect($conversion)->toBeInstanceOf(MediaConversion::class);
2323
expect($conversion->width)->toBe(10);
2424
expect($conversion->extension)->toBe('webm');
25-
25+
expect(round($conversion->duration))->toBe(2740.0);
2626
});
2727

2828
it('converts and resizes a gif into a webm', function () {
@@ -41,5 +41,4 @@
4141
expect($conversion)->toBeInstanceOf(MediaConversion::class);
4242
expect($conversion->width)->toBe(10);
4343
expect($conversion->extension)->toBe('webm');
44-
4544
});

tests/Unit/VideoTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
expect($dimension?->width)->toBe(1080);
2525
});
2626

27-
it('get the correct duration of a video', function () {
27+
it('get the correct duration of an mp4 video', function () {
2828

2929
$file = $this->getTestFile('videos/horizontal.mp4');
3030

3131
$duration = Video::duration($file);
3232

33-
expect($duration)->toBe(2736.067);
33+
expect(round($duration))->toBe(2763.0);
3434
});

0 commit comments

Comments
 (0)