title: FFMPEG - avcodec_decode_video2 return "Invalid frame dimensions 0x0"
body: <p>I am trying to build a simple FFMPEG MPEG2 video PES decoder on ANDROID using the ffmpeg/doc/example/decoding__encoding_8c-source.html.</p>
  
  <p>I am using FFMPEG version 2.0!</p>
  
  <p>I initialize the ffmpeg system with the following code:</p>
  
  <pre><code>int VideoPlayer::_setupFFmpeg()
  {
      int rc;
      AVCodec *codec;
  
      av_register_all();
      codec = avcodec_find_decoder(AV_CODEC_ID_MPEG2VIDEO);
      if(NULL == codec){
          LOGE("_setupFFmpeg. No codec!");
          return -1;
      }
      LOGI("found: %p. name: %s", codec, codec-&gt;name);
  
      _video_dec_ctx = avcodec_alloc_context3(codec);
      if(NULL == _video_dec_ctx){
          LOGE("_setupFFmpeg. Could not allocate codec context space!");
          return -1;
      }
      _video_dec_ctx-&gt;debug = FF_DEBUG_PICT_INFO;
      if(codec-&gt;capabilities &amp; CODEC_CAP_TRUNCATED) _video_dec_ctx-&gt;flags |= CODEC_FLAG_TRUNCATED;
  
      rc = avcodec_open2(_video_dec_ctx, codec, NULL);
      if(rc &lt; 0) {
          LOGE("_setupFFmpeg. Could not open the codec: %s!", _video_dec_ctx-&gt;codec-&gt;name);
          return -1;
      }
  
      av_init_packet(&amp;_avpkt);
  
      if(NULL == _video_frame) _video_frame = avcodec_alloc_frame();
      if(NULL == _video_frame){
          LOGE("_setupFFmpeg. Could not allocate memory for the video frame!");
          return -1;
      }
  
      LOGI("_setupFFmpeg(exit)");
      return 0;
  }
  </code></pre>
  
  <p>And then just having a loop that is continuously sending PES packets at the decoder calling this function:</p>
  
  <pre><code>int VideoPlayer::_playVideoPacket(PesPacket *packet)
  {
      int len, frameReady;
      _avpkt.data = packet-&gt;buf;
      _avpkt.size = packet-&gt;info.bufferSize;
      while(_avpkt.size){
          len = avcodec_decode_video2(_video_dec_ctx, _video_frame, &amp;frameReady, &amp;_avpkt);
          if(len &lt; 0){
              LOGE("FFW_decodeVideo");
              return len;
          }
          if(frameReady){
              //Draw the picture...
          }
          _avpkt.size -= len;
          _avpkt.data += len;
      }
      return 1;
  }
  </code></pre>
  
  <p>But when I run the code I get:
  "Invalid frame dimensions 0x0" error from FFMPEG after calling avcodec_decode_video2().</p>
  
  <p>It seems that I am not setting up the codec correctly. The MpegEncContext in Mpeg1Context in mpeg12dec.c is not setup correctly. What do I have to do to setup MpegEncContext correctly?</p>