[theora-dev] forcing eos on last theora packet (was Re: Theora 1.0 RC2)

Conrad Parker conrad at metadecks.org
Tue Oct 28 17:50:25 PDT 2008


2008/10/29 Romain Beauxis <toots at rastageeks.org>:
>
> I am currently implementing theora for our application.
> In our model for generating ogg streams, we may want to stop
> a stream while not providing a new YUV data buffer for encoding.
>
> Current API doesn't allow such thing, since the eos flag is set by the
> packetout function only when the last_p parameter was passed *and*
> there was some data available to output.
>
> Hence, I have written a function that forges this packet, along with NULL
> data, which is allowed by the ogg specifications (and works with other
> encoders, like speex).

Hi,

I think a simpler approach might be for you to directly set the eos
flag on the last ogg page, after you have retrieved it from
ogg_stream_pageout(). You can use a function like this (copied from
oggz-chop.c, where it similarly cuts the end of a file):

static void
_ogg_page_set_eos (const ogg_page * og)
{
  if (og == NULL) return;

  og->header[5] |= 0x04;
  ogg_page_checksum_set (og);
}

> Furthermore, since API claims that the 1-1 correspondance with YUV encoded
> buffer and ogg packet might not remain in the futur, I believe such function
> may be usefull in the case when 2, 3 or 4 buffers could be needed to fill a
> new ogg packet..
>
> Patch is attached. I didn't test it yet, but it is mainly packetout's code. I
> believe it is correct, though I don't know if the granulepos and packetno
> should be incremented in this case.

As for these questions regarding your patch, packetno would need to be
incremented. I think granulepos would probably be the same as that of
the previous packet (ie. the last actual frame), but the spec doesn't
define that such an empty packet is valid for theora.

Just setting eos directly on the last page produced should avoid any
of these issues.

cheers,

Conrad.


More information about the theora-dev mailing list