[Libav-user] trouble decoding bitstream

Alex Cohn alexcohn at netvision.net.il
Fri Sep 2 19:41:59 CEST 2011


On Thu, Sep 1, 2011 at 22:11, jpkouma <jpkouma at gmail.com> wrote:
> Hi everybody,
> I would like to decode the bitstream *outbuf* as it is encoded from
> *enc_picture* as below:
>
> *out_size = avcodec_encode_video(c, outbuf, outbuf_size, enc_picture);*
>
> then decode that buffer into the frame *dec_picture*:
>
> *packet.data = outbuf;
> packet.size = out_size;
> while (packet.size>0) {
>        len = avcodec_decode_video2(c, dec_picture, &got_picture, &packet);
>         if (got_picture) { // Stream succesful decoded
>                 printf("Decoded %d bytes", len);
>         }
>         packet.size -= len;
>         packet.data += len;
> }*
>
> The issue is that *got_picture *is always returning 0, even though *len* is
> grater than 0. The codec id is *CODEC_ID_MPEG4*.

If I understand your data flow correctly, you always encode one raw
frame, and then send the result to decoder. The answer (len>0,
got_picture==0) is expected in this scenario. It means that the
decoder has stored a frame or two (or more) in its framebuffer, and
will deliver them later. The actual loop should include two
conditions:

while (len>0 || got_picture) { ... }

Note that the call to avcodec_decode_video2() should be expressed this way:

avcodec_decode_video2(c, dec_picture, &got_picture, len ? &packet : NULL);

> Thankful for any help

Cheers,
Alex


More information about the Libav-user mailing list