[Libav-user] Pb H264 avcodec_decode_video2 avcodec54 to avcodec55

Jérôme SALAYET jerome.salayet at hymatom.fr
Thu Jul 4 16:37:18 CEST 2013


Hi to All. I use FFMPEG 1.2 in my software to decompress H264 video packet from IP camera. I have on some error in the log like Frame Num Gap or concealing 3600 DC, 3600 AC, 3600 MV errors in P frame,top block unavailable for requested intra mode at 35 2, error while decoding MB 35 2, concealing 3600 DC, 3600 AC, 3600 MV errors in I frame ".....

 

I see there is a new version of FFMPEG, with avcodec55.dll, ... which fix somes bugs on h264

 

But my code work perfect with FFMPEG1.2 and doesn"t work with the last dll files of FFMPEG ,I get them on Latest Zeranoe FFmpeg Build Version: git-e0be3cb (2013-07-03). it seems with the last avcodec file, the function  avcodec_decode_video2 return me 0 and in the log I have "no frame"
...
 
If someone can explain me what' s the major difference between the version 1.2 and the lastest one, beacsue I'm looking for the major changes, but I can't understand why my code below doesn't work.
 
Thanks for yours answers

 

Variables:

AVPixelFormat           m_AVPixelFormat;

AVCodecContext*     m_lpCodecCtx;

AVCodec*                  m_lpCodec;

AVFrame*                  m_lpFrame;

AVPacket                   m_lpPacket;

AVPicture                   m_lpPict;

SwsContext*              m_lpSwsContext;

INT                             m_iThreadCount;

LPBYTE                     m_lpFFMPEGBuffer;

INT                              iImageWidth, iImageHeigh;

         

Of course I before init libraries :

av_register_all();

av_lockmgr_register(&ff_lockmgr);

 

with 

 

static int ff_lockmgr(void **mutex, enum AVLockOp op)

//////////////////////////////////////////////////////////////////////////////////////////////////////

{ CRITICAL_SECTION **cSec = (CRITICAL_SECTION **)mutex;

  switch (op) 

   { case AV_LOCK_CREATE:

      { *cSec = new CRITICAL_SECTION();

        if (*cSec == NULL) return 1;

        InitializeCriticalSection(*cSec);

        return 0;

      }  

     case AV_LOCK_OBTAIN:

      { if (*cSec == NULL) return 1;

        EnterCriticalSection(*cSec);

        return 0;

      } 

     case AV_LOCK_RELEASE:

      { if (*cSec == NULL) return 1;

        LeaveCriticalSection(*cSec);

        return 0;

      }  

     case AV_LOCK_DESTROY:

      { if (*cSec == NULL) return 1;

        DeleteCriticalSection(*cSec);

        delete *cSec;

        *cSec = NULL;

        return 0;

      }

   }

  return 0;

}

 

The lpImageData and dwImageSize I decode is a whole frame I receive from RTP packet from the camera and I « format » to send to FFMPEG decoder

I also ahve verify the iImageWidth and iImageHeight are well set too.

 

 

BOOL FFMpegDecompress( LPBYTE lpImageData, DWORD dwImageSize)

{        if (m_lpCodec==NULL)

      { // find_decoder

            m_lpCodec = avcodec_find_decoder(CODEC_ID_H264);

      }

     

     if ((m_lpCodec != NULL)&&(m_lpCodecCtx == NULL))

      { // Alloc codecContext

        m_lpCodecCtx = avcodec_alloc_context3(m_lpCodec);

        if (m_lpCodecCtx != NULL)

         { // Init  CodecContext

           if (m_lpCodecCtx->width == 0)

            { m_lpCodecCtx->pix_fmt           = AV_PIX_FMT_YUV420P;

              m_lpCodecCtx->codec_type        = AVMEDIA_TYPE_VIDEO;

              m_lpCodecCtx->codec_id          = CODEC_ID_H264;

              m_lpCodecCtx->coded_width       = iImageWidth;

              m_lpCodecCtx->coded_height      = iImageHeight;

              m_lpCodecCtx->width             = iImageWidth;

              m_lpCodecCtx->height            = iImageHeight;

              m_lpCodecCtx->thread_count      = 3;

              m_lpCodecCtx->thread_type       = FF_THREAD_SLICE;

              m_lpCodecCtx->err_recognition   = AV_EF_EXPLODE;

            }

         }   

      }

     dwWidth  = iImageWidth;

     dwHeight = iImageHeight;

     // open decoder if not...    

     if ((m_lpCodecCtx!=NULL) && (m_lpCodec!=NULL)&&(!lpfnavcodec_is_open(m_lpCodecCtx)))

      { if ( m_lpCodec != NULL)

         { if(m_lpCodec->capabilities&CODEC_CAP_TRUNCATED) 

            m_lpCodecCtx->flags|= CODEC_FLAG_TRUNCATED;

      

           iResult = avcodec_open2( m_lpCodecCtx,  m_lpCodec, &optionsDict);

           // if error

           if (iResult < 0)

            { avcodec_close(m_lpCodecCtx);

              av_free(m_lpCodecCtx);

              m_lpCodecCtx = NULL;

              m_lpCodec    = NULL;

            }

         }

      }

     

     if ((m_lpCodecCtx!=NULL) && (m_lpCodec!=NULL))

      { // Allouer la frame video 

        if (m_lpFrame == NULL)

         { m_lpFrame = avcodec_alloc_frame();

         }

        // Si l'allocation à réussi

        if (m_lpFrame!=NULL)

         { // Affecter les dimensions

           m_lpFrame->width  = m_lpCodecCtx->width;

           m_lpFrame->height = m_lpCodecCtx->height;

         }

        

        if ((m_lpCodecCtx != NULL) && ( m_lpCodec != NULL) &&(m_lpFrame != NULL) && (pddsDesc != NULL))

        if ((dwWidth>0)&&(dwHeight>0))

         { int iRes = 0;

           // init  packet 

           av_init_packet(&m_lpPacket);

           if (m_lpFFMPEGBuffer == NULL)

            { m_lpFFMPEGBuffer = new BYTE[MAX_MPEG4VIDEO_FRAMESIZE+FF_INPUT_BUFFER_PADDING_SIZE];

            }

           if (m_lpFFMPEGBuffer !=NULL)

            { ZeroMemory( m_lpFFMPEGBuffer, MAX_MPEG4VIDEO_FRAMESIZE+FF_INPUT_BUFFER_PADDING_SIZE);

              CopyMemory(m_lpFFMPEGBuffer, lpImageData, dwImageSize);

            } 

              

           // set data

           m_lpPacket.data = m_lpFFMPEGBuffer;

           // Set size

           m_lpPacket.size = dwImageSize; 

           // Decode  H264

           if ((m_lpFrame!=NULL)&&(m_lpPacket.size>0))

            { while (m_lpPacket.size>0)

               { iRes = navcodec_decode_video2( m_lpCodecCtx, m_lpFrame, &iFrameFinished, &m_lpPacket);

                 if (iRes<=0)

                  { break;

                  }

                 if (iRes>0)

                  { m_lpPacket.data+=iRes;

                    m_lpPacket.size-=iRes;

                  }

               }

            }

 

           // free Packet

           av_free_packet(&m_lpPacket); 

         }

      }

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130704/d4d4d0ca/attachment.html>


More information about the Libav-user mailing list