M3U8 parsing with NuGet package M3USharp

820 views Asked by At

I need to read in an m3u8 master playlist, the individual chunk playlists, and the individual binary data chunks. I am just moving the data around, not doing any playbacks.

I'm using a NuGet package M3USharp to parse the master playlist, which gives me a list of streams. From each individual stream, I can get each chuck playlist. but I can not parse the chunk lists to get the individual chunks. I can not find any examples showing how to do this with this package.

this is my code:

var content = getMasterFilePlaylist();
M3UFile m3u8File = M3UReader.Parse(content);

foreach(var stream in m3u8File.Streams)
{
     Console.WriteLine(stream.Path);

     // do stuff here...
}

But I can not find any examples for paring the chunk lists. are there any other packages I should be using?

1

There are 1 answers

0
xav-stargate On

Try to use https://www.nuget.org/packages/M3U8Parser/ instead.

Like :

var masterPlaylist = MasterPlaylist.LoadFromFile("master.m3u8");

// Example, list all stream uri
foreach(var stream in masterPlaylist.Streams)
{
    Console.WriteLine("Uri:" + stream.Uri);
}

OR :

var mediaPlaylist = MediaPlaylist.LoadFromFile("playlist.m3u8");

Console.WriteLine(mediaPlaylist.HlsVersion);
Console.WriteLine(mediaPlaylist.PlaylistType);

foreach (var mediaSegment in mediaPlaylist.MediaSegments)
{
    foreach (var segment in mediaSegment.Segments)
    {
        Console.WriteLine(segment.Uri);
        Console.WriteLine(segment.ByteRangeLentgh);
        Console.WriteLine(segment.ByteRangeStartSubRange);
        Console.WriteLine(segment.Duration);
    }
}