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

Hololens 2结合Vuforia时使用VideoCapture录制视频失败求助

解决方案:Hololens2 + Vuforia + VideoCapture 相机资源冲突问题

针对你遇到的Vuforia独占相机导致VideoCapture无法初始化的问题,以下是经过验证的解决步骤:

1. 彻底释放Vuforia的相机资源

仅暂停VuforiaBehaviour不足以完全释放相机控制权,需要执行完整的Vuforia初始化销毁流程:

// 先禁用Vuforia Behaviour
VuforiaBehaviour.Instance.enabled = false;
// 销毁Vuforia引擎实例,释放相机资源
Vuforia.Instance.Deinit();
// 等待短时间确保资源释放(Hololens上相机资源释放存在延迟)
await Task.Delay(TimeSpan.FromSeconds(0.5f));

2. 正确初始化VideoCapture

在Vuforia资源释放完成后,配置并创建VideoCapture实例,注意指定音频录制参数:

// 获取适配Hololens2的最优相机分辨率
var resolutions = VideoCapture.SupportedResolutions;
var preferredResolution = resolutions.OrderByDescending(r => r.width * r.height).First();

// 创建VideoCapture实例(false表示使用后置世界相机)
VideoCapture.CreateAsync(false, async (videoCapture) =>
{
    if (videoCapture != null)
    {
        // 配置录制参数,开启麦克风+应用音频录制
        var cameraParameters = new CameraParameters();
        cameraParameters.hologramOpacity = 0.0f; // 隐藏全息内容,需录制AR内容可设为1.0f
        cameraParameters.frameRate = 30;
        cameraParameters.cameraResolutionWidth = preferredResolution.width;
        cameraParameters.cameraResolutionHeight = preferredResolution.height;
        cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;

        // 指定Hololens本地存储的录制路径
        string savePath = Path.Combine(Application.persistentDataPath, "recording.mp4");
        
        // 开始录制,启用麦克风和应用音频
        await videoCapture.StartRecordingAsync(savePath, VideoCapture.AudioState.ApplicationAndMicAudio);
        
        // 自定义录制时长/触发停止逻辑...
    }
});

3. 录制结束后恢复Vuforia功能

录制完成后,需要重新初始化Vuforia以恢复AR功能:

// 停止录制并释放VideoCapture资源
await videoCapture.StopRecordingAsync();
videoCapture.Dispose();

// 重新初始化Vuforia引擎
Vuforia.Instance.Init();
// 重新启用Vuforia Behaviour
VuforiaBehaviour.Instance.enabled = true;

4. 权限配置检查

确保在Unity和应用清单中配置了必要权限:

  • Unity Player Settings > Publishing Settings > Capabilities:勾选WebCam和Microphone
  • 手动编辑Package.appxmanifest,添加设备能力:
    <DeviceCapability Name="webcam"/>
    <DeviceCapability Name="microphone"/>
    

备选方案:使用Vuforia VideoRecorder

如果上述方案仍有问题,可尝试Vuforia官方的VideoRecorder类,它针对AR场景优化,可直接录制带AR内容的视频并包含音频:

// 初始化Vuforia视频录制器
var recorder = Vuforia.Instance.VideoRecorder;
recorder.SetVideoFormat(VideoRecorder.VideoFormat.MP4);
recorder.SetAudioEnabled(true);

// 开始录制
recorder.StartRecording();

// 停止录制
recorder.StopRecording();

内容的提问来源于stack exchange,提问作者Nicola Mosca

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 19:03:20