[Libav-user] FFMPEG decode video packet with avcodec_send_packet avcodec_receive_frame

Jérôme SALAYET jerome.salayet at hymatom.fr
Tue Sep 8 13:09:45 EEST 2020

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);
         { 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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200908/07590b9b/attachment.html>

More information about the Libav-user mailing list