The correct process is described at https://ffmpeg.org/doxygen/3.3/group__lavc__encdec.html.
To summarize: after each call to avcodec_send_packet, you loop, calling avcodec_receive_frame and processing returned frames until you get AVERROR(AGAIN) or an error. When you get AVERROR(AGAIN), it is time to call avcodec_send_packet with the next received packet, then start the loop again. Any other non-zero return from avcodec_receive_frame is a real error, which you have to deal with as you wish. Note that you can receive 0, 1, or more frames for each packet you send, depending on the codec. When encoding, it is the same, with avcodec_send_frame and avcodec_receive_packet. - Richard On Tue, Sep 8, 2020 at 6:09 AM Jérôme SALAYET <[email protected]> wrote: > Hello, > > I recently want to use the last FFMPEG release version to decode video > packets. avcodec_decode_video2 is deprecated so I want to use > avcodec_send_packet > and avcodec_receive_frame > > > > I’m just not sure waht about doing when receiving eror like > AVERROR(EAGAIN), AVERROR_EOF… my code is below. > > > > int FFMpegImgDecode( AVCodecContext* lpCodecCtx, AVPacket* lpAVPacket, > AVFrame* lpAVFrame) > > { int iResult = 1; > > int iDecodeResult = 1; > > > > > > if ((lpCodecCtx!=NULL) && (lpAVFrame!=NULL) && (lpAVPacket!=NULL)) > > { if (m_lpCodecCtx->codec_type == AVMEDIA_TYPE_VIDEO) > > { iResult = lpfnavcodec_send_packet( m_lpCodecCtx, &m_lpPacket); > > if (iResult == AVERROR_EOF) > > { iResult = 0; > > } > > if (iResult == 0) // success > > { iDecodeResult = lpfnavcodec_receive_frame(m_lpCodecCtx, > m_lpFrame); > > // iDecodeResult == 0 => Success > > // iDecodeResult == AVERROR(EAGAIN)) => Need to feed the next > input frame > > // else => Error > > if (iDecodeResult==AVERROR(EAGAIN)) > > { printf("avcodec_receive_frame ERROR [AVERROR(EAGAIN)]\r\n"); > > } > > if ((iDecodeResult!=0) && (iDecodeResult!=AVERROR(EAGAIN))) > > { char szErrorText[255]; > > av_strerror( iResult, szErrorText, sizeof(szErrorText)); > > printf("avcodec_receive_frame ERROR [%i][%s]\r\n", iResult, > szErrorText); > > } > > } > > else > > { char szErrorText[255]; > > av_strerror( iResult, szErrorText, sizeof(szErrorText)); > > printf("avcodec_send_packet ERROR [%i][%s]\r\n", iResult, > szErrorText); > > iDecodeResult = iResult; > > > > } > > } > > } > > return iDecodeResult; > > } > > > > Also sometimes I receive error : avcodec_send_packet ERROR > [-1094995529][Invalid data found when processing input]. > > It is when I decompress a h264 video stream from a camera. Do you think it > is possible that this error can arrive if I have some network trouble with > the camera. > > > > Regards, > > > > > > > > > > > _______________________________________________ > Libav-user mailing list > [email protected] > https://ffmpeg.org/mailman/listinfo/libav-user > > To unsubscribe, visit link above, or email > [email protected] with subject "unsubscribe".
_______________________________________________ Libav-user mailing list [email protected] https://ffmpeg.org/mailman/listinfo/libav-user To unsubscribe, visit link above, or email [email protected] with subject "unsubscribe".
