Skip to content

Commit d800be9

Browse files
committed
prevent height not divisible by 2
1 parent b751b09 commit d800be9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/Definitions/MediaConversionPoster.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Elegantly\Media\Enums\MediaType;
99
use Elegantly\Media\Models\Media;
1010
use Elegantly\Media\Models\MediaConversion;
11+
use FFMpeg\Coordinate\TimeCode;
1112
use Illuminate\Contracts\Filesystem\Filesystem;
1213
use ProtoneMedia\LaravelFFMpeg\Support\FFMpeg;
1314
use Spatie\Image\Enums\Fit;
@@ -26,7 +27,7 @@ public function __construct(
2627
public ?string $queue = null,
2728
public array $conversions = [],
2829
public ?string $fileName = null,
29-
public float $seconds = 0.0,
30+
public TimeCode|float $seconds = 0.0,
3031
public ?int $width = null,
3132
public ?int $height = null,
3233
public Fit $fit = Fit::Contain,
@@ -69,7 +70,11 @@ public function handle(
6970

7071
FFMpeg::fromFilesystem($filesystem)
7172
->open($file)
72-
->getFrameFromSeconds($this->seconds)
73+
->getFrameFromTimecode(
74+
is_float($this->seconds)
75+
? TimeCode::fromSeconds($this->seconds)
76+
: $this->seconds
77+
)
7378
->export()
7479
->save($fileName);
7580

src/Definitions/MediaConversionVideo.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ public function handle(
7373

7474
$ratio = new AspectRatio($source->aspect_ratio);
7575

76-
$width = $this->width;
77-
$height = $this->height;
76+
$modulus = match (true) {
77+
$this->format instanceof X264 => 2, // dimensions must be divisible by 2
78+
default => 1,
79+
};
7880

79-
if ($width && ! $height) {
80-
$height = $ratio->calculateHeight($width);
81-
} elseif ($height && ! $width) {
82-
$width = $ratio->calculateWidth($height);
83-
}
81+
$width = $this->width ?? ($this->height ? $ratio->calculateWidth($this->height, $modulus) : null);
82+
$height = $this->height ?? ($this->width ? $ratio->calculateHeight($this->width, $modulus) : null);
8483

8584
$ffmpeg = FFMpeg::fromFilesystem($filesystem)
8685
->open($file)

0 commit comments

Comments
 (0)