使用 OBS 创建 Azure 媒体服务实时传送流Create an Azure Media Services live stream with OBS

本快速入门帮助你使用 Azure 门户和 Open Broadcasting Studio (OBS) 创建 Azure 媒体服务实时传送流。This quickstart will help you create an Azure Media Services live stream by using the Azure portal and Open Broadcasting Studio (OBS). 本文假设你有一个 Azure 订阅,并已创建媒体服务帐户。It assumes that you have an Azure subscription and have created a Media Services account.

本快速入门将介绍以下方面的内容:In this quickstart, we'll cover:

  • 使用 OBS 设置本地编码器。Setting up an on-premises encoder with OBS.
  • 设置实时传送流。Setting up a live stream.
  • 设置实时传送流输出。Setting up live stream outputs.
  • 运行默认的流式处理终结点。Running a default streaming endpoint.
  • 使用 Azure Media Player 观看实时传送流和按需输出。Using Azure Media Player to view the live stream and on-demand output.

先决条件Prerequisites

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

登录到 Azure 门户Sign in to the Azure portal

打开 Web 浏览器,并转到 Azure 门户Open your web browser, and go to the Azure portal. 输入登录到门户所需的凭据。Enter your credentials to sign in to the portal. 默认视图是服务仪表板。The default view is your service dashboard.

使用 OBS 设置本地编码器Set up an on-premises encoder by using OBS

  1. Open Broadcaster Software 网站上下载适用于你的操作系统的 OBS,然后进行安装。Download and install OBS for your operating system on the Open Broadcaster Software website.
  2. 启动应用程序,使其保持打开状态。Start the application and keep it open.

运行默认的流式处理终结点Run the default streaming endpoint

  1. 在媒体服务列表中选择“流式处理终结点”。Select Streaming endpoints in the Media Services listing.

    “流式处理终结点”菜单项

  2. 如果默认流式处理终结点的状态为“已停止”,请选择它。If the default streaming endpoint status is stopped, select it. 此步骤会将你转到该终结点的页面。This step takes you to the page for that endpoint.

  3. 选择“开始”。Select Start.

    流式处理终结点的“启动”按钮

设置 Azure 媒体服务实时传送流Set up an Azure Media Services live stream

  1. 在门户中转到 Azure 媒体服务帐户,然后从“媒体服务”列表中选择“实时传送视频流”。 Go to the Azure Media Services account within the portal, and then select Live streaming from the Media Services listing.

    “实时传送视频流”链接

  2. 选择“添加实时事件”创建新的实时传送视频流事件。Select Add live event to create a new live streaming event.

    “添加实时事件”图标

  3. 在“实时事件名称”框中,输入新事件的名称,例如 TestLiveEvent。Enter a name for your new event, such as TestLiveEvent, in the Live event name box.

    “实时事件名称”框

  4. 在“说明”框中输入事件的可选说明。Enter an optional description of the event in the Description box.

  5. 选择“直通 – 无云编码”选项。Select the Pass-through – no cloud encoding option.

    云编码选项

  6. 选择“RTMP”选项。Select the RTMP option.

  7. 确保选择了与“启动实时事件”对应的“无”选项,以免在该实时事件准备就绪之前产生费用。 Make sure that the No option is selected for Start live event, to avoid being billed for the live event before it's ready. (启动实时事件后,即会开始计费。)(Billing will begin when the live event is started.)

    “启动实时事件”选项

  8. 选择“查看 + 创建”按钮检查设置。Select the Review + create button to review the settings.

  9. 选择“创建”按钮以创建实时事件。Select the Create button to create the live event. 随后你会返回到实时事件列表。You're then returned to the live event listing.

  10. 选择刚刚创建的实时事件的链接。Select the link to the live event that you just created. 可以观察到你的事件已停止。Notice that your event is stopped.

  11. 在浏览器中将此页保持打开状态。Keep this page open in your browser. 稍后我们将返回到该文件。We'll come back to it later.

使用 OBS Studio 设置实时传送流Set up a live stream by using OBS Studio

OBS 启动时有一个默认场景,但未选择任何输入。OBS starts with a default scene but with no inputs selected.

OBS 默认屏幕

添加视频源Add a video source

  1. 在“源”面板中,单击添加图标,选择新的源设备。From the Sources panel, click the add icon to select a new source device. 此时会打开“源”菜单。The Sources menu will open.

  2. 从源设备菜单中选择“视频捕获设备”。Select Video Capture Device from the source device menu. 此时会打开“创建/选择源”菜单。The Create/Select Source menu will open.

    其中选定了视频设备的 OBS 源菜单

  3. 选择“添加现有”单选按钮,然后单击“确定”。 Select the Add Existing radio button, then click OK. 此时会打开“视频设备的属性”菜单。The Properties for Video Device menu will open.

    其中选定了“添加现有”的 OBS 新视频源菜单

  4. 从“设备”下拉列表中,选择要用于广播的视频输入。From the Device dropdown list, select the video input you want to use for your broadcast. 暂时保留其余设置,单击“确定”。Leave the rest of the settings alone for now, and click OK. 输入源会添加到“源”面板中,视频输入视图会显示在“预览”区域中。The input source will be added to the Sources panel, and the video input view will show up in the Preview area.

    OBS 摄像头设置

添加音频源Add an audio source

  1. 在“源”面板中,单击添加图标,选择新的源设备。From the Sources panel, click the add icon to select a new source device. 此时会打开“源设备”菜单。The Source Device menu will open.

  2. 从源设备菜单中选择“音频输入捕获”。Select Audio Input Capture from the source device menu. 此时会打开“创建/选择源”菜单。The Create/Select Source menu will open.

    其中选定了音频设备的 OBS 源菜单

  3. 选择“添加现有”单选按钮,然后单击“确定”。 Select the Add Existing radio button, then click OK. 此时会打开“音频输入捕获的属性”菜单。The Properties for Audio Input Capture menu will open.

    其中选定了“添加现有”的 OBS 音频源OBS audio source with add existing selected

  4. 从“设备”下拉列表中,选择要用于广播的音频捕获设备。From the Device dropdown list, select the audio capture device you want to use for your broadcast. 暂时保留其余设置,单击“确定”。Leave the rest of the settings alone for now, and click OK. 音频捕获设备将添加到音频混合器面板中。The audio capture device will be added to the audio mixer panel.

    OBS 音频设备选择下拉列表

在 OBS 中设置流式处理Set up streaming in OBS

在接下来的过程中,你将在浏览器中返回到 Azure 媒体服务来复制输入 URL,以便将其输入到输出设置中:In the next procedure, you'll go back to Azure Media Services in your browser to copy the input URL to enter into the output settings:

  1. 在门户的“Azure 媒体服务”页上,选择“启动”以启动实时传送流事件。On the Azure Media Services page of the portal, select Start to start the live stream event. (现在开始计费。)(Billing starts now.)

    “启动”图标

  2. 将“RTMP”开关设置为“RTMPS”。Set the RTMP toggle to RTMPS.

  3. 在“输入 URL”中,将 URL 复制到剪贴板。In the Input URL box, copy the URL to your clipboard.

    输入 URL

  4. 切换到 OBS 应用程序。Switch to the OBS application.

  5. 在“控制”面板中,单击“设置”按钮。 Click the Settings button in the Controls panel. 此时会打开“设置”选项。The Settings options will open.

    其中选中了“设置”的 OBS 控制面板

  6. 从“设置”菜单中选择“流”。 Select Stream from the Settings menu.

  7. 从“服务”下拉列表中,选择“全部显示”,然后选择“自定义...” 。From the Service dropdown list, select Show all, then select Custom....

  8. 在“服务器”字段中,粘贴已复制到剪贴板的 RTMPS URL。In the Server field, paste the RTMPS URL you copied to your clipboard.

  9. 在“流键”字段中输入一些内容。Enter something into the Stream key field. 此字段的内容是什么并不重要,但需要有一个值。It doesn't really matter what it is, but it needs to have a value.

    OBS 流设置

  10. 从“设置”菜单中选择“输出”。 Select Output from the Settings menu.

  11. 在“关键帧间隔”字段中输入“2”。Enter 2 into the Keyframe interval field. 这会将片断长度设置为 2 秒。This sets the fragment length to 2 seconds. 若要降低实时传递的延迟,请使用 1 秒作为值。For lower latency live delivery, use the value of 1 second.

  12. 可选:如果你使用的计算机处理能力较弱,请将“CPU 使用情况预设”设置为“veryfast”。OPTIONAL: Set the CPU Usage Preset to veryfast if you are using a computer that is low on processing power. 如果网络条件不理想,则可选择将 kbps 设置为较低的值。Optionally, you can set the kbps to something lower if there are undesirable network conditions.

    OBS 输出设置

  13. 保留其余设置不变,然后单击“确定”。Leave the rest of the settings unchanged and click OK.

启动流式处理Start streaming

  1. 在“控制”面板中,单击“启动流式处理”。 In the Controls panel, click Start Streaming.

    OBS 的“启动流式处理”按钮

  2. 在浏览器中切换到 Azure 媒体服务实时事件屏幕,单击“重载播放器”链接。Switch to the Azure Media Services Live event screen in your browser and click the Reload Player link. 现在应该可以在“预览播放器”中看到你的流。You should now see your stream in the Preview player.

设置输出Set up outputs

此部分将设置输出,并使你可以保存实时流的录制内容。This part will set up your outputs and enable you to save a recording of your live stream.

备注

若要流式传输此输出,流式处理终结点必须正在运行。For you to stream this output, the streaming endpoint must be running. 请参阅后面的运行默认的流式处理终结点部分。See the later Run the default streaming endpoint section.

  1. 选择“输出”视频查看器下面的“创建输出”链接。 Select the Create outputs link below the Outputs video viewer.

  2. 如果需要,请将“名称”框中的输出名称编辑为用户更容易理解的内容,便于今后查找。If you like, edit the name of the output in the Name box to something more user-friendly so it's easy to find later.

    输出名称框

  3. 暂时不要理会其余所有框。Leave all the rest of the boxes alone for now.

  4. 选择“下一步”添加流定位器。Select Next to add a streaming locator.

  5. 如果需要,请将定位器的名称更改为用户更容易理解的内容。Change the name of the locator to something more user-friendly, if you want.

    定位器名称框

  6. 暂时不要理会此屏幕上的其他任何设置。Leave everything else on this screen alone for now.

  7. 选择“创建”。Select Create.

使用 Azure Media Player 播放输出的广播Play the output broadcast by using Azure Media Player

  1. 复制“输出”视频播放器下面的流 URL。Copy the streaming URL under the Output video player.
  2. 在 Web 浏览器中,打开 Azure Media Player 演示In a web browser, open the Azure Media Player demo.
  3. 将流 URL 粘贴到 Azure Media Player 的“URL”框中。Paste the streaming URL into the URL box of Azure Media Player.
  4. 选择“更新播放器”按钮。Select the Update Player button.
  5. 选择视频中的“播放”图标查看实时传送流。Select the Play icon on the video to see your live stream.

停止广播Stop the broadcast

如果你认为已流式传输了足够的内容,请停止广播。When you think you've streamed enough content, stop the broadcast.

  1. 在门户中选择“停止”。In the portal, select Stop.

  2. 在 OBS 的“控制”面板中,选择“停止流式处理”按钮。 In OBS, select the Stop Streaming button in the Controls panel. 此步骤会在 OBS 中停止广播。This step stops the broadcast from OBS.

使用 Azure Media Player 播放按需输出Play the on-demand output by using Azure Media Player

现在,只要流式处理终结点正在运行,创建的输出就可供按需流式处理。The output that you created is now available for on-demand streaming as long as your streaming endpoint is running.

  1. 转到媒体服务列表并选择“资产”。Go to the Media Services listing and select Assets.
  2. 找到前面创建的事件输出,然后选择指向该资产的链接。Find the event output that you created earlier and select the link to the asset. 此时会打开资产输出页。The asset output page opens.
  3. 复制该资产的视频播放器下的流 URL。Copy the streaming URL under the video player for the asset.
  4. 在浏览器中返回到 Azure Media Player,将流 URL 粘贴到“URL”框中。Return to Azure Media Player in the browser and paste the streaming URL into the URL box.
  5. 选择“更新播放器”。Select Update Player.
  6. 选择视频中的“播放”图标以观看按需资产。Select the Play icon on the video to view the on-demand asset.

清理资源Clean up resources

重要

请停止服务!Stop the services! 完成本快速入门中的步骤后,请务必停止实时事件和流式处理终结点,否则系统会按它们的运行时间计收费用。After you've completed the steps in this quickstart, be sure to stop the live event and the streaming endpoint, or you'll be billed for the time they remain running. 若要停止实时事件,请参阅停止广播过程的步骤 2 和 3。To stop the live event, see the Stop the broadcast procedure, steps 2 and 3.

若要停止流式处理终结点,请执行以下操作:To stop the streaming endpoint:

  1. 从媒体服务列表中选择“流式处理终结点”。From the Media Services listing, select Streaming endpoints.
  2. 选择前面启动的默认流式处理终结点。Select the default streaming endpoint that you started earlier. 此步骤会打开该终结点的页面。This step opens the endpoint's page.
  3. 选择“停止”。Select Stop.

提示

如果你不想要保留来自此事件的资产,请务必将其删除,以免产生存储费用。If you don't want to keep the assets from this event, be sure to delete them so you're not billed for storage.

后续步骤Next steps