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.
- 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
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
- Use CMake 3.2.1 or newer and configure/generate from CMakeLists.txt in the source root
- Use Visual Studio 2013 or newer to compile webm_player.sln in the generated build folder
- run run.bat in the bin/Release or bin/Debug folder to play example video
Library source code
I plan to release the low-level library source code in the near future, when I will have some time, writing and opensourcing mood or ban in Dota :).