Page breaks when encoding ogg/theora

Hi everyone,

I'm trying to build theora encoding into my game engine. Essentially,
I'd like to do something similar to png2theora.c, where I take
individual screen shots of my game and encode them into a video.
Because png2theora.c uses the legacy C API, I used encoder_example.c
as a template instead. encoder_example.c seems to be the only code out
there that actually uses the th_* API.

The basic program flow is:
- start
  - open file
  - init theora and ogg
  - write first header
  - ogg page break
  - write remaining headers
  - ogg page break

- for each frame
  - encode frame
  - pass packet to ogg
  - if ogg page is ready, write the page out  <-- ** problem is here **

- end
  - get all remaining packets from the encoder
  - write all remaining ogg pages out
  - close file

It all works when I put every theora packet into its own ogg page
using ogg_stream_flush() after encoding a frame. However, when I use
(Continue reading)

Ralph Giles | 11 Jun 06:47
Favicon

Re: Page breaks when encoding ogg/theora

On 10-Jun-08, at 8:20 PM, Claus Höfele wrote:

> Is there anything obvious you guys could point out to me? I'd
> appreciate some hints; I've spent quite some time to solve the  
> problem to no avail.

Not off the top of my head. Not looping to drain all the accumulated  
pages is the most common mistake, and you seem to hav covered that.

That does oggz-validate say about your file (command line tool from  
liboggz)? Can VLC play it?

Also, make sure you're correctly handling the return code from  
ogg_stream_pageout() correctly.

If you still can't get it to work, post a file and I'll take a look  
and see if anything's wrong with it. There were apparently problems  
with DirectShow playing the Ogg files on the Big Buck Bunny DVD.

  -r

Re: Page breaks when encoding ogg/theora

Hi Ralph,

Thanks for your feedback.

After adding a couple more frames and eos to the last frame,
oggzvalidate reports no problem and oggzinfo prints:
Theora: serialno 0000000041
        94 packets in 3 pages, 31.3 packets/page
        Video-Framerate: 30.000 fps
        Video-Width: 512
        Video-Height: 512

Neither the DirectShow filters nor VideoLan can display the ogg file
when using ogg_stream_pageout(). VLC pops up a window for a short
time, but doesn't display anything.

I wrapped all ogg/theora function calls with asserts (see attached
TheoraResourceWriter.cpp/.h). test_pageout.ogv is the problematic
video file and test_flush.ogv the working one. The only difference in
producing these file is line 246/7 in TheoraResourceWriter.cpp.

I call my theora encoder class like so:

    const string fileName =
      TestUtils::getTestDirectory(m_details.suiteName) + FILE_NAME;

    // Write 3s worth of frames.
    TheoraResourceWriter theora(fileName);
    for (unsigned int i = 0; i < 90; i++)
    {
(Continue reading)

Ralph Giles | 13 Jun 00:17
Favicon

Re: Page breaks when encoding ogg/theora

On 11-Jun-08, at 1:48 AM, Claus Höfele wrote:

> Neither the DirectShow filters nor VideoLan can display the ogg  
> file when using ogg_stream_pageout(). VLC pops up a window for a  
> short time, but doesn't display anything.

This looks like a player bug. Both files are valid, and the only  
difference in the packet streams (according to oggzdump) is in the  
frequency of timestamps, due to the different pagination. They both  
play identically with gstreamer and the libtheora player_example.

The issue is exacerbated by your chroma-key purple frames which  
compress really well, so all three seconds of video end up in a  
single page. Does the same thing happen with real output?

To work around the problem, try flushing every n frames or so, and  
see if there's a value of n for which directshow starts working. This  
is a good idea anyway, to limit buffering requirements when the video  
is multiplexed with audio.

  -r
Conrad Parker | 13 Jun 01:00
Favicon
Gravatar

Re: Page breaks when encoding ogg/theora

2008/6/13 Ralph Giles <giles <at> xiph.org>:
>
> To work around the problem, try flushing every n frames or so, and
> see if there's a value of n for which directshow starts working. This
> is a good idea anyway, to limit buffering requirements when the video
> is multiplexed with audio.

just to add to this -- a good tool for debugging this kind of problem
is oggplay-info (in the liboggplay distribution). It shows how far
ahead of each other the video and audio get in a stream, with some
stats about it: the worst and average overruns, and a histogram of
these.

(Yes we have too many tools in too many different packages ...)

Conrad.

Gmane