WebM video player library

Introduction

I’m releasing another of my free time projects – C++ library able to play WebM videos and supports decoding of the audio track.

Features:

  • 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:

Usage

Playing video:

  1. link your application with libWebmPlayer.lib
  2. include <libWebmPlayer/player.hpp>
  3. load video using uvpx::Player::load
  4. then each frame:
    1. update the player using uvpx::Player::update(deltaTime)
    2. read YUV frame:
      1. frame = uvpx::Player::lockRead()
      2. do something with received YUV frame (fill SDL texture etc.)
      3. release frame using uvpx::Player::unlockRead()
  5. use play() / stop() / pause() functions to control playback

Audio:

During playback, video player will call our custom audio callback with decoded audio PCM data.

  1. register audio callback using uvpx::Player::setOnAudioData
  2. append PCM data from parameters to your internal PCM buffer
  3. 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

Building

Using CMake, generate project files and compile (tested on Visual Studio 2015).

Example project

I wrote about my Webm Video Player some time ago – this project is using SDL 2 to display the decoded YUV frame and plays the decoded PCM audio.

Download

The library is distributed under BSD license and can be found on my BitBucket.

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:

theora_profiler

MovieTexture (Theora) performance, 1080p@60fps

Somewhere deep inside Unity, decoding the Theora full-hd, 60 fps video could took around 44 ms.

VP8/VP9

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:

Webm (VP8+Vorbis audio) video playing, 1080p@60fps

Webm (VP8+Vorbis audio) video playing, 1080p@60fps

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.