我想使用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);
}
但是encode函数返回的值总是-1(错误)。有人能指出我在这里失踪的东西。 任何帮助将受到高度赞赏。感谢。