Bryce
Bryce

Reputation: 3354

ffmpeg - How does avcodec_decode_video2 work?

As we know, one AVPacket contains one AVFrame, and we can use

int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
                          int *got_frame_ptr, const AVPacket *avpkt)

to decode a packet to frame, if it works, got_frame_ptr will be set with nonzero, otherwise, it's zero.

int len = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
if ( len < 0 )
{
    fprintf(stderr, "Problems decoding frame\n");
    return 1;
}

fprintf(stderr, "len = %d\n", len );

// Did we get a video frame?
if(frameFinished) {
    dosomething();
}

How would it fail(got_frame_ptr is 0)? Is the AVPacket we got corrupted or something else?

Upvotes: 1

Views: 8098

Answers (1)

rajneesh
rajneesh

Reputation: 1749

there are 2 main reasons (apart from error)

  1. The current frame is a future P-Frame, hence this cannont be retured (displayed) now. This happens in case of B-frames in the sequence.

  2. The current packet is not a complete decodable frame.

Upvotes: 2

Related Questions