Display CMS Optimierungen 29-05-2026
- Mediathek: Video-Vorschaubilder statt Icons (FFmpeg-Thumbnails + Backfill-Command), Kategorie "Sonstiges" - B2in Media-Picker zeigt alle Medientypen, Typ wird automatisch erkannt; Thumbnail-Preview vor allen Medien-URL-Feldern - B2in Marke/Footer: Footer ein/aus, Logo+Claim frei positionierbar (Ecken) mit Constraints, separate Anzeige-Schalter - Angebote-Modul dynamisch: kein Slide-Typ mehr, einheitliches Detail-Layout mit ein-/ausblendbaren Bloecken, Logo/Brand pro Slide, Streichpreis-Option - Player: leere Module stoppen Endlosschleife, dynamische Layout-Anpassung bei verstecktem Footer/Header - Fix: Script-Ladereihenfolge (Livewire vor Flux), entfernte stale public/flux/flux.js, Modal-Crash beim Aktualisieren behoben Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9262132325
commit
6c6d683b9a
42 changed files with 2267 additions and 13905 deletions
|
|
@ -7,6 +7,7 @@ use Illuminate\Http\UploadedFile;
|
|||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class DisplayMediaService
|
||||
{
|
||||
|
|
@ -34,7 +35,7 @@ class DisplayMediaService
|
|||
}
|
||||
}
|
||||
|
||||
return DisplayMedia::create([
|
||||
$media = DisplayMedia::create([
|
||||
'filename' => $filename,
|
||||
'disk' => 'public',
|
||||
'path' => $relativePath,
|
||||
|
|
@ -45,6 +46,80 @@ class DisplayMediaService
|
|||
'collection' => $collection,
|
||||
'metadata' => ! empty($metadata) ? $metadata : null,
|
||||
]);
|
||||
|
||||
if ($type === 'video') {
|
||||
$thumbnailPath = $this->generateVideoThumbnail($media);
|
||||
|
||||
if ($thumbnailPath !== null) {
|
||||
$media->update(['thumbnail_path' => $thumbnailPath]);
|
||||
}
|
||||
}
|
||||
|
||||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a poster frame for an uploaded video using ffmpeg.
|
||||
*
|
||||
* Returns the relative thumbnail path on the media's disk, or null when
|
||||
* generation is not possible (e.g. ffmpeg missing or an unreadable file).
|
||||
*/
|
||||
public function generateVideoThumbnail(DisplayMedia $media): ?string
|
||||
{
|
||||
if (! $media->isVideo() || ! $media->isUpload() || ! $media->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$disk = Storage::disk($media->disk);
|
||||
$videoPath = $disk->path($media->path);
|
||||
|
||||
if (! is_file($videoPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$thumbnailRelativePath = preg_replace('/\.[^.\/]+$/', '', $media->path).'-poster.jpg';
|
||||
$thumbnailPath = $disk->path($thumbnailRelativePath);
|
||||
|
||||
if (! is_dir(dirname($thumbnailPath))) {
|
||||
@mkdir(dirname($thumbnailPath), 0755, true);
|
||||
}
|
||||
|
||||
// Try a frame ~1s in first (avoids black intro frames); fall back to
|
||||
// the very first frame for clips shorter than one second.
|
||||
foreach (['1', '0'] as $seekSeconds) {
|
||||
if ($this->extractFrame($videoPath, $thumbnailPath, $seekSeconds) && filesize($thumbnailPath) > 0) {
|
||||
return $thumbnailRelativePath;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_file($thumbnailPath)) {
|
||||
@unlink($thumbnailPath);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function extractFrame(string $videoPath, string $thumbnailPath, string $seekSeconds): bool
|
||||
{
|
||||
$process = new Process([
|
||||
'ffmpeg',
|
||||
'-y',
|
||||
'-ss', $seekSeconds,
|
||||
'-i', $videoPath,
|
||||
'-frames:v', '1',
|
||||
'-vf', 'scale=640:-2',
|
||||
'-q:v', '3',
|
||||
$thumbnailPath,
|
||||
]);
|
||||
$process->setTimeout(60);
|
||||
|
||||
try {
|
||||
$process->run();
|
||||
} catch (\Throwable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $process->isSuccessful() && is_file($thumbnailPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue