void ReleaseRenderTexture(object encoderLock)
        {
            if (_cameraOutputTexture != null)
            {
                _cameraOutputTexture.Release();
            }
            _cameraOutputTexture = null;

            if (_vidEnc != IntPtr.Zero && _vCfgEnc != IntPtr.Zero && _vTxfEnc != IntPtr.Zero &&
                _aCfgEnc != IntPtr.Zero && _audEnc != IntPtr.Zero)
            {
                IntPtr _vidEncCopy  = _vidEnc;
                IntPtr _vCfgEncCopy = _vCfgEnc;
                IntPtr _vTxfEncCopy = _vTxfEnc;
                IntPtr _aCfgEncCopy = _aCfgEnc;
                IntPtr _audEncCopy  = _audEnc;


                int msTimeout = 1000 / MixCastAV.chunksPerSec;

                new Thread(() =>
                {
                    lock (encoderLock)
                    {
                        Thread.Sleep(msTimeout);
                        //Debug.Log("Asynchronously cleaning up encoder: " + _encCopy.ToString());
                        MixCastAV.writeTrailerCloseStreams(_vidEncCopy);
                        MixCastAV.freeVideoCfg(_vCfgEncCopy);
                        MixCastAV.freeAudioEncodeContext(_audEncCopy);
                        MixCastAV.freeVideoTransform(_vTxfEncCopy);
                        MixCastAV.freeAudioCfg(_aCfgEncCopy);
                    }
                }).Start();
            }

            _vidEnc  = IntPtr.Zero;
            _vCfgEnc = IntPtr.Zero;
            _vTxfEnc = IntPtr.Zero;
            _aCfgEnc = IntPtr.Zero;
            _audEnc  = IntPtr.Zero;
        }