[theora] Page breaks when encoding ogg/theora
claus.hoefele at gmail.com
Tue Jun 10 20:20:59 PDT 2008
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:
- 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 **
- 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
ogg_stream_pageout() to write pages on demand, the video doesn't play
in Windows Media Player using the latest ogg/theora DirectShow
When using ogg_stream_pageout(), I'm making sure that all the
remaining pages are flushed at the end; it still doesn't work.
This is a hex dump of the page after the comment pages. This page
should contain 3 frames; no eos set. The frames are extremely simple
(Y, U, V all set to 0xc8, 512x512).
- header (30 bytes)
0x0012F33C 4f 67 67 53 00 00 42 00 00 00 00 00 00 00 29 00 OggS..B.......).
0x0012F34C 00 00 02 00 00 00 a2 31 5b d2 03 13 09 09 ......¢1[Ò....
- body (37 bytes)
0x0196BBD8 30 00 0b 89 69 f7 ff ee 17 27 d3 ff b8 5c 9f 4f 0...i÷ÿî.'Óÿ¸\ŸO
0x0196BBE8 ff 83 00 7a 3f 15 e7 e2 bd e0 00 00 7a 3f 15 e7 ÿƒ.z?.çâ.à..z?.ç
0x0196BBF8 e2 bd e0 00 00
As mentioned, when using ogg_stream_flush() after every frame, it
works. The size of the resulting file is similar.
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.
Windows XP/MSVC++ 2005
More information about the theora