unosquare / ffmediaelement

FFME: The Advanced WPF MediaElement (based on FFmpeg)
https://unosquare.github.io/ffmediaelement/
Other
1.18k stars 243 forks source link

HLS: Feature Request: Smart m3u8 selection #14

Closed MrArca9 closed 7 years ago

MrArca9 commented 8 years ago

Okay, so i was going to implement this into my own project but if we can figure out how to do it in the library it might make my life easier.

Repro steps are simple: load an m3u8 file with more than one video element inside of it.

The player will get stuck trying to figure out what link to use.

If we can implement a simple get m3u8 and check for more than one link and play the first link in m3u8 that should work fine.

Just wanted to bring this up in a different issue thread so it can get its own attention.

mariodivece commented 7 years ago

The new library already has this support -- it finds the best stream of each type of media. Still working on this.

MrArca9 commented 7 years ago

Copy that, feel free to close this when you are finished with it.

mariodivece commented 7 years ago

The new decoder finds the "best stream" automatically. Can you provide me with a sample stream so I can test an maybe close this issue? Thanks.

Vasilich commented 7 years ago

http://kika_geo-lh.akamaihd.net/i/livetvkika_de@75114/master.m3u8 from this playlist the 1st stream will be taken, though the best one is at the list end. Moreover, if i save this playlist locally, and then try to open it from HDD, i'll get "Media failed .FFME.Container exception. Could not open "path-to-playlist" Error -22: Invalid argument"

mariodivece commented 7 years ago

I get an Access Denier error... What happens when you open it in ffplay.exe?

Vasilich commented 7 years ago

hmm. it is probably blocked based on location (it is public TV channel, so it could be available only in Germany and Austria). But ffplay took also the smallest resolution from that playlist, though if i copy the last link with highest resolution then fflpay plays it perfectly. Are there any options for ffplay to select best possible quality, and not the first item from playlist?

mariodivece commented 7 years ago

That, I do not know. But if you tell me what option to use I can read ffplay's source code and implement such selection in the control.

mariodivece commented 7 years ago

@Vasilich good news! This is now possible with the latest version! Please use the MediaOpening event Info contains all of the streams. Pick one from the Streams collection and set it in the Options.VideoStream which originally contains the "best" stream. Example:

private void Media_MediaOpening(object sender, MediaOpeningRoutedEventArgs e)
{
     // An example of switching to a different stream
     if (e.Info.InputUrl.EndsWith("matroska.mkv"))
     {
        var audioStreams = e.Info.Streams.Where(kvp => kvp.Value.CodecType == AVMediaType.AVMEDIA_TYPE_AUDIO)
             .Select(kvp => kvp.Value).ToArray();
        var commentaryStream = audioStreams.FirstOrDefault(s => s.StreamIndex != e.Options.AudioStream.StreamIndex);
        e.Options.AudioStream = commentaryStream;
      }
}