gaby
gaby

Reputation: 23

ffmpeg avcodec_decode_video2 function error codes

i use at the function avcodec_decode_video2 at the flowing way:

if (packet.isEOF()) {
    AVPacket eofpkt;
    av_init_packet(&eofpkt);
    eofpkt.data = NULL;
    eofpkt.size = 0;
    ret = avcodec_decode_video2(d.codec_ctx, d.frame, &got_frame_ptr, &eofpkt);
} else {
    ret = avcodec_decode_video2(d.codec_ctx, d.frame, &got_frame_ptr, (AVPacket*)packet.asAVPacket());
}
//qDebug("pic_type=%c", av_get_picture_type_char(d.frame->pict_type));
d.undecoded_size = qMin(packet.data.size() - ret, packet.data.size());
if (ret < 0) {
    //qWarning("[VideoDecoderFFmpegBase] %s", av_err2str(ret));
    return false;
}
if (!got_frame_ptr) {
    qWarning("no frame could be decompressed: %s %d/%d", av_err2str(ret), d.undecoded_size, packet.data.size());
    return !packet.isEOF();
}

When i run it I get an error (I go inside if(!got_frame_ptr) ) and in the printing i get that ret value's is: 203,3053,5120 (or more accurate tis is my printings:

Warning: "no frame could be decompressed: Error number 203 occurred 0/203" Warning: "no frame could be decompressed: Error number 3053 occurred 0/3053" Warning: "no frame could be decompressed: Error number 5120 occurred 0/5120"

(av_err2str(ret) just print decorated ret, nothing more))

the avcodec_decode_video2 docomentatin said: On error a negative value is returned, otherwise the number of bytes used or zero if no frame could be decompressed.

i'm not in situation that avcodec_decode_video2 return me negative value, but i do get zero at got_frame_ptr , instead of got_frame_ptr will be the same value as ret like doc. said i get this odd value (203,3053,5120).

my questions is:

  1. what this error code means? (i search at ffmpeg doc. and i didn't found a good record on what every numeric value should represent)

  2. why i get this values from this function? is it ffmpeg bug? or did i didn't understand ffmpeg currectly?

thank you g.

Upvotes: 2

Views: 1187

Answers (1)

Ronald S. Bultje
Ronald S. Bultje

Reputation: 11174

It's not an error to not finish decompressing a frame, frame decoding tends to be delayed by a few frames to enable frame multi-threading.

[edit] In other words, if ret >= 0 && got_frame_ptr == 0, just continue as normal and assume it was successful but output was delayed. The delayed data will come back at the end when flushing the queue with NULL packets.

Upvotes: 2

Related Questions