Fasse die Bearbeitung in Dialoge und übernimm eine Filmstelle als Titelbild.
Deploy Test / test (push) Successful in 23s
Deploy Test / deploy (push) Successful in 22s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 18:58:26 +01:00
1 parent 9195cdcd15
commit c47c3b9b32
9 files changed
+1052 -228

No files matched your search

+85
View File
@@ -58,6 +58,91 @@ public function forCompositionFromElement(Composition $composition, ContentEleme
$this->rememberChoice($composition, 'element:'.$element->id);
}
public function forCompositionFrame(Composition $composition, ContentElementVersion $version, float $seconds): void
{
$version->loadMissing('element');
if ($version->element?->output_class !== 'film') {
$this->failComposition($composition, 'Aus dieser Filmstelle ließ sich kein Titelbild erzeugen.');
return;
}
$bytes = $this->jpegAtVersion($version, $seconds);
if (! is_string($bytes)) {
$this->failComposition($composition, 'Aus dieser Filmstelle ließ sich kein Titelbild erzeugen.');
return;
}
$name = 'komposition-'.$composition->id;
$path = 'vorschau/'.$name.'.jpg';
Storage::disk('media_derived')->put($path, $bytes);
$this->still($composition, Storage::disk('media_derived'), $path, $name);
$this->rememberChoice($composition, 'frame:'.$version->id.'@'.$this->secondText($seconds));
}
public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?string
{
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
if (! is_string($file) || $file === '' || str_contains($file, '..') || ! str_starts_with($file, 'inhalte/')) {
return null;
}
if ($seconds < 0 || $seconds > 7200) {
return null;
}
$disk = Storage::disk('media_derived');
if (! $disk->exists($file)) {
return null;
}
$binary = (new ExecutableFinder)->find('ffmpeg');
if ($binary === null) {
return null;
}
$process = new Process([
$binary,
'-hide_banner',
'-loglevel',
'error',
'-i',
$disk->path($file),
'-ss',
$this->secondText($seconds),
'-frames:v',
'1',
'-f',
'image2pipe',
'-vcodec',
'mjpeg',
'pipe:1',
]);
$process->setTimeout(30);
$process->run();
$bytes = $process->getOutput();
if (! $process->isSuccessful() || ! str_starts_with($bytes, "\xFF\xD8")) {
return null;
}
return $bytes;
}
private function secondText(float $seconds): string
{
$seconds = max(0, min(7200, $seconds));
$text = number_format($seconds, 3, '.', '');
return rtrim(rtrim($text, '0'), '.') ?: '0';
}
private function frame(ContentElement $element, string $file): void
{
$binary = (new ExecutableFinder)->find('ffmpeg');