title: FFmpeg (sharpFFmpeg) decoding - Protected memory error
body: <p>I'm trying to use C# binding of FFmpeg library calling SharpFFmpeg to decode H264 video stream that I receive by RTP. I think I correctly decapsulate NALUs from RTP-packets, but I can't decode complete frames. Function avcodec_decode_video calling throws an AccessViolationException (Attempted to read or write protected memory).<br>
  Here are some code lines:</p>
  
  <pre><code>    //buf is a byte array containing encoded frame
      int success;
      FFmpeg.avcodec_init();
      FFmpeg.avcodec_register_all();
      IntPtr codec = FFmpeg.avcodec_find_decoder(FFmpeg.CodecID.CODEC_ID_H264);
      IntPtr codecCont = FFmpeg.avcodec_alloc_context(); //AVCodecContext
      FFmpeg.avcodec_open(codecCont, codec);
      IntPtr frame = FFmpeg.avcodec_alloc_frame();  //AVFrame
      FFmpeg.avcodec_decode_video(codecCont, frame, ref success, (IntPtr)buf[0], buf.Length); //exception
  </code></pre>
  
  <p>Function has been imported as follows:</p>
  
  <pre><code>    [DllImport("avcodec.dll", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
      public unsafe static extern int avcodec_decode_video(IntPtr pAVCodecContext, IntPtr pAVFrame, ref int got_picture_ptr, IntPtr buf, int buf_size);
  </code></pre>
  
  <p>Unfortunately, I don't know what do I have to do with the codecCont. Somebody wrote that it is needed to fill this structure by AVCDCR using session description received by RTSP. But I don't know which field(s) store this record.<br>
  I'll be glad for any help.<br>
  P.S. Excuse me for my English</p>