Theora video playback

Hi folks!
There is my adaptation for Urho3D of the Orange’s example with Theora playback on textures

  • previous CPU color decoding was removed
  • last version have only OpenGL shader for GPU color decoding

Nice work. I am thinking of doing the same for OpenCV.

Cool! :smiley:

Awesome :stuck_out_tongue:

Thanks )
I guess it still working only for the one movie, that i testing. So there are a lot of work in future

computer vison + urho3d you mean? for what ?

Nice work.
Could be very useful for games, playing intro’s, cut-scenes, and such.

Yes, that’s is common case of usage.

Previously I’m also locking on FFmpeg, but i suppose it has bad licence for urho3d ? (GPL)

Theora has BSD licence

FFmpeg itself is LGPL, which is fine as long as you link dynamically.
Some libraries that FFmpeg can be built with (most known, x264) are GPL licensed.
But if you have full control of assets, there is no reason not to use OGG video / theora instead.

Firstly, nice work!

Secondly, I’m trying to make this work in a BorderImage but having trouble converting properly to RGB from YUV. Any idea how i could do this? At the moment I’ve got the black and white from the Y element of the video displaying on a BorderImage by doing:

At the bottom of UpdatePlaneTextures(). This works. (I’ve taken away the code that renders it to a material in the scene)

1 Like

Awesome work! Finally getting around to testing this and the video works great but missing sound.

edit: maybe it’s not supposed to have audio?

1 Like

Playing audio using Urho3D’s BufferedStreamAudio:


Excellent work !This would be a nice addon for Urho3d ! Do you plan to make it open source ?

1 Like

The video/audio player that you see is literally this example, in the repo.
Instead of using AUDIO_DEVICE and ioctrl fns, use the BufferedStreamAudio, the video conversion from yuv420 to rgba is already there. I’m still having trouble with audio synchronization, as you can hear some skipping in the video, and studying the process.


Audio should be in sync now,


Just found some time to test it ! Works perfectly ! Even CPU decoding is really fast (No serious impact on CPU usage).

Excellent work ! Thank you !
Definitely will use this for my cutscenes !

I found a small issue with the player. If i run the app in windowed mode and the window loses focus the video and audio start going out of sync the audio starts to crackle and the video just freezes randomly. (the same issue as in your video)
Also limiting the fps affects the video playback speed which makes sense but is there any solution to run updates independently of fps ? Maybe the whole update procedure should be in an other thread ?

The cpu usage is below 20% while playing the video so its not a hardware issue

EDIT : Tried it with my own video (1280 * 768) and even with maximum fps the audio goes out of sync after 7-8 seconds…

Looking at the code, I think HandleUpdate() should do multiple UpdateTheora() calls until decoding is up to date with latest possible data. I would recommend doing the decoding in separate thread and signaling the main thread when a video/audio frame data is ready, then doing texture blit on the main thread.


At the bottom of the UpdateTheora() fn, there’s a loop correction section:

      // correction loops
      // note: audioTime_ will remain negative (-1000) until vorbis actually acquires a vorbis packet
      audioOffset = audioTime_ - elapsedTime_;

      if (audioOffset < 0)
          if (++numLoops > MAX_CORRECTIVE_LOOPS)

Check the audioOffset and see how far it lags behind, and instead of using MAX_CORRECTIVE_LOOPS, you might consider a fixed desirable offset value.

Pseudo code might look something like:

      if (audioTime_ != -1000LL && audioOffset < -5LL)
         then continue looping
1 Like

Updated the repo with the corrective audio loop fix.


I turned Vsync on and it totally ruined the playback (extreme stuttering and frame freezes)…
Seems it really needs a separate thread for decoding.