Ribamar Santarosa de Sousa
2006-Aug-24 18:26 UTC
[theora] trying to encode/decode videos using libtheora
I'm trying to learn how to use libtheora but I'm having some problems: I believe to have encoded a video, but I can't decode it. I've tried 2 things: to record a .ogg file and to write a libtheora decoder, using the encoded ogg_packets present in memory. The source code is here: http://opensvn.csie.org/ribamar/projects/streaming/cvaenc.c (it has a makefile in http://opensvn.csie.org/ribamar/projects/streaming/Makefile and requires highgui and opencv to compile, in debian and ubuntu with universe it must be trivial to install them with apt-get install libhighgui-dev libcv-dev) 1) generating the ogg files: ./cvaenc > a.ogg It generates this ogg file: http://opensvn.csie.org/ribamar/projects/streaming/a.ogg but mplayer can't play it: Playing a.ogg. Ogg : Warning found none bos page from unknown stream 0 Ogg : Warning found none bos page from unknown stream 0 Win32 LoadLibrary failed to load: avisynth.dll, /usr/lib/win32/avisynth.dll, /usr/local/lib/win32/avisynth.dll libavformat file format detected. LAVF_header: av_open_input_stream() failed 2) trying to decode it by myself: theora_decode_init(&ts, &thi) gives me a segmentation fault. Can anyone help me? Thanks, Ribamar
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.cI'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){ fwrite(page.header,1,page.header_len,fout); fwrite(page.body,1,page.body_len,fout); } 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, -r