-
Notifications
You must be signed in to change notification settings - Fork 104
Advanced
The purpose of DecoderContext is to support plugins and include all the required demuxers, decoders, remuxers and handle the low level configuration and synchronization of them. All the higher level media contexts (such as Player, Downloader, Extractor) should be based on this and only use direct instances of remuxers, demuxers and decoders only if really required. Use default enableDecoding if you are planning to use decoders and want the demuxers to split the packages to audio, video and subtitles.
It exposes the following main classes:-
-
Video Demuxer
Main demuxer which can demux all media (audio, video, subtitles) -
Audio Demuxer
When main demuxer is in use (e.g. for video) it is required to use an external demuxer to handle the audio -
Subtitles Demuxer
When the main demuxer is in use it is required to use an external demuxer to handle the subtitles
-
Video Stream
The currently main enabled video stream from the video demuxer -
Audio Stream
The currently main enabled audio stream from the audio or video demuxer -
Subtitles Stream
The currently main enabled subtitles stream from the subtitles or video demuxer
-
Video Decoder
Decodes packets of a video stream from the video demuxer -
Audio Decoder
Decodes packets of an audio stream from the audio or video demuxer -
Subtitles Decoder
Decodes packets of an subtitles stream from the subtitles or video demuxer
Plugins can be used to extend the embedded functionality and support more formats that ffmpeg does not already. To achieve best performance you should avoid including plugins that you are not going to use.
Some basic plugin ideas are: -
-
Open
non supported formats (e.g. torrents, browser URLs, online subtitles) -
Suggest
the best input/stream from currently available (e.g. audio/subtitles based on languages or video based on screen resolution) -
Scrape
information (e.g. movie title, ratings)
FlyleafLib embeds the following basic plugins:-
-
OpenDefault
Handles playlist files and any url or custom IO stream that cannot be handled from other plugins.It extracts basic information (scrape) such as Title, FileSize, Season/Episode, Duration. -
OpenSubtitles
Handles subtitles files (such as .srt). It searches locally for an already existing subtitles of the currently playing video -
StreamSuggester
Suggests video stream based on Config.Video.MaxVerticalResolution. Suggests audio based on Config.Audio.Languages and video's stream program. Suggests subtitles based on Config.Subtitles.Languages, rating and if it is already downloaded
Currently developed plugins that you can place under "Plugins" directory:-
-
BitSwarm
Initializes a torrent client for torrent, magnet link, and/or hash inputs and provides custom IOStreams to the demuxer. Suggests the first (from sorted list) input. -
YoutubeDL
Handles HTTP(s) URLs (non m3u8 playlists) and parses them to an external .exe youtube-dl (or any other fork of it, currently uses yt-dlp) to extract all the ffmpeg supported audio and video inputs. Suggests video based on Config.Video.MaxVerticalResolution and tries to avoid vp9 codec and dash protocol. Suggests audio (if video does not already have) based on audio inputs without video to save bandwidth. -
OpenSubtitlesOrg
Performs online search to opensubtitles.org to automatically identify and download subtitles related to the video input. -
SubtitlesConverter
As ffmpeg requires a utf-8 encoding of the input subtitles it will use an advanced detection method of the current encoding and will convert them to utf-8 if required.
Plugins should be placed under "Plugins" directory. Each plugin should inherit FlyleafLib.Plugins.PluginBase and -if not already within the same assembly- should be placed under "Plugins/<PluginName>" directory (dlls and other required files if any). Can implement any of the available plugin interfaces (check PluginBase.cs and Plugins) based on what it is going to do.
A commonly used plugin example would be to change the default video stream suggester (ISuggestVideoStream) to one of your own:-
using FlyleafLib.MediaFramework.MediaStream;
using FlyleafLib.Plugins;
using System.Collections.Generic;
using System.Linq;
...
/// <summary>
/// Custom Video Stream Suggester based on max height and fps
/// </summary>
public class CustomVideoStreamSuggester : PluginBase, ISuggestVideoStream
{
public new int Priority { get; set; } = 1; // Not required but could be set if you use multiple plugins of the same type
public VideoStream SuggestVideo(ObservableCollection<VideoStream> streams)
{
return streams.OrderByDescending(stream => stream.Height).ThenByDescending(stream => stream.FPS).FirstOrDefault();
}
}
You could just Open the input by disabling the the defaultVideo and then Open the stream of your choice. However, by this way you follow the FlyleafLib's recommendations to get the best stability and performance.