title: Not able to decode mp4 file using latest ffmpeg library : av_decode_video2
body: <p>I am writing a wrapper code around latest ffmpeg library. I am supplying MP4 files from local system. My problem is that I am unable to get any decoded frames when I use <code>av_decode_video2()</code>. The return value comes out to be negative. I have used <code>av_read_frame()</code> which returns 0. I googled about the problem I am facing but no where could I find the correct explanation. Please give me insight here. Pasting the pseudo code here.</p>
  
  <pre><code>    av_init_packet(avpkt);
      picture=av_frame_alloc();
      pFrameRGB=av_frame_alloc();
      codec = avcodec_find_decoder(CODEC_ID_H264);
      c= avcodec_alloc_context3(codec)
      avcodec_open2(decoderLibraryData-&gt;c, decoderLibraryData-&gt;codec, NULL)
      FormatContext = avformat_alloc_context();
      char *pUrl ="./1.MP4";
  
      iRet = avformat_open_input(atContext, pUrl, pFmt, NULL);
  
      if(FormatContext == NULL)
      {
          printf("could not assign any memory !!!!!!!!! \n");
      }
  
      avformat_find_stream_info(FormatContext, NULL);
  
  
      while(av_read_frame(FormatContext,avpkt) &gt;= 0)
      {
  
        len = avcodec_decode_video2(c, picture, &amp;got_picture,avpkt);
  
        printf("CODEC MANAGER len %d Frame decompressed %d \n",len,got_picture);
  
        if (len &lt;= 0) 
        {
          return ERROR;
        }
      }
  }
  
  
  
          if(lastHeight != 0 &amp;&amp; lastWidth != 0)
          {
              if(lastWidth != c-&gt;width || lastHeight != c-&gt;height )
              {
                  av_free(buffer);
                  buffer = NULL;
                  lastWidth = c-&gt;width;
                  lastHeight = c-&gt;height;
  
              }
          }
          else
          {
              lastWidth = c-&gt;width;
              lastHeight = c-&gt;height;
          }
          decodeFlag = 1;
          if(!buffer)
          {
              int numBytes;
              v_mutex_lock(globalCodecLock);
              switch(inPixFormat)
              {
              case RGB:
  
  
                  // Determine required buffer size and allocate buffer
                  numBytes=avpicture_get_size(PIX_FMT_RGB24, c-&gt;width, c-&gt;height);
  
                  buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
                  avpicture_fill((AVPicture *)pFrameRGB,buffer,PIX_FMT_RGB24,c-&gt;width, c-&gt;height);
  
                  if(cntxt)
                      sws_freeContext(cntxt);
  
                  cntxt = sws_getContext(c-&gt;width, c-&gt;height, c-&gt;pix_fmt,
                          c-&gt;width, c-&gt;height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
  
                  break;
  
              }
              v_mutex_unlock(globalCodecLock);
              if(cntxt == NULL)
              {
                  printf("sws_getContext error\n");
                  return ERROR;
              }
              }
  
          {
              sws_scale(cntxt, picture-&gt;data, picture-&gt;linesize, 0, c-&gt;height, pFrameRGB-&gt;data, pFrameRGB-&gt;linesize);
              if(rgbBuff)
              {
  
  
                  if(c-&gt;width &lt;= *width &amp;&amp; c-&gt;height &lt;= *height)
                  {                   
                      saveFrame(pFrameRGB, c-&gt;width, c-&gt;height, rgbBuff,inPixFormat);
  
                      *width = c-&gt;width;
                      *height = c-&gt;height;
                      rs = SUCCESS;
                      break;
                  }
                  else
                  {
                      rs = VA_LOWBUFFERSIZE;
                  }
              }
              else
              {
                  rs = VA_LOWBUFFERSIZE;
              }
          }
          if(width)
          {
              *width = c-&gt;width;
          }
          if(height)
          {
              *height = c-&gt;height;
          }
          if(rs == VA_LOWBUFFERSIZE)
          {
              break;
          }
  </code></pre>
  
  <p>I am getting the return value of <code>av_read_frame</code> as 0 but <code>av_decode_video2</code> returns value in negative. I am not able to get any clue here.</p>