On 2009-08-05 at 15:34:01 [+0200], Sven Alisch <[email protected]> wrote:
> OK I found my problem. swscale is not guilty. But a solution is far away.
>
> I copied some h.264 coded frames in to a buffer and let av_decode_video()
> decode it. The stream in the buffer started with an i-slice. I get some
> frames decoded all these pictures have the same size and are not
> displayable. Damn. But if I save my buffer into a file named buffer.264
> the mplayer shows me my extracted pictures. So what is my fault?
>
> BTW. My decoding function looks like this (its a terrible test code but
> for mpeg2 it worked):
>
> <snip>
> do
> {
> if (packet.stream_index == mStreamID)
> {
> memcpy(&h264buffer[bufP], packet.data, packet.size);
> bufP += packet.size;
> if (framesToCopy == 0)
> {
> decoding = true;
> }
> else
> decoding = false;
>
> framesToCopy--;
> }
>
> if (decoding)
> {
> if (mPCodecCtx->codec_id == CODEC_ID_H264)
> {
> do
> {
> bytesDecoded = avcodec_decode_video(mPCodecCtx, frame,
> &frameFinished,
> h264buffer, bufP);
> } while (!frameFinished);
This loop does not work, because you need to fetch the next packet into
h264buffer. With mpeg2, it probably only works because frameFinished is
always true after the first iteration for the streams you tested.
> }
>
> if (frameFinished && decoding)
> {
> cout << frame->pict_type << " dekodiert!" << endl;
> break;
> }
> }
> }
> } while (mPAVFile->readFrame(filenr, &packet) >= 0);
> <snap>
Is that really all of your demuxing loop? Because then you are accessing
the packet before reading the first frame.
A decoding loop looks more like this (pseudo code):
bool decode_one_frame(...)
{
while (true) {
uint8_t* buffer;
int size;
// fetch_next_chunk makes "buffer" point to the data and tells
// the size of this buffer in "size".
if (!fetch_next_chunk(&buffer, &size))
break;
int gotPicture = 0;
int len = avcodec_decode_video(..., &gotPicture, buffer, size);
// len is ignored in all the examples I read
if (gotPicture) {
// do something with the picture, like color conversion,
// deinterlacing...
return true;
}
}
return false;
}
So you wouldn't first collect chunks and then do the decoding, but instead
read chunks for each call to avcodec_decode_video(), until gotPicture is
true.
Best regards,
-Stephan
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user