[theora] Simple RGB->YUV Stuff...

Jeremy Moles jeremy at emperorlinux.com
Sun Aug 20 20:14:57 PDT 2006

I've spent the weekend or so trying to get my head around Theora and I'm
just not having any luck. First of all, I really don't have any interest
in immersing myself in video encoding--I just have one simple thing I'd
like to do--so I haven't spent any time reading about the theory or
specs or anything like that.

I'm attempting to write a "render-to-theora" target for OpenGL.
Basically, I have access to a buffer of RGBA data that I want to convert
into YUV and pass to Theora to encode for me.

There are lots of different ways to do the per-pixel conversion from RGB
to YUV that I've found online; I think I have this part down fairly
well. Eventually, what I end up with are three buffers, each one as
large as the other and containing the from-RGB-to-YUV values performed
per-pixel. This is where I get hung up.

To pass the YUV data to the various encode functions I have to create a
yuv_buffer struct and set the widths, heights, and strides correctly.
What I've been trying to use is:

        yuv_buffer yuv;

        yuv.y_width   = Width;
        yuv.y_height  = Height;
        yuv.y_stride  = Width;
        yuv.uv_width  = Width;
        yuv.uv_height = Height;
        yuv.uv_stride = Width;
        yuv.y         = YDATA;
        yuv.u         = UDATA;
        yuv.v         = VDATA;

There isn't a lot of documentation on how Theora "wants" the pixel data
in theora.h, so I really feel like this should be right (since I have a
1:1:1 ratio of RGB data to YUV data). The Y data is perfect--that is,
the grayscale image in my video is perfect. However, the UV stuff is
very wrong, and I've included a screenshot here:


In that screeny, the "blue" bars should be right on top of the grayscale
beneath it (the real image is just a left-to-right blue line drawn by

If anyone has any advice I would very, VERY much appreciate it. It seems
like a simple enough thing to do, and I imagine lots of other people
would be interested in it. I don't really think it's a question of "how
do I convert from RGB to YUV", but rather "how do I populate the
yuv_buffer struct properly so libtheora interprets my data correctly."

Am I missing something very fundamental here? :)

More information about the theora mailing list