Skip to content

A self-hosted media server and file management system

fix: storyboard generation should skip instead of fail on incompatibility

aminnausin446f17a8b637
diff --git a/app/Exceptions/StoryboardNotSupportedException.php b/app/Exceptions/StoryboardNotSupportedException.php
new file mode 100644
index 00000000..a778b099
--- /dev/null
+++ b/app/Exceptions/StoryboardNotSupportedException.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace App\Exceptions;
+
+use Exception;
+
+class StoryboardNotSupportedException extends Exception {}
diff --git a/app/Jobs/ManagedSubTask.php b/app/Jobs/ManagedSubTask.php
index 1eb0af02..689aa83c 100644
--- a/app/Jobs/ManagedSubTask.php
+++ b/app/Jobs/ManagedSubTask.php
@@ -140,6 +140,27 @@ abstract class ManagedSubTask implements ShouldQueue {
}
}
+ /**
+ * Fail the subtask
+ *
+ * @param string $reason Skip reason
+ */
+ public function skipSubTask(TaskService $taskService, string $reason = ''): void {
+ $endedAt = now();
+ $duration = $this->getTaskDuration($endedAt);
+
+ DB::transaction(function () use ($taskService, $reason, $endedAt, $duration) {
+ $taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++']);
+ $taskService->updateSubTask($this->subTaskId, [
+ 'status' => TaskStatus::SKIPPED,
+ 'summary' => $reason ?: 'Skipped',
+ 'progress' => 100,
+ 'ended_at' => $endedAt,
+ 'duration' => $duration,
+ ]);
+ });
+ }
+
/**
* Determine if the batch has been cancelled...
*/
diff --git a/app/Jobs/Metadata/GenerateStoryboard.php b/app/Jobs/Metadata/GenerateStoryboard.php
index cdf72318..bfe0fe57 100644
--- a/app/Jobs/Metadata/GenerateStoryboard.php
+++ b/app/Jobs/Metadata/GenerateStoryboard.php
@@ -3,6 +3,7 @@
namespace App\Jobs\Metadata;
use App\Enums\TaskStatus;
+use App\Exceptions\StoryboardNotSupportedException;
use App\Jobs\ManagedSubTask;
use App\Models\Metadata;
use App\Models\Storyboard;
@@ -10,6 +11,7 @@ use App\Models\SubTask;
use App\Services\Ffmpeg\FFmpegCommandBuilder;
use App\Services\Images\Storyboard\StoryboardOptions;
use App\Services\TaskService;
+use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\Process\Process;
@@ -34,7 +36,7 @@ class GenerateStoryboard extends ManagedSubTask {
$this->filePath = $filePath;
$this->uuid = $uuid;
- $subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Generate storyboard for video file ' . basename(dirname($filePath)) . '/' . basename($filePath)]);
+ $subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Generate storyboard for ' . basename(dirname($filePath)) . '/' . basename($filePath)]);
$this->taskId = $taskId;
$this->subTaskId = $subTask->id;
@@ -49,6 +51,8 @@ class GenerateStoryboard extends ManagedSubTask {
try {
$summary = $this->handleGenerateStoryboard($builder);
$this->completeSubTask($taskService, $summary);
+ } catch (StoryboardNotSupportedException $th) {
+ $this->skipSubTask($taskService, 'Skipped: ' . $th->getMessage());
} catch (\Throwable $th) {
Log::warning('Storyboard generation failed', [
'uuid' => $this->uuid,
@@ -69,11 +73,10 @@ class GenerateStoryboard extends ManagedSubTask {
$metadata = Metadata::where('uuid', $this->uuid)->firstOrFail();
$metadata->load('video');
+ $tile_count = ceil($metadata->duration / config('media.storyboard.default_interval_seconds', 10));
$filePath = $publicDisk->path(str_replace('storage/', '', $metadata->video->path));
$options = StoryboardOptions::fromMetadata($metadata, $filePath);
- $tile_count = ceil($metadata->duration / config('media.storyboard.default_interval_seconds', 10));
-
$command = $builder->storyboard(
filePath: $filePath,
outputPattern: $publicDisk->path($outputDir) . '/%d.jpg',
@@ -104,15 +107,21 @@ class GenerateStoryboard extends ManagedSubTask {
throw new \RuntimeException('FFmpeg produced no output files');
}
- Storyboard::updateOrCreate(['metadata_uuid' => $this->uuid], [
- 'tile_rows' => 10,
- 'tile_cols' => 10,
- 'tile_width' => $options->width,
- 'tile_height' => $options->height,
- 'tile_count' => $tile_count,
- 'interval_seconds' => 10,
- 'modified_at' => now(),
- ]);
+ DB::transaction(function () use ($options, $tile_count) {
+ Storyboard::updateOrCreate(['metadata_uuid' => $this->uuid], [
+ 'tile_rows' => $options->rows,
+ 'tile_cols' => $options->cols,
+ 'tile_width' => $options->width,
+ 'tile_height' => $options->height,
+ 'tile_count' => $tile_count,
+ 'interval_seconds' => 10,
+ 'modified_at' => now(),
+ ]);
+
+ Metadata::where('uuid', $this->uuid)->update([
+ 'storyboard_scanned_at' => now(),
+ ]);
+ });
Log::info('Storyboard generated', [
'uuid' => $this->uuid,
diff --git a/app/Services/Images/Storyboard/StoryboardOptions.php b/app/Services/Images/Storyboard/StoryboardOptions.php
index 75671ef0..12de4703 100644
--- a/app/Services/Images/Storyboard/StoryboardOptions.php
+++ b/app/Services/Images/Storyboard/StoryboardOptions.php
@@ -2,7 +2,9 @@
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(
@@ -52,27 +54,27 @@ class StoryboardOptions {
$unsupportedCodecs = ['vp9', 'vp8'];
if (empty($metadata->codec)) {
- throw new \RuntimeException('No codec detected for storyboard generation');
+ throw new StoryboardNotSupportedException('No codec detected for storyboard generation');
}
if (in_array($metadata->codec, $unsupportedCodecs)) {
- throw new \RuntimeException("Codec {$metadata->codec} not supported for storyboard generation");
+ throw new StoryboardNotSupportedException("Codec {$metadata->codec} not supported for storyboard generation");
}
if (empty($metadata->duration) || $metadata->duration < 10) {
- throw new \RuntimeException('Duration too short or missing for storyboard generation');
+ throw new StoryboardNotSupportedException('Duration too short or missing for storyboard generation');
}
if (empty($metadata->resolution_width) || empty($metadata->resolution_height)) {
- throw new \RuntimeException('Resolution missing for storyboard generation');
+ throw new StoryboardNotSupportedException('Resolution missing for storyboard generation');
}
if (str_starts_with($metadata->mime_type ?? '', 'audio/')) {
- throw new \RuntimeException('Audio files not supported for storyboard generation');
+ throw new StoryboardNotSupportedException('Audio files not supported for storyboard generation');
}
if (! file_exists($filePath)) {
- throw new \RuntimeException("File not found: {$filePath}");
+ throw new FileNotFoundException("File not found: {$filePath}");
}
}
}