ffmpeg - avcodec_receive_frame returns -11,为什么以及如何解决?

ffmpeg - avcodec_receive_frame returns -11, why and how to solve it?

我正在学习在我的引擎中使用 ffmpeg,

我想解码视频流的第一帧并将其输出到图像文件。

我试过了,只是想不通为什么会这样 returns -11.

我的代码:(最后5行代码错误,第70-74行)

Link to my code

这是您的代码(第 70 - 74 行):

res = avcodec_receive_frame(pCodecContext, pFrame);
if (res != 0)
{
    return EXIT_FAILURE;
}

让我们看看文档对相关函数有什么看法 (avcodec_receive_frame):

Returns

0: success, a frame was returned
AVERROR(EAGAIN): output is not available in this state - user must try to send new input
AVERROR(EOF): the decoder has been fully flushed, and there will be no more output frames
AVERROR(EINVAL): codec not opened, or it is an encoder >
other negative values: legitimate decoding errors

您只需执行以下操作:

switch (res) {
default: puts("unknown result"); break;
case 0: puts("success"); break;
case AVERROR(EAGAIN): puts("output is not available"); break;
//... you get the idea
}