[theora-dev] Beginner Hurdles

Zack Morris zmorris at gmail.com
Tue Aug 24 19:17:46 PDT 2010


On Aug 15, 2010, at 8:28 PM, Chris Double wrote:

> On Mon, Aug 16, 2010 at 8:30 AM, Zack Morris <zmorris at gmail.com>  
> wrote:
>> Thanxs for writing Ogg Theora, I think it's a wonderful library, just
>> needs some better documentation and examples.  I tend to work on the
>> back end of things and realize that getting someone to write concise
>> example code is like herding cats.
>
> I did a series for weblog posting's about writing a player that might
> be a bit less complicated than player_example:
>
> http://www.bluishcoder.co.nz/2009/06/24/reading-ogg-files-using-libogg.html
> http://www.bluishcoder.co.nz/2009/06/25/decoding-theora-files-using-libtheora.html
> http://www.bluishcoder.co.nz/2009/06/26/decoding-vorbis-files-with-libvorbis.html
> http://www.bluishcoder.co.nz/2009/06/27/playing-ogg-files-with-audio-and-video.html
>
> They're mainly based on my experience on trying to work out how things
> work too. the example player is:
>
> http://github.com/doublec/plogg


On Aug 16, 2010, at 2:27 PM, salsaman wrote:

> Hi Zack,
> I think I can help with some of this since I wrote the ogg/theora
> decoder for LiVES (lives.sf.net) and more recently I reworked the
> ogg/theora demuxer for vlc.
>
> Converting from yuv420 to rgb:
> take a look at the code here
> http://lives.svn.sourceforge.net/viewvc/lives/trunk/src/colourspace.c
> convert_yuv420p_to_rgb_frame()
>
> for theora you should use clamped yuv (16-235, 16-240, 16-240). The
> function uses arrays for conversion and does chroma super sampling
> using an averaging array.
>
>
> Seeking back to the beginning:
> you can seek to byte 0 and skip the bos packets, or you can store the
> position of data_start which follows the bos packets and seek back to
> that. You must remember to call ogg_stream_reset() for each logical
> stream after doing any seek operation.

Hey gyys, thanx for the examples.  I did some serious studying of the  
code and realized that my red and blue channels were reversed, because  
in our code, PixMapHandles and the OpenGL buffers had reversed pixel  
values, I think BRGA and RGBA.  Red and blue cause different responses  
in the eye, and so these formulas:

r = (1904000*(*py)+2609823*(*pv)-363703744)/1635200;
g = (3827562*(*py)-1287801*(*pu)-2672387*(*pv)+447306710)/3287200;
b = (952000*(*py)+1649289*(*pu)-225932192)/817600;

Obviously work incorrectly if you swap the red and blue, use the r and  
b formulas, and then swap them back.  No amount of adjusting offsets  
or scale factors or clipping would align all of the RGB with YUV  
properly and I was going nutz.  When I fixed the channels, my image  
rendered nearly identically to VLC even with the plain old linear  
code.  So I'm just going to put some keywords here like salmon pink  
orange teal navy blue in case someone in the future hits this problem.

I was thinking that it might be nice in the theora test movie to put a  
message in the corner like "salmon" "red" that would only show up  
properly if the red and blue use the proper formulas.  I'm not sure  
how often people run into this issue though.

As a side note, I think on modern hardware, all of the array lookups  
to do the YUV conversion properly could be a bit slow.  Maybe there is  
a way to do some kind of first order polynomial approximation of the  
curves that would avoid table lookups.  I miss the PowerPC days when  
you could pretty much do as much math as you wanted without slowdown,  
but I digress.

As for seeking, I tried a rewind() on the file and it "just worked",  
which I found really impressive.  A seeking example would be nice too  
though someday.  It's one of the least documented features and I still  
have a hard time wrapping my head around it.

I also have a hard time picturing how theora buffers ahead, because  
somehow memory has to increase if you feed it buffers but don't  
request audio/video frames.  Maybe these are questions for the users  
group?

Well, thanx for your help, when I have this wrapped up, I do want to  
post an OpenGL/OpenAL example.

Zack Morris
zmorris at zsculpt.com


More information about the theora-dev mailing list