I’m releasing another of my free time projects – C++ library able to play WebM videos and supports decoding of the audio track.
- optimized (see Implementing into Unity plugin and example project)
- able to smoothly play 1080p @ 60fps
- decodes audio track
- provides decoded YUV texture and PCM audio data
Internally, the library uses following dependencies:
- link your application with libWebmPlayer.lib
- include <libWebmPlayer/player.hpp>
- load video using uvpx::Player::load
- then each frame:
- update the player using uvpx::Player::update(deltaTime)
- read YUV frame:
- frame = uvpx::Player::lockRead()
- do something with received YUV frame (fill SDL texture etc.)
- release frame using uvpx::Player::unlockRead()
- use play() / stop() / pause() functions to control playback
During playback, video player will call our custom audio callback with decoded audio PCM data.
- register audio callback using uvpx::Player::setOnAudioData
- append PCM data from parameters to your internal PCM buffer
- pass this PCM data from your buffer to the audio source when requested by your audio platform (see sdlAudioCallback in the example code), then erase written data from the buffer
Using CMake, generate project files and compile (tested on Visual Studio 2015).
The library is distributed under BSD license and can be found on https://github.com/ssincak/webmPlayer
Example project: https://github.com/ssincak/webmPlayerExample
Implementing the library into Unity plugin
Some time ago, before I started to work on my video player, I was trying to play full-hd video in the Unity using their default built-in MovieTexture component (internally using Theora codec).
Unity MovieTexture (Theora)
However, the video was choppy even at 50% quality set at Unity. So I opened the profiler and saw what was the problem:
Somewhere deep inside Unity, decoding the Theora full-hd, 60 fps video could took around 44 ms.
So I decided to roll my own video plugin using some other codec than Theora. I went for VPX after weeks of spare time coding, I got some nice library that can play videos with wery nice performance.
I have written about that in my previous post (see here).
I’ve also built the Unity plugin using that library and got the same video playing smoothly (with audio), see profiler window for the same video encoded using VP8 with Vorbis audio:
Announcement of new Unity video player (5.6+)
Recently, Unity has announced a new video player that will replace the old MovieTexture system. It brings several cool features and also significant performance boost. This player is available from Unity 5.6+, so when you want to play videos in the Unity smoothly, just download 5.6 and use the new system.