Theora video in LWJGL and others

After crawling the internet for hours, I wasn’t able to find any solutions to playing video (for cutscenes and such) inside my LWJGL game. After 3 frustrating weeks, I’ve managed to come up with a PURE JAVA implementation of the Theora video codec for use with various libraries (I only included an LWJGL module, but it’s easy to make one for JOGL or otherwise). Results are promising, and the system can render full 1080p video with audio (tested up to 48000 Hz) at upwards of 80 FPS. I’m currently using it in a real-world context with no issues. I’ve encapsulated it all in a library, which you can find here:
https://github.com/OrionNebula/JavaGL-Theora
Its 2 dependencies are licensed under LGPL, and the API itself is MIT.
I am having a bit of trouble with audio synchronization, and I figured you guys might be able to help out. openAudio() and audioThread contains the bulk of the problem, but some of it may be in playVideoInline(…). I’ve tried adjusting the audio line’s buffer size and the fragment size, which works until the situation changes. I still can’t think of any ways to permanently link the audio and video rates.

Cas is supposed to have a pure java implementation of theora IF that worked out eventually.

And yes audio syncing is one of the usual issues and not a small one

Yes, I got it all working, though it’s pretty finicky about what format it can actually play. For my purposes though that was perfectly OK. Theora YUV 422 encoding to be precise. Also I deliberately make it rely on OpenGL and shaders to render which can cause issues with cough Intel but there we go. Keeps the riffraff away.

Audio syncing is the easy bit. I hacked out all the JavaSound stuff from Cortado and replaced it with an implementation that uses OpenAL instead.

Unfortunately the source code is quite crappy to look at :slight_smile: It may take a bit of time to gather together.

Cas :slight_smile:

Thank you for your suggestion. JOGL 2 already supports video with FFMPEG and LibAV, its media player works even under Android. I’m going to look at your source code.

Edit.: Do you plan to use JOAL or LWJGL for the sound instead of JavaSound? (princec is right)

I’ll see what I can do about modularizing audio output as well, so users can choose between the various audio pipelines (JavaSound, LWJGL, JOAL, etc.). I should have something in a couple hours. How did you end up syncing the audio, Cas?

The posts here and here might be helpful as they set out to solve the same problem.

You use the audio to drive the video; wait for a frame’s worth of audio, and when you’ve got it, play it and you display the next frame of video.

Cas :slight_smile: