[Vorbis-dev] ogg encoding

Ralph Giles giles at xiph.org
Wed Jun 7 21:54:01 PDT 2006

On Wed, Jun 07, 2006 at 09:43:12PM -0400, Stephen Whiters-Ridley wrote:

> ok, I know its faux pas to post code snippets but will pseudo code be ok?

Is it? We often find there's no other way to give useful advice. :-)

> while (amtread = fread(readbuf, file)){
>  ogg_packet.bytes = amtread
>  if first_read_from_file then
>    ogg_packet.b_o_s = 1
>  if amtread < PACKETSIZE then
>    ogg_packet.e_o_s = 1
>  ogg_packet.packet = readbuf
>  ogg_stream_packetin()
>  if (ogg_stream_pageout()) then
>    write_page_to_file()
>  elseif (amtread < PACKETSIZE) then
>    ogg_stream_flush() and write_page_to_file()
> }

So that should be:

  while (ogg_stream_pageout()) {
  if (amtread < PACKETSIZE) {
    while (ogg_stream_flush() {

Otherwise you can easily (depending on the size of PACKETSIZE) have 
some fraction of your file buffered inside libogg and so the first 
ogg_stream_flush() doesn't actually return the last page. That remains 
my best guess why you're not seeing your eos.

You also probably want to update the sequence number and granulepos 
fields for each packet.

Just out of curiousity, what kind of data is this you're encapsulating?


More information about the Vorbis-dev mailing list