BGR to RGB from video


I’m using Riven’s (from JGO) video player for java, and I am getting each frame of video on a BufferedImage. The only thing is the image is of the type: BufferedImage.TYPE_3BYTE_BGR

I then do

AWTLoader loader = new AWTLoader();
Image img = loader.load(buf, true);
Texture2D tex = new Texture2D(img);

To get it in the form of a texture2d. The result is a somewhat purple looking image. I noticed Texture2D can be set to a type in the constructor, but not if you use the constructor I am. What can I do to get it looking right without it being slow?

Here’s a lil pic of the video’s colors, left in jme and right as they should be

Hard to say, how does the player works?
You could set the format of the resulting image to BGR8, and the GPU will interpret it correctly.

Do it on shader’s code, it would be much more efficient than any conversion in java code. Set an custom material for the object you are using to show the video on screen, just copy and rework the default one: Common/MatDefs/Gui/Gui.j3md
In your version of .frag file do:

gl_FragColor = texVal.bgra * color;

This will swap the colors.

By the way - converting each frame into an texture is a bad idea. Do you get an buffer with data in some event? If so, just copy it into an existing Texture buffer. You just need to have an texture with the same width/height and bpp as your player.

1 Like

Nah sometimes it’s just a matter of telling the GPU what is the proper format of the image. No conversion needed

1 Like

Wow, thanks for the quick replies guys!

Unfortunately due to other limitations of this video player I’ve decided to just drop videos. Turning out to be not remotely worth the hassle, plus it won’t run on Linux.

So no worries, and thanks for the help regardless.

Try JavaFX’s video player, there is a nice code you can use: GitHub - empirephoenix/JME3-JFX: JFX Gui bridge for JME with usefull utilities for common usecases

Would probably be easier / faster to upload the video directly as YUV straight from the decoder. This is how it works in the JFX version mentioned by @FrozenShade

Title says all. :smile: