SharpFFmpegを使用して生のフレーム (byte[]) を H264 にエンコードしたい。コードは次のとおりです。
public void Encoder(byte[] capturedFrame)
{
int returnValue;
FFmpeg.avcodec_init();
FFmpeg.avcodec_register_all();
IntPtr codec = FFmpeg.avcodec_find_encoder(FFmpeg.CodecID.CODEC_ID_H264);
IntPtr codecCont = FFmpeg.avcodec_alloc_context(); //AVCodecContext
FFmpeg.avcodec_open(codecCont, codec);
IntPtr frame = FFmpeg.avcodec_alloc_frame(); //AVFrame
IntPtr encodedFramePtr = new IntPtr();
///// byte[] to IntPtr
IntPtr unmanagedPointer = Marshal.AllocHGlobal(capturedFrame.Length);
Marshal.Copy(capturedFrame, 0, unmanagedPointer, capturedFrame.Length);
returnValue = FFmpeg.avcodec_encode_video(codecCont, encodedFramePtr, capturedFrame.Length, unmanagedPointer);
Console.WriteLine("Return value is {0}", returnValue); // return value is always "-1"
Console.Read();
// Call unmanaged code
Marshal.FreeHGlobal(unmanagedPointer);
}
しかし、エンコード関数によって返される値は常に -1 (エラー) です。誰かが私がここで見逃していることを指摘できますか? どんな助けでも大歓迎です。ありがとう。