0

I am trying to integrate LibVLCSharp in to my game engine built using MonoGame.

I have gotten it to render and gotten decent results using

_mediaPlayer.SetVideoFormat("RGBA", _width, _height, stride);
_mediaPlayer.SetVideoCallbacks(LockCb, null, DisplayCb);

Unfortunately, it's not quite good enough. Until now I have been using another library for videos called Theora Playback Library (https://www.cateia.com/libtheoraplayer/wiki/index.php?title=Main_Page). With it we are getting very smooth video playback, but we are trying to move our engine to 64bit and this library doesn't have that capability.

Looking at the source for TPL, I see it is decoding video frames to I420 buffers then converting them to RGBA. I wanted to see if doing the same thing with LibVLCSharp would improve playback performance but I've hit a snag.

The buffer for a I420 frame requires 3 picture buffers but the delegate signature for LibVLCVideoFormatCb doesn't appear to allow you to define that.

The libVLC documentation says that both lines and pitches are tables that should allow you to set the pitch and lines for each picture buffer

pitches: table of scanline pitches in bytes for each pixel plane (the table is allocated by LibVLC) [OUT]

lines: table of scanlines count for each plane [OUT]

but in LibVLCSharp pitches and lines are both uint so I can only set 1 value when I need to set 3.

public delegate uint LibVLCVideoFormatCb(
  ref IntPtr opaque,
  IntPtr chroma,
  ref uint width,
  ref uint height,
  ref uint pitches,
  ref uint lines);

Is there a way to define the format of an I420 buffer with the existing signature or is there another way entirely to get the decoded I420 frame data for each frame that I'm not doing?

nitramssirc
  • 340
  • 1
  • 2
  • 7
  • https://stackoverflow.com/questions/69210874/libvlcsharp-will-get-stuck-playing-specific-videos-on-any-platform – bbhxwl Sep 16 '21 at 15:52

1 Answers1

1

Please feel free to come discuss on our Discord or reach out on GitLab. MonoGame integration is definitly on our roadmap and we would love to have your contribution!

That being said, onto your question.

LibVLC 3 (the current stable version, for both the native library and the C# bindings) offer this API for custom rendering. However, as you have seen, it is not quite performant due to CPU copy (no hardware support).

In LibVLC 4 (previews available for both the native library and the C# bindings), a new API got added which allows to have the best performance possible with custom rendering.

The documentation is here https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html#gafae363ba4c4655780b0403e00159be56 It currently supports Direct3D9, Direct3D11, OpenGL and OpenGLES. Direct3D12 and Vulkan are also on the roadmap I believe.

For an example of implementation of this new LibVLC API, please see the Unity integration for Windows (D3D11) https://code.videolan.org/videolan/vlc-unity/-/blob/master/PluginSource/RenderAPI_D3D11.cpp

mfkl
  • 1,914
  • 1
  • 11
  • 21