I'm learning to use ffmpeg in my engine,
and I wanna decode the first frame of video stream and output it to an image file.
I tried and just can't figured out why it returns -11.
My code:(error in last 5 lines of code, line 70-74)
CodePudding user response:
This is your code (line 70 - 74):
res = avcodec_receive_frame(pCodecContext, pFrame);
if (res != 0)
{
return EXIT_FAILURE;
}
Let's see, what the documentation has to say about the related function (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
You could just do the following:
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
}