SharpFFmpegを呼び出すFFmpegライブラリのC#バインディングを使用して、RTPで受信したH264ビデオストリームをデコードしようとしています。NLUをRTPパケットから正しくカプセル化解除したと思いますが、完全なフレームをデコードできません。関数avcodec_decode_videoの呼び出しは、AccessViolationException(保護されたメモリの読み取りまたは書き込みを試みました)をスローします。
ここにいくつかのコード行があります:
//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
関数は次のようにインポートされました。
[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);
残念ながら、codecContをどうする必要があるのかわかりません。誰かが、RTSPが受信したセッションの説明を使用してAVCDCRでこの構造を埋める必要があると書いています。しかし、どのフィールドにこのレコードが保存されているのかわかりません。
助けていただければ幸いです。
PSすみません英語で