PDA

View Full Version : Decoding stream


2dpikke
18th June 2008, 14:18
I’m trying to decode a stream, but I’m stuck with a problem.
I’ve tried to follow the xvid_decraw sample converting it into C#, using pointers where needed.
Basically I have a loop where I read bytes from the stream into a fixed size buffer of 1024 * 1024 bytes until the end of the stream is reached, then another nested loop iterates through the encoded frames inside the buffer to decode them until the bytes of the buffer are done incrementing the pointer to the buffer of the bytes used.
I check the stats for each call to the decode function to analyze the frame type (VOL, NOTHING, IVOP, PVOP etc.) and take the necessary action.
Everything is fine until I’m close to the end of the buffer, the last call to the decode function returns a value of used bytes greater of the length property of the xvid_dec_frame_t structure.
Since then the decoded frames are wrong.
I’ve tried not to increment the bytes used in this last case, so they can be reused with the following buffer fill, but it doesn’t work.
The only workaround I’ve found is to avoid the last calls and exit the inner loop with an amount of bytes still to be used, but this amount is not easily predictable.
Somewhere in the forums I’ve read that the decode function wants to eat a full frame each time it is called, is it true?
Does anybody have a workable solution?
I don’t mind to break my code if is wrong, I havent’t find any updated docs on xvid but the sample in the sources.

Thank you in advance

Marco

P.S. I’ve compiled the sources and the sample, and I’ve tried to use the xvid_decraw executable with an avi xvid file containing a tv movie, but it fails with a crash. :scared:

Koepi
20th June 2008, 07:13
Hi Marco,

I don't know an answer to the question what is wrong with your code. I fear you won't get that answer here (this is more a user forum than a developer meeting point). This is a case where you should subscribe to the Xvid developer mailinglist. Many developers are discussing their problems there. It's much more likely that you get a proper answer there than here (and probably much faster). You can try to search for your problem description in the xvid-devel-archives over at xvid.org: http://list.xvid.org/pipermail/xvid-devel/

Subscribe to the developer list here: http://www.xvid.org/Mailinglists.51.0.html

Cheers
Koepi

sysKin
20th June 2008, 12:59
Xvid doesn't check if it received enough data. You *must* accumulate at least one full frame in your buffer before decoding it, or else Xvid will read too much and either produce garbage or crash.

Typically it's some higher level transport stream that keeps individual frame lengths. If you don't have it, you have to buffer "enough" just like xvid_decraw does, and that's probably a bad solution.

squid_80
22nd June 2008, 13:31
It's not a bad idea to pad the end of the decompression input buffer with about four non-zero bytes (don't include them in the reported length). The b-frame resync marker check does not respect the length of the input buffer, and if it does mistakenly find one there will be trouble. The padding should prevent this.

(This is the cause of the mysterious virtualdub "Show decompressed output" bug BTW. Doesn't happen with recent virtualdub builds.)