loading...

Introducing LibVLCSharp for Unity3D

mfkl profile image mfkl Originally published at mfkl.github.io ・3 min read

Today (December 18th 2019), we are announcing the initial release of VLC for Unity (Windows) on the Unity Store!

This Unity plugin allows you to use a LibVLC-powered video player in your games and Unity apps. Whether you need to support a strange format, live streaming or play a 4K video in your latest production, we got you covered.

Commercial support

While this Unity plugin is opensource, its Unity Store price is 100USD.

This price is intended to help sponsor the development and the commercial support of this Unity plugin by Videolabs, the main commercial contributor to the VLC apps.

All LibVLC features available in your Unity game

Given that this plugin is using LibVLCSharp (which uses LibVLC), it exposes more or less the same feature set and same codecs support than VLC, such as:

  • Play every media file formats, every codec and every streaming protocols
  • Run on every platform, from desktop (Windows, Linux, Mac) to mobile (Android, iOS) and TVs
  • Hardware and efficient decoding on every platform, up to 8K
  • Network browsing for distant filesystems (SMB, FTP, SFTP, NFS...) and servers (UPnP, DLNA)
  • Playback of Audio CD, DVD and Bluray with menu navigation
  • Support for HDR, including tonemapping for SDR streams
  • Audio passthrough with SPDIF and HDMI, including for Audio HD codecs, like DD+, TrueHD or DTS-HD
  • Support for video and audio filters
  • Support for 360 video and 3D audio playback, including Ambisonics
  • Able to cast and stream to distant renderers, like Chromecast and UPnP renderers.

And more.

Performance focus

This plugin uses a LibVLC 4.0 build which has seen a lot of improvements regarding performance in the past year. The plugin also makes use of a new, low-level, LibVLC API consisting of Zero Copy GPU callbacks.

This means your (slow) CPU is bypassed and only your GPU is working to provide decoded textures. The LibVLC API offers Direct3D and OpenGL hooks, but this is all taken care of for you inside the Unity plugin. Have a look here if you're curious about it.

With this plugin and this new API, you can get similar performance to VLC Desktop in your Unity games and enjoy low CPU use and optimized battery life on your devices when playing high definition medias.

Getting started

As usual, you need to load the libvlc libraries and create your LibVLC, MediaPlayer and Media objects as you would on any other platform with LibVLCSharp.

The public API of this plugin is strictly the same than LibVLCSharp for all but one additional method on the MediaPlayer:

/// <summary>
/// Retrieve a video frame from the Unity plugin as a texture.
/// </summary>
/// <param name="updated">True if the video frame has been updated</param>
/// <returns>A decoded texture</returns>
public IntPtr GetTexture(out bool updated)
Enter fullscreen mode Exit fullscreen mode

This is the method that you need to call in a Unity coroutine in your script and give its result to your texture's UpdateExternalTexture method. Full script example can be found here.

What's next

Platforms support

Currently, this plugin only supports Windows Classic 64bit with Direct3D11. We aim to bring support to the following platforms during the coming year:

  • UWP,
  • macOS, iOS, tvOS,
  • Android (prototype working),
  • Linux.

And the following graphics APIs:

  • OpenGL ES,
  • OpenGL,
  • Metal,

We currently have a prototype working on Android with OpenGL ES.

Other goals

  • Provide various easy to use, ready-to-run samples and improved documentation.
  • Provide in-Editor MediaPlayer customization, so you can customize LibVLC and playback parameters directly from the Unity Editor.

Discussion

pic
Editor guide