A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
fix: storyboard generation logs should be in the database instead of a new log for every file
aminnausin38ac85cebb3b
diff --git a/app/Jobs/Metadata/GenerateStoryboard.php b/app/Jobs/Metadata/GenerateStoryboard.phpindex bfe0fe57..ffdf41a4 100644--- a/app/Jobs/Metadata/GenerateStoryboard.php+++ b/app/Jobs/Metadata/GenerateStoryboard.php@@ -11,9 +11,11 @@ use App\Models\SubTask;use App\Services\Ffmpeg\FFmpegCommandBuilder;use App\Services\Images\Storyboard\StoryboardOptions;use App\Services\TaskService;+use Illuminate\Support\Carbon;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Storage;+use Symfony\Component\Process\Exception\ProcessFailedException;use Symfony\Component\Process\Process;class GenerateStoryboard extends ManagedSubTask {@@ -46,21 +48,27 @@ class GenerateStoryboard extends ManagedSubTask {* Execute the job.*/public function handle(TaskService $taskService, FFmpegCommandBuilder $builder): void {- $this->beginSubTask($taskService, "Generating storyboard for $this->filePath");+ if (! $this->beginSubTask($taskService, "Generating storyboard for $this->filePath")) {+ return;+ }try {$summary = $this->handleGenerateStoryboard($builder);$this->completeSubTask($taskService, $summary);} catch (StoryboardNotSupportedException $th) {$this->skipSubTask($taskService, 'Skipped: ' . $th->getMessage());+ $this->updateStoryboardScannedAt(now());} catch (\Throwable $th) {Log::warning('Storyboard generation failed', ['uuid' => $this->uuid,'file' => basename($this->filePath),'error' => $th->getMessage(),+ 'trace' => $th->getTraceAsString(),]);++ $this->updateStoryboardScannedAt(null);$this->failSubTask($taskService, $th);- // throw $th; Don't stop subsequent jobs if this one fails?+ // Don't stop subsequent jobs if this one fails (so don't throw)}}@@ -73,9 +81,9 @@ 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 * $options->fps);$command = $builder->storyboard(filePath: $filePath,@@ -87,13 +95,17 @@ class GenerateStoryboard extends ManagedSubTask {$process = new Process($command);$process->setTimeout(600);- $process->run();+ $command = str_replace('"^%"', '%', str_replace('\\', '/', $process->getCommandLine()));- if (! $process->isSuccessful()) {- Log::warning('Storyboard command failed', [+ try {+ $process->mustRun();+ } catch (ProcessFailedException $th) {+ Log::error('Storyboard command failed', ['uuid' => $this->uuid,'file' => basename($this->filePath),- 'command' => str_replace('"^%"', '%', str_replace('\\', '/', $process->getCommandLine())),+ 'command' => $command,+ 'error' => $process->getErrorOutput(),+ 'th' => $th->getMessage(),]);throw new \RuntimeException('FFmpeg failed: ' . $process->getErrorOutput());}@@ -107,7 +119,7 @@ class GenerateStoryboard extends ManagedSubTask {throw new \RuntimeException('FFmpeg produced no output files');}- DB::transaction(function () use ($options, $tile_count) {+ DB::transaction(function () use ($options, $tile_count, $timeElapsed, $command) {Storyboard::updateOrCreate(['metadata_uuid' => $this->uuid], ['tile_rows' => $options->rows,'tile_cols' => $options->cols,@@ -116,22 +128,24 @@ class GenerateStoryboard extends ManagedSubTask {'tile_count' => $tile_count,'interval_seconds' => 10,'modified_at' => now(),+ 'generation_time' => $timeElapsed . 's',+ 'command' => $command,]);- Metadata::where('uuid', $this->uuid)->update([- 'storyboard_scanned_at' => now(),- ]);+ $this->updateStoryboardScannedAt(now());});- Log::info('Storyboard generated', [- 'uuid' => $this->uuid,- 'file' => basename($filePath),- 'sheets' => $sheetCount,- 'tile_count' => $tile_count,- 'time' => $timeElapsed . 's',- 'command' => str_replace('"^%"', '%', str_replace('\\', '/', $process->getCommandLine())),- ]);-return "Generated storyboard for {$this->uuid} in {$timeElapsed}s";}++ /**+ * Updates storyboard scanned flag on metadata based on the uuid+ *+ * @param ?Carbon $time Timestamp saved to metadata (null on error)+ */+ private function updateStoryboardScannedAt(?Carbon $time) {+ Metadata::where('uuid', $this->uuid)->update([+ 'storyboard_scanned_at' => $time,+ ]);+ }}diff --git a/app/Models/Storyboard.php b/app/Models/Storyboard.phpindex 81e3efc3..308d99f6 100644--- a/app/Models/Storyboard.php+++ b/app/Models/Storyboard.php@@ -21,6 +21,9 @@ class Storyboard extends Model {* created_at -> timestamptz (nullable)* updated_at -> timestamptz (nullable)* modified_at -> timestamptz (nullable)+ *+ * command -> text (nullable)+ * generation_time -> float (nullable)*/protected $casts = ['modified_at' => 'datetime',@@ -35,6 +38,8 @@ class Storyboard extends Model {'tile_count','interval_seconds','modified_at',+ 'generation_time',+ 'command',];public function metadata(): BelongsTo {diff --git a/database/migrations/2026_05_24_182518_add_log_columns_to_storyboard.php b/database/migrations/2026_05_24_182518_add_log_columns_to_storyboard.phpnew file mode 100644index 00000000..15640a70--- /dev/null+++ b/database/migrations/2026_05_24_182518_add_log_columns_to_storyboard.php@@ -0,0 +1,26 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration {+ /**+ * Run the migrations.+ */+ public function up(): void {+ Schema::table('storyboards', function (Blueprint $table) {+ $table->text('command')->nullable();+ $table->float('generation_time')->nullable();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void {+ Schema::table('storyboards', function (Blueprint $table) {+ $table->dropColumn(['command', 'generation_time']);+ });+ }+};