Skip to content

Commit

Permalink
fix nullable stream when getting dimensions of video
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Jan 26, 2024
1 parent b5f3d2a commit 5cc8cfb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Helpers/HasDimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

interface HasDimension
{
public static function dimension(string $path): Dimension;
public static function dimension(string $path): ?Dimension;

public static function ratio(string $path, bool $forceStandards = true): AspectRatio;
public static function ratio(string $path, bool $forceStandards = true): ?AspectRatio;
}
10 changes: 7 additions & 3 deletions src/Helpers/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class Video implements HasDimension
{
public static function dimension(string $path): Dimension
public static function dimension(string $path): ?Dimension
{
$file = FFProbe::create([
'ffmpeg.binaries' => config('laravel-ffmpeg.ffmpeg.binaries'),
Expand All @@ -21,6 +21,10 @@ public static function dimension(string $path): Dimension
->videos()
->first();

if (! $stream) {
return null;
}

$dimension = $stream->getDimensions();

/** @var int */
Expand All @@ -33,9 +37,9 @@ public static function dimension(string $path): Dimension
return $dimension;
}

public static function ratio(string $path, bool $forceStandards = true): AspectRatio
public static function ratio(string $path, bool $forceStandards = true): ?AspectRatio
{
return static::dimension($path)->getRatio($forceStandards);
return static::dimension($path)?->getRatio($forceStandards);
}

public static function duration(string $path): float
Expand Down

0 comments on commit 5cc8cfb

Please sign in to comment.