Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove EXT-X-ENDLIST from master playlist file #519

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dave-nicholas
Copy link

@dave-nicholas dave-nicholas commented Feb 4, 2024

I am a contributor on the shaka project and noticed that playback was broken with this library.
This PR fixes a bug in the master playlist and allows playback with shaka (and probably other players where playback previously failed).

Unlike the EXTM3U element which is required at the start every Media Playlist and every Master Playlist. The EXT-X-ENDLIST should only appear in a Media Playlist file.

@exxsy
Copy link

exxsy commented Jun 17, 2024

Yeah EXT-X-ENDLIST line causes shaka player to throw error

@exxsy
Copy link

exxsy commented Jun 17, 2024

If you just dont want to wait PR,

Create a PlaylistGenerator for this case, like this one.

namespace App\PlaylistGenerators;

class HLSExtendedGenerator implements PlaylistGenerator
{
    public const PLAYLIST_START = '#EXTM3U';

    private function getStreamInfoLine(Media $segmentPlaylistMedia, string $key): string
    {
        $segmentPlaylist = $segmentPlaylistMedia->getDisk()->get(
            $segmentPlaylistMedia->getDirectory() . HLSExporter::generateTemporarySegmentPlaylistFilename($key)
        );

        $lines = DynamicHLSPlaylist::parseLines($segmentPlaylist)->filter();

        return $lines->get($lines->search($segmentPlaylistMedia->getFilename()) - 1);
    }

    public function get(array $segmentPlaylists, PHPFFMpeg $driver): string
    {
        return Collection::make($segmentPlaylists)->map(function (Media $segmentPlaylist, $key) use ($driver) {
            $streamInfoLine = $this->getStreamInfoLine($segmentPlaylist, $key);

            $media = (new MediaOpener($segmentPlaylist->getDisk(), $driver))
                ->openWithInputOptions($segmentPlaylist->getPath(), ['-allowed_extensions', 'ALL']);

            if ($media->getVideoStream()) {
                if ($frameRate = StreamParser::new($media->getVideoStream())->getFrameRate()) {
                    $streamInfoLine .= ",FRAME-RATE={$frameRate}";
                }
            }

            return [$streamInfoLine, $segmentPlaylist->getFilename()];
        })->collapse()->prepend(self::PLAYLIST_START)->implode(PHP_EOL);
    }
}

Then use it like this,

        FFMpeg::fromDisk("videos")
            ->open("/$this->name.$this->extension")
            ->exportForHLS()
            ->withPlaylistGenerator(new HLSExtendedGenerator)
            ->setSegmentLength(10)->...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants