[theora] trying to encode/decode videos using libtheora

Ralph Giles giles at xiph.org
Fri Aug 25 14:39:25 PDT 2006

On Thu, Aug 24, 2006 at 10:26:32PM -0300, Ribamar Santarosa de Sousa wrote:

> The source code is here:
> http://opensvn.csie.org/ribamar/projects/streaming/cvaenc.c

I've only taken a quick look, but it looks like you're not writing out 
all the ogg pages. A packet can map to multiple pages, or many packets 
can map to the same page. You want something like this:

	while((ret = ogg_stream_pageout(&stream, &page) > 0){
	if (ret < 0) {
		fprintf(finfo, "problem pageout-ing.\n"); 

...and something similar to with ogg_stream_flush() when you know you've 
submitted you last packet. You're only making the fwrite() calls once 
after all the ogg_stream_* calls, which of course drops most of the 
stream data.

Two other things I noticed: by spec you must page flush after the first 
and last header packets. libogg does the first flush automatically, but 
you must do the second yourself.

You should use a random number for the serial number field in ogg_stream_init().
The rule is that the serial number must be unique in concatenated ogg 
streams, but best practice is to use a random number when creating a 
stream so native concatenation works most of the time.

Hope that helps,

More information about the theora mailing list