[XviD-devel] Decoding stream

Marco Filippini marco.filippini at cisitaly.com
Mon Jun 23 13:51:00 CEST 2008


Hi, 

I agree with Stephan, I should have expected an error or an
XVID_TYPE_NOTHING type in the stats, so my code could easily handle the
problem.
Not checking the real length of data passed to the call and use dirty bytes
can lead to unexpected crash.
Hope it will be fixed in the future, in the meantime I will use some
workaround, the hint given by Michael to check for VOP_START_CODE in the
bitstream is a good one.

Best regards

Marco


-----Original Message-----
From: xvid-devel-bounces at xvid.org [mailto:xvid-devel-bounces at xvid.org] On
Behalf Of Michael Militzer
Sent: lunedì 23 giugno 2008 11.43
To: xvid-devel at xvid.org
Subject: Re: [XviD-devel] Decoding stream

Hi,

it is correct that the xvid decoder expects to be fed with full frames all
the time. If you provide less data the decoder may read outside your buffer
and crash or detect the problem, incorrectly decode the frame and return
(the intended behavior).

So to fix your problem you need to ensure that your buffer contains at least
one full frame of data when you call the decoder.

There are several ways how you could do this. If your streams are muxed in
a container format like AVI it should be easy to extract full frames because
e.g. AVI holds a full frame per AVI chunk.

If your streams are not stored in a container that allows you to identify
single frames you could parse for frame boundaries yourself. The beginning
of a frame is marked by VOP_START_CODE (see bitstream.h), so if your buffer
contains at least two such VOP_START_CODEs you should have at least one
full frame of data and it should be ok to call the decoder.

Alternatively, you could also try to make use of VBV parameters in the
stream (see bitstream.c) since frames can't grow larger than the VBV buffer
size (well, normally...).

Regards,
Michael

PS: Note that xvid_decraw expects raw video streams as input. AVI is a
container format to interleave both the audio and video stream in one file,
so trying to decode an AVI file with xvid_decraw will likely fail. You'll
have to demux and extract the raw video stream from AVI first before you
can feed it to the xvid_decraw example.


Quoting Marco Filippini <marco.filippini at cisitaly.com>:

>
>
> 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. L
>
>
>
> _______________________________________________
> XviD-devel mailing list
> XviD-devel at xvid.org
> http://list.xvid.org/mailman/listinfo/xvid-devel
>
>






_______________________________________________
XviD-devel mailing list
XviD-devel at xvid.org
http://list.xvid.org/mailman/listinfo/xvid-devel




More information about the XviD-devel mailing list