Skip to content

useSegmentFilenameGenerator and Temporary SegmentΒ #539

@wilianmaique

Description

@wilianmaique

why the master.m3u8 path does not generate relative to the segments folder?

master:

#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=1238841,AVERAGE-BANDWIDTH=1224139,RESOLUTION=854x480,CODECS="avc1.64001e",FRAME-RATE=25.000
playlist.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2465150,AVERAGE-BANDWIDTH=2439108,RESOLUTION=1280x720,CODECS="avc1.64001f",FRAME-RATE=25.000
playlist.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=8774116,AVERAGE-BANDWIDTH=7755382,RESOLUTION=1920x1080,CODECS="avc1.640028",FRAME-RATE=25.000
playlist.m3u8
#EXT-X-ENDLIST

the correct one would be 480p/playlist.m3u8, 720p/playlist.m3u8 I imagine

folders:
path

my code:

$uuid = Str::uuid()->toString();
$basePath = "videos_output/{$uuid}";

$lowBitrate = new X264()->setKiloBitrate(1250);
$midBitrate = new X264()->setKiloBitrate(2500);
$highBitrate = new X264()->setKiloBitrate(8000);

FFMpeg::fromDisk('local')
        ->open("videos/2.mp4")
        ->exportForHLS()
        ->addFormat($lowBitrate, function ($media) {
            $media->addFilter('scale=-2:480');
        })
        ->addFormat($midBitrate, function ($media) {
            $media->addFilter('scale=-2:720');
        })
        ->addFormat($highBitrate, function ($media) {
            $media->addFilter('scale=-2:1080');
        })
        ->useSegmentFilenameGenerator(function ($name, $format, $key, callable $segments, callable $playlist) use ($basePath) {
            $folder = match ($format->getKiloBitrate()) {
                1250 => '480p',
                2500 => '720p',
                8000 => '1080p',
            };

            $segments("{$basePath}/{$folder}/segment_%05d.ts");
            $playlist("{$basePath}/{$folder}/playlist.m3u8");
        })
        ->setSegmentLength(3)
        ->onProgress(function ($percentage) {
            echo "{$percentage}% transcoded\n";
        })
        ->toDisk('public')
        ->save("{$basePath}/video.m3u8")
        ->cleanupTemporaryFiles();

and the temporary files like in the image temporary_segment_playlist_1 are not being removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions