Leite Vorschaubilder und Filmstufen geschuetzt ab
Deploy Test / test (push) Successful in 2m28s
Deploy Test / deploy (push) Failing after 14s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 09:40:59 +01:00
1 parent d6ff881e4e
commit c997eb500c
32 files changed
+979 -68

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
<?php
namespace App\Domain\Media;
use Illuminate\Support\Facades\Storage;
use RuntimeException;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;
class FfmpegFilmTranscoder implements FilmTranscoder
{
public function available(): bool
{
return (new ExecutableFinder)->find('ffmpeg') !== null;
}
public function derive(int $versionId, string $sourceRelative): array
{
$binary = (new ExecutableFinder)->find('ffmpeg');
if ($binary === null) {
return [];
}
$disk = Storage::disk('media_derived');
$source = $disk->path($sourceRelative);
$base = 'ableitungen/'.$versionId;
$rows = [];
foreach ([480, 720, 1080] as $height) {
$directory = $base.'/'.$height;
$disk->makeDirectory($directory);
$playlist = $disk->path($directory.'/index.m3u8');
$segment = $disk->path($directory.'/segment_%03d.m4s');
$process = new Process([
$binary,
'-y',
'-i',
$source,
'-vf',
'scale=-2:'.$height,
'-c:v',
'libx264',
'-preset',
'veryfast',
'-crf',
'23',
'-c:a',
'aac',
'-hls_time',
'6',
'-hls_playlist_type',
'vod',
'-hls_segment_filename',
$segment,
$playlist,
]);
$process->setTimeout(3600);
$process->run();
if (! $process->isSuccessful()) {
throw new RuntimeException('Die Qualitätsstufe '.$height.' ließ sich nicht ableiten.');
}
$rows[] = [
'role' => 'variant',
'label' => (string) $height,
'path' => $directory.'/index.m3u8',
];
}
$master = "#EXTM3U\n#EXT-X-VERSION:3\n"
."#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=854x480\n480/index.m3u8\n"
."#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720\n720/index.m3u8\n"
."#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080\n1080/index.m3u8\n";
$disk->put($base.'/master.m3u8', $master);
$rows[] = ['role' => 'master', 'label' => 'master', 'path' => $base.'/master.m3u8'];
return $rows;
}
}