This document contains a bunch of Q&A from users that asked how to do a specific operation with LibVLC or LibVLCSharp.
As a general rule, it's a good idea to check how to perform a given operation on official VLC app (iOS, Android, Windows, etc.). From there, logs can give you information, and looking at the code as well.
Create your media with dvd:///
as per the documentation.
Check out our Chromecast sample
Check out our LocalNetwork sample
Check out our RecordHLS sample
Check out our VideoMosaic sample
Check out our Gestures sample
Inspect the Video and Audio tracks objects with Media.Tracks
.
Subscribe to the LibVLC.Log
event.
Like any other media. Here is a non exhaustive list of protocols we support.
We have a sample using ImageSharp and one using SkiaSharp doing exactly this.
From a libvlc standpoint, that means using libvlc_video_set_callbacks
and libvlc_video_set_format_callbacks
.
Pretty similarly to how you would do it from the CLI. Read https://wiki.videolan.org/Transcode/ and try media options with Media.AddOption
.
MediaPlayer.EnableHardwareDecoding = true
Like this, for example:
using(var libVLC = new LibVLC())
{
var media = new Media(libVLC, "https://www.youtube.com/watch?v=dQw4w9WgXcQ", FromType.FromLocation);
await media.Parse(MediaParseOptions.ParseNetwork);
using (var mp = new MediaPlayer(media.SubItems.First()))
{
var r = mp.Play();
Console.ReadKey();
}
}
Try the sample here https://code.videolan.org/mfkl/libvlcsharp-samples/-/blob/master/YoutubePlayback
Full list commands and arguments https://wiki.videolan.org/VLC_command-line_help/
using(var libVLC = new LibVLC())
{
var media = new Media(_libVLC, "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", FromType.FromLocation);
using (var mp = new MediaPlayer(media))
{
mp.AddSlave(MediaSlaveType.Subtitle, "file:///C:\\Users\\Me\\Desktop\\subs.srt", true);
var r = mp.Play();
Console.ReadKey();
}
}
media.AddOption(":freetype-rel-fontsize=10"); // Usually 10, 13, 16 or 19
media.AddOption(":freetype-color=16711680"); // Red
media.AddOption(":subsdec-encoding=Windows-1252");
If you are using the MediaPlayerElement
, then it is built-in in the UI.
If not, you should play with the Scale
and AspectRatio
MediaPlayer properties.
MediaPlayer.SetRate(float rate)
new LibVLC("--avcodec-skiploopfilter=2")
--avcodec-skiploopfilter={0 (None), 1 (Non-ref), 2 (Bidir), 3 (Non-key), 4 (All)}
Skip the loop filter for H.264 decoding
Skipping the loop filter (aka deblocking) usually has a detrimental
effect on quality. However it provides a big speedup for high
definition streams.
MediaPlayer.TakeSnapshot(uint num, string? filePath, uint width, uint height)
new LibVLC("--input-repeat=2")
https://stackoverflow.com/questions/56487740/how-to-achieve-looping-playback-with-libvlcsharp
using var libVLC = new LibVLC();
using var media = new Media(libVLC, new Uri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"));
await media.Parse(MediaParseOptions.ParseNetwork);
foreach(var track in media.Tracks)
{
switch(track.TrackType)
{
case TrackType.Audio:
Debug.WriteLine("Audio track");
Debug.WriteLine($"{nameof(track.Data.Audio.Channels)}: {track.Data.Audio.Channels}");
Debug.WriteLine($"{nameof(track.Data.Audio.Rate)}: {track.Data.Audio.Rate}");
break;
case TrackType.Video:
Debug.WriteLine("Video track");
Debug.WriteLine($"{nameof(track.Data.Video.FrameRateNum)}: {track.Data.Video.FrameRateNum}");
Debug.WriteLine($"{nameof(track.Data.Video.FrameRateDen)}: {track.Data.Video.FrameRateDen}");
Debug.WriteLine($"{nameof(track.Data.Video.Height)}: {track.Data.Video.Height}");
Debug.WriteLine($"{nameof(track.Data.Video.Width)}: {track.Data.Video.Width}");
break;
}
}
1 to enable marquee displaying. Marquee can be seen.
0 to disable marquee displaying. Marquee will not be visible.
MediaPlayer.SetMarqueeInt(VideoMarqueeOption.Enable, 1);
Font size in pixels. The default value is 0.
MediaPlayer.SetMarqueeInt(VideoMarqueeOption.Size, 32);
Marquee position: 0=center, 1=left, 2=right, 4=top, 8=bottom
You can also use combinations of these values, like 6 = top-right. The default value is 0.
MediaPlayer.SetMarqueeInt(VideoMarqueeOption.Position, 8);
^
| Y axis
|
|50x
|--------*
| |
| | 90y
| |
| |
<----------|------------------>
| X axis
|
The symbol "*" shows your text position, it will be appear like in diagram above if you set axis like below:
MediaPlayer.SetMarqueeInt(VideoMarqueeOption.X, 50); //X offset, from the left screen edge. default_value=0
MediaPlayer.SetMarqueeInt(VideoMarqueeOption.Y, 90); //Y offset, down from the top. default_value=0
Value should be within this range [0-255]
.
0 = transparent, 255 = totally opaque.
default value: 255
MediaPlayer.SetMarqueeInt(VideoMarqueeOption.Opacity, 100);
Text to be displayed as marquee text
MediaPlayer.SetMarqueeString(VideoMarqueeOption.Text, "my text"); //Text to display
Set color in decimal (hex will not work).
Use Hex2Dec to convert hex to decimal.
The default value is 16777215 (white).
Example usage for red.
MediaPlayer.SetMarqueeInt(VideoMarqueeOption.Color, 16711680); // red
More Advance options here wiki.videolan.org
LibVLC has many advanced options to customize playback and streaming features.
Multiple kinds of syntax are accepted to set these options:
- Using the LibVLC constructor, like this:
using var libvlc = new LibVLC("--verbose=2");
or like this
using var libvlc = new LibVLC("--verbose", "2");
- Using the
Media.AddOption
method, like this:
media.AddOption(":no-audio");
Several points to note:
- Some options may not be available on some platforms.
- Some options may be incompatible when used together.
- Some options name may change or get removed from one version of libvlc to another.
- Some options only work with LibVLC constructor, or only with
media.AddOption
.
Once the video has started playing, you can do this
uint videoHeight = 0;
uint videoWidth = 0;
mediaPlayer.Size(0, ref videoWidth, ref videoHeight);
Do pay attention to the orientation of the video. You can check it analyzing the video track of the media. If the orientation turns out to be "Bottom right", you might want to switch width/height values.