WebM video player with audio support (C++)

WebM video player with audio support (C++)


Some time ago I was looking for a simple video player library  written in C++, that would be free, multi-threaded, supporting audio and it would not be Ogg Theora :).

I could not find anything useful. There is Bink, which is great, but paid (and expensive). Codecs like h.264 have not very friendly licenses or come with various restrictions (openh264). So I have searched a little bit and found the WebM project.

WebM is a container for VP8/VP9 video coding formats + Vorbis/Opus audio. Fully open-source and with friendly license, so this was my choice. The problem is – there is not a single library. There are libs for video decoding, audio decoding and webm (matroska) container parsers. When you want full video player with audio, you need to put them all together (and make it working).

I worked on this video player in my free time during weekends for several weeks until I finally got it running with OggVorbis audio support. I have even created an Unity plugin that used this library to play webm videos :-).

This project was just sitting on my hard drive, so I decided to let it out under BSD-style license. Maybe it will be useful for someone.


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


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


The video player is available on my github: https://github.com/ssincak/webmPlayer. Clone or download as you wish.

Example code: https://github.com/ssincak/webmPlayerExample

Example project

  1. Use CMake 3.2.1 or newer and configure/generate from CMakeLists.txt in the source root
  2. Use Visual Studio 2013 or newer to compile webm_player.sln in the generated build folder
  3. run run.bat in the bin/Release or bin/Debug folder to play example video