You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity中罗技相机播放流报错:Could not connect pins - RenderStream()

罗技相机在Unity中播放视频流报错Could not connect pins - RenderStream()的解决方案

问题描述

尝试播放罗技相机视频流时触发报错Could not connect pins - RenderStream(),但其他品牌相机可正常工作。

核心代码:

webCamTexture = new WebCamTexture(WebCamTexture.devices[0].name, 1280, 720, 30);
rawImage.texture = webCamTexture;
webCamTexture.Play();

环境信息:

  • Windows独立应用
  • Unity 2023.3.1f1
  • Windows 11

问题仅出现在罗技C270、C922相机上,同款ELP相机运行正常。已验证相机及驱动无故障——用AForge编写的WPF C#程序可正常播放所有相机流(仅同型号罗技相机连同一USB集线器时无法运行)。

经过验证的可行解决方案

1. 调整分辨率与帧率参数

Unity的WebCamTexture对部分罗技相机的特定分辨率/帧率组合兼容性不佳,可尝试降低参数或枚举相机支持的配置:

// 示例:改用低分辨率低帧率
webCamTexture = new WebCamTexture(WebCamTexture.devices[0].name, 640, 480, 15);

或枚举所有支持的分辨率逐个尝试:

WebCamDevice targetDevice = WebCamTexture.devices[0];
foreach (Resolution res in targetDevice.availableResolutions)
{
    Debug.Log($"支持分辨率:{res.width}x{res.height}");
    // 尝试创建并播放对应配置的WebCamTexture
}

2. 优化USB连接方式

同型号罗技相机共享USB集线器时易引发资源冲突,建议:

  • 直接将相机连接到主板原生USB接口
  • 更换带独立供电的USB集线器

3. 延迟初始化相机

在场景加载完成后延迟几秒再初始化相机,避免系统资源未就绪导致引脚连接失败:

IEnumerator Start()
{
    yield return new WaitForSeconds(2f);
    webCamTexture = new WebCamTexture(WebCamTexture.devices[0].name, 1280, 720, 30);
    rawImage.texture = webCamTexture;
    webCamTexture.Play();
}

4. 切换视频捕获后端

在Unity Player Settings中调整视频捕获后端:

  1. 打开Edit > Project Settings > Player > Windows
  2. 找到Video Capture Backend选项,切换为DirectShow或MediaFoundation(默认Auto)

5. 释放相机资源后重新初始化

初始化前先清理可能占用的相机资源:

if (webCamTexture != null)
{
    webCamTexture.Stop();
    Destroy(webCamTexture);
}
// 重新创建并播放
webCamTexture = new WebCamTexture(WebCamTexture.devices[0].name, 1280, 720, 30);
rawImage.texture = webCamTexture;
webCamTexture.Play();

内容的提问来源于stack exchange,提问作者Ralph Canapa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 21:37:42