Skip to content

A self-hosted media server and file management system

feat: storyboard options tests

aminnausin32f94caaaf90
diff --git a/app/Jobs/Metadata/GenerateStoryboard.php b/app/Jobs/Metadata/GenerateStoryboard.php
index 4822b2d2..fbdcb1f2 100644
--- a/app/Jobs/Metadata/GenerateStoryboard.php
+++ b/app/Jobs/Metadata/GenerateStoryboard.php
@@ -11,6 +11,7 @@ use App\Models\SubTask;
use App\Services\Ffmpeg\FFmpegCommandBuilder;
use App\Services\Images\Storyboard\StoryboardOptions;
use App\Services\TaskService;
+use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -91,7 +92,12 @@ class GenerateStoryboard extends ManagedSubTask {
$metadata->load('video');
$filePath = $publicDisk->path(str_replace('storage/', '', $metadata->video->path));
- $options = StoryboardOptions::fromMetadata($metadata, $filePath);
+
+ if (! file_exists($filePath)) {
+ throw new FileNotFoundException("File not found: {$filePath}");
+ }
+
+ $options = StoryboardOptions::fromMetadata($metadata);
$tile_count = ceil($metadata->duration * $options->fps);
$command = $builder->storyboard(
diff --git a/app/Services/Images/Storyboard/StoryboardOptions.php b/app/Services/Images/Storyboard/StoryboardOptions.php
index 5bd28d81..1fb11adc 100644
--- a/app/Services/Images/Storyboard/StoryboardOptions.php
+++ b/app/Services/Images/Storyboard/StoryboardOptions.php
@@ -4,7 +4,6 @@ namespace App\Services\Images\Storyboard;
use App\Exceptions\StoryboardNotSupportedException;
use App\Models\Metadata;
-use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
class StoryboardOptions {
public function __construct(
@@ -19,8 +18,8 @@ class StoryboardOptions {
public int $duration,
) {}
- public static function fromMetadata(Metadata $metadata, string $filePath): self {
- self::assertSupported($metadata, $filePath);
+ public static function fromMetadata(Metadata $metadata): self {
+ self::assertSupported($metadata);
$sourceW = $metadata->resolution_width ?? 1920;
$sourceH = $metadata->resolution_height ?? 1080;
@@ -60,7 +59,7 @@ class StoryboardOptions {
);
}
- private static function assertSupported(Metadata $metadata, string $filePath): void {
+ private static function assertSupported(Metadata $metadata): void {
// Unsupported codecs for hardware accelerated storyboard generation
$unsupportedCodecs = ['vp9', 'vp8'];
@@ -83,9 +82,5 @@ class StoryboardOptions {
if (str_starts_with($metadata->mime_type ?? '', 'audio/')) {
throw new StoryboardNotSupportedException('Audio files not supported for storyboard generation');
}
-
- if (! file_exists($filePath)) {
- throw new FileNotFoundException("File not found: {$filePath}");
- }
}
}
diff --git a/tests/Unit/Services/Storyboard/StoryboardOptionsTest.php b/tests/Unit/Services/Storyboard/StoryboardOptionsTest.php
new file mode 100644
index 00000000..5d0cc221
--- /dev/null
+++ b/tests/Unit/Services/Storyboard/StoryboardOptionsTest.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Tests\Unit\Services\Storyboard;
+
+use App\Exceptions\StoryboardNotSupportedException;
+use App\Models\Metadata;
+use App\Services\Images\Storyboard\StoryboardOptions;
+use Tests\TestCase;
+
+class StoryboardOptionsTest extends TestCase {
+ public function test_landscape_video_gets_correct_dimensions(): void {
+ $metadata = Metadata::factory()->make([
+ 'codec' => 'h264',
+ 'duration' => 600,
+ 'resolution_width' => 1920,
+ 'resolution_height' => 1080,
+ 'mime_type' => 'video/mp4',
+ ]);
+
+ $options = StoryboardOptions::fromMetadata($metadata);
+
+ $this->assertEquals(320, $options->width);
+ $this->assertEquals(180, $options->height);
+ }
+
+ public function test_portrait_video_gets_correct_dimensions(): void {
+ $metadata = Metadata::factory()->make([
+ 'codec' => 'h264',
+ 'duration' => 600,
+ 'resolution_width' => 1080,
+ 'resolution_height' => 1920,
+ 'mime_type' => 'video/mp4',
+ ]);
+
+ $options = StoryboardOptions::fromMetadata($metadata);
+
+ $this->assertEquals(180, $options->width);
+ $this->assertEquals(320, $options->height);
+ }
+
+ public function test_vp9_throws_not_supported(): void {
+ $this->expectException(StoryboardNotSupportedException::class);
+
+ $metadata = Metadata::factory()->make(['codec' => 'vp9', 'duration' => 600]);
+ StoryboardOptions::fromMetadata($metadata);
+ }
+
+ public function test_short_video_gets_higher_fps(): void {
+ $metadata = Metadata::factory()->make([
+ 'codec' => 'h264',
+ 'duration' => 16,
+ 'resolution_width' => 1920,
+ 'resolution_height' => 1080,
+ 'mime_type' => 'video/mp4',
+ ]);
+
+ $options = StoryboardOptions::fromMetadata($metadata);
+
+ $this->assertEquals(1, $options->fps);
+ }
+}