protected override void DisposeUnmanaged() { fixed(AVPacket *p = &_pkt) { FFmpegInvoke.av_free_packet(p); } FFmpegInvoke.avcodec_close(_codec_context); FFmpegInvoke.av_free(_codec_context); FFmpegInvoke.av_freep(&_avFrameYUV->data_0); fixed(AVFrame **p = &_avFrameYUV) { FFmpegInvoke.avcodec_free_frame(p); } FFmpegInvoke.av_freep(&_avFrameBGR->data_0); fixed(AVFrame **p = &_avFrameBGR) { FFmpegInvoke.avcodec_free_frame(p); } }
public byte[] EncodeFrame(IntPtr rgb) { fixed(AVPacket *packet = &_pkt) { FFmpegInvoke.av_init_packet(packet); _pkt.data = null; _pkt.size = 0; FFmpegInvoke.avpicture_fill((AVPicture *)_avFrameBGR, (byte *)rgb, INPUT_PIXEL_FORMAT, _avFrameBGR->width, _avFrameBGR->height); var convertedBytes = _converter.ConvertFrame(_avFrameBGR); fixed(byte *yuv = &convertedBytes[0]) { FFmpegInvoke.avpicture_fill((AVPicture *)_avFrameYUV, yuv, CODEC_PIXEL_FORMAT, _avFrameYUV->width, _avFrameYUV->height); } int got_output; var ret = FFmpegInvoke.avcodec_encode_video2(_codec_context, packet, _avFrameYUV, &got_output); if (ret < 0) { throw new Exception("Error encoding frame"); } if (got_output != 0) { byte[] arr = new byte[_pkt.size]; Marshal.Copy((IntPtr)_pkt.data, arr, 0, _pkt.size); FFmpegInvoke.av_free_packet(packet); return(arr); } else { return(null); } } }