3.将视频中的音频空间化3. Spatializing audio from a video

概述Overview

在本教程中,您将学习如何从视频源 spatialize 音频并在 unity 编辑器和 HoloLens 2 中对此进行测试。In this tutorial, you will learn how to spatialize audio from an video source and test this in the unity editor and HoloLens 2.

目标Objectives

  • 导入视频并添加视频播放器Import a video and add a Video Player
  • 播放视频到 quadranglePlay the video onto a quadrangle
  • 将音频从视频路由到 quadrangle,并 spatialize 音频Route audio from the video to the quadrangle, and spatialize the audio

导入视频并将视频播放器添加到场景Import a video and add a Video Player to the Scene

在本教程中,你可以从空间音频示例项目使用 此视频For this tutorial use You can use this video from the spatial audio sample project.

将视频导入 unity 项目。To import Video into the unity project. 在 Unity 菜单中,选择 "资产 > 导入新资产  导入资产"in the Unity menu select Asset > Import New Asset Importing Asset

在 " 导入新资产 ... " 窗口中,选择已下载的 Microsoft HoloLens 空间 PTPvx7mDon4 文件,并单击 " 打开 " 按钮将资产导入到项目中:In the Import New Asset... window, select the Microsoft HoloLens - Spatial Sound-PTPvx7mDon4 file you downloaded and click the Open button to import the asset into the project:

选择资产

调整视频剪辑的质量设置可以确保在 HoloLens 2 上顺畅地播放。Adjusting the quality settings on the video clip can ensure smooth playback on HoloLens 2. 在 " 项目 " 窗口中选择视频文件,并在视频文件的 "检查器" 窗口中, 覆盖 Windows 应用商店应用 的设置,并执行以下操作:Select the video file in the Project window and in the Inspector window of the video file, override the settings for Windows Store Apps, and:

  • 启用 转码Enable Transcode
  • 编解码器 设置为 H264Set Codec to H264
  • 比特率模式 设置为低Set Bitrate Mode to Low
  • 空间质量 设置为中等空间质量Set Spatial Quality to Medium Spatial Quality

完成这些调整后,单击 "应用" 以更改视频剪辑的质量设置。After these adjustments, click on Apply to change the quality setting on the video clip.

视频属性更改

右键单击层次结构,选择 "视频 > 视频播放器" 添加视频播放器组件。Right click on the Hierarchy, Select Video > Video Player to add Video player component.

添加视频播放器

播放视频到 quadranglePlay video onto a quadrangle

视频播放器 对象需要纹理的游戏对象来渲染视频。The Video Player object needs a textured game object to render the video.

右键单击层次结构,选择 " 3d 对象 > 个",创建一个四核,并按如下所示配置 转换 组件:Right click the Hierarchy , Select 3D Object > Quad to create a quad and configure its Transform component as follows:

  • Position: X = 0、Y = 0、Z = 2Position: X = 0, Y = 0, Z = 2
  • 旋转:X = 0, Y = 0, Z = 0Rotation: X = 0, Y = 0, Z = 0
  • Scale: X = 1.28,Y = 0.72,Z = 1Scale: X = 1.28, Y = 0.72, Z = 1

添加四

现在,需要使用视频对 四核 进行着色,在 "项目" 窗口中,右键单击并选择 "创建 > 渲染纹理" 以创建渲染纹理组件,为渲染纹理输入合适的名称(例如,空间音频纹理):Now you need to texture the Quad with the video, In the Project window, right-click and choose Create > Render Texture to create a Render Texture component, enter a suitable name to the Render Texture for example, Spatial Audio Texture:

创建着色纹理

选择 " 渲染纹理 ",然后在 "检查器" 窗口中,设置 " Size " 属性以匹配视频的 "1280x720 的本机分辨率"。Select the Render Texture and in the Inspector window set the Size property to match the video's native resolution of 1280x720. 然后,若要确保在 HoloLens 2 上呈现良好的性能,请将 深度缓冲区 属性设置为 至少16位深度Then, to ensure good rendering performance on HoloLens 2, set the Depth Buffer property to At least 16 bits depth.

呈现纹理属性

接下来,使用创建的呈现纹理 空间音频纹理 作为 个的纹理:Next, use the created Render Texture Spatial Audio Texture as the texture for the Quad:

  1. 空间音频纹理 从 " 项目 " 窗口拖到层次结构中的 " 个",将渲染纹理添加到 "四核"Drag the Spatial Audio Texture from the Project window onto the Quad in the Hierarchy to add the Render Texture to the Quad
  2. 若要在 HoloLens 2 上确保良好的性能,请在层次结构中选择四个四个,并在着色器的检查器窗口中选择 混合现实工具包 > 标准 着色器。To ensure good performance on HoloLens 2, select Quad in the Hierarchy and in the Inspector window for shader select the Mixed Reality Toolkit > Standard Shader.

四纹理属性

若要设置 视频播放机渲染纹理 以播放视频剪辑,请在 层次结构 中选择 视频播放器,然后在 "检查器" 窗口中选择To set Video Player and Render Texture to play the video clip, select the Video Player in the Hierarchy and in the Inspector window,

  • 视频剪辑 属性设置为下载的视频文件 "Microsoft PTPvx7mDon4"Set the Video Clip property to the downloaded video file 'Microsoft HoloLens - Spatial Sound-PTPvx7mDon4'
  • 选中 " 循环 " 复选框Check the Loop checkbox
  • 目标纹理 设置为新的呈现纹理 空间音频纹理Set Target Texture to your new render texture Spatial Audio Texture

视频播放器属性

Spatialize 视频中的音频Spatialize the audio from the video

在 "层次结构" 窗口中,选择 " 个对象",然后在 "检查器" 窗口中,使用 " 添加组件 " 按钮添加 音频源 ,从视频将音频源路由到该视频源。In the Hierarchy window, select Quad object, then in the Inspector window, use the Add Component button to add Audio Source to which you'll route the audio from the video.

音频源 中:In the Audio Source:

  • 输出 设置为 空间音频混合器Set Output to the Spatial Audio Mixer
  • 选中 " Spatialize " 框Check the Spatialize box
  • 空间混合 滑块移动到 1 (3d) Move the Spatial Blend slider to 1 (3D)

四核音频源检查器

若要将视频播放机设置为将音频源路由到 音频源,请在 "层次结构" 窗口中选择 视频播放器 ,然后在 "检查器" 中的 "视频播放器" 对象中执行以下更改。To set the Video Player to route its audio to the Audio Source, select the Video Player In the Hierarchy window, and in Video Player object in the Inspector do the following changes.

  • 音频输出模式 设置为 音频源Set the Audio Output Mode to Audio Source
  • 将 " 音频源 " 属性设置为 Set the Audio Source property to the Quad

视频播放器设置音频源

提示

要查看提示了解如何生成 Unity 项目并将其部署到 HoloLens 2,可参阅在 HoloLens 2 上构建应用中的说明。For a reminder on how to build and deploy your Unity project to HoloLens 2, you can refer to the Building your app to your HoloLens 2 instructions.

祝贺Congratulations

在本教程中,你已学习如何从视频源 spatialize 音频,尝试在 HoloLens 2 上或在 Unity 编辑器中运行你的应用。In this tutorial, you have learned how to spatialize audio from an video source Try out your app on a HoloLens 2 or in the Unity editor. 你会看到并听到视频,视频中的音频是 spatialized 的。You'll see and hear the video, and the audio from the video is spatialized.

在下一教程中,你将了解如何在运行时启用和禁用 spatializationIn the next tutorial you will learn how to Enable and disable spatialization at run time