Unity接入海康网络摄像头SDK

写这篇文章是因为采用https://blog.csdn.net/qq_33214503/article/details/80091247 的方法,导致unity无法退出,导出的exe无法关闭

采用的方案是使用32位的海康SDK

我的Demo项目已经上传的码云

地址: https://gitee.com/mrlx0/MonitorCamera_FFmpeg

  1. ffmpeg_for_unity同样采用了32位的 ,而网络上搜的是64位,所有自己编译了一个32位的,地址: https://gitee.com/mrlx0/ffmpeg_for_unity
  2. demo中包含了64位ffmpeg_for_unity64位的海康SDK,可以选择64位测试(建议不要,能看到内容,但是unity退出会卡死);
  3. 注意发布时要选择x86;选择x86_64打包会读64位的sdk,依然是无法关闭
  4. 我同时根据 http://blog.51cto.com/weiyuqingcheng/2323546 提供的方案(YV12转换为RGB32),制作了第二个场景,但会卡顿和画质不对,可能算法有问题,没仔细研究

效果: ![Alt]在这里插入图片描述

没有采用存储

	private void DecCallbackFUN(int nPort, IntPtr pBuf, int nSize, ref PlayCtrl32.FRAME_INFO pFrameInfo,
        int nReserved1, int nReserved2)
    {
        if (m_realHanle > -1)
        {
            // 将pBuf解码后视频输入写入文件中(解码后YUV数据量极大,尤其是高清码流,不建议在回调函数中处理)
            if (pFrameInfo.nType == 3)
            {
                if (playerResolution == null)
                {
                    var resolution = new Resolution();
                    resolution.width = pFrameInfo.nWidth;
                    resolution.height = pFrameInfo.nHeight;
                    resolution.refreshRate = pFrameInfo.nFrameRate;
                    playerResolution = resolution;
                    transforDataframe = new byte[(long)pFrameInfo.nWidth * pFrameInfo.nHeight * 4];
                }
                if(sourceDataFrame == null)
                {
                    sourceDataFrame = new byte[nSize];
                }

                Marshal.Copy(pBuf, sourceDataFrame, 0, nSize);
            }
        }
    }
	private void StartTransformData()
    {
        while (m_IsFFmpeg && m_userId > -1)
        {
            if (sourceDataFrame != null)
            {
                if (FFMPEG32.YV12toRgb_Updated(transforDataframe, sourceDataFrame, playerResolution.Value.width, playerResolution.Value.height))
                {
                    //dataBackupQueue.Enqueue(transforDataframe);
                }
                else
                    Debug.Log("转换失败");
            }
            float waitTime = Mathf.Max(16, _farmeTime * 1000);
            Thread.Sleep((int)waitTime);
        }
    }
	private IEnumerator AnalizeData()
    {
        var endFrame = new WaitForEndOfFrame();
        while ((m_realHanle > -1 || m_PlayHandle > -1) && m_userId > -1)
        {

            if (playerResolution != null && m_Texture == null)
            {
                m_Texture = new Texture2D(playerResolution.Value.width, playerResolution.Value.height
                    , TextureFormat.RGB24, false);
            }
            if (m_Texture != null && transforDataframe!=null)//dataBackupQueue.Count > 0)
            {
                View.texture = m_Texture;
                m_Texture.LoadRawTextureData(transforDataframe);//(dataBackupQueue.Dequeue());
                m_Texture.Apply();
                View.texture = m_Texture;
            }
            _farmeTime = Time.deltaTime;
            yield return endFrame;
        }
    }

技术有限,有问题欢迎留言。

评论 29
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值