【问题标题】:Youtube API v3 - Get "Live Now" rtmp and streamkeyYoutube API v3 - 获取“Live Now” rtmp 和 streamkey
【发布时间】:2016-02-21 07:13:23
【问题描述】:

Youtube 现在有一个直播部分,允许用户播放他们自己的直播会话。在这个“直播”部分,有 2 个选项:“现在直播 [Beta]”和“活动”。

  • Live Now 是一种快速简便的自动启动流式会话的方法,只需将视频编码器指向指定的 RTMP 网址和流键即可。它将自动检测传入媒体并开始公开广播。

  • Events 几乎是一样的东西,但是使用高级设置,虽然它不会自动开始广播,你需要手动设置所有内容。

我知道 Youtube API 允许您检索 Event 的摄取 url 和 streamkey,因此您可以广播到该目标,但它还需要手动管理许多其他步骤(例如发布流、将广播与流绑定、检查状态、开始、停止等)。另一方面,“Live Now”让一切都自动进行。

问题:如何从 Youtube API v3 检索“Live Now”摄取信息(rtmp url 和 streamkey)?

【问题讨论】:

  • 嗨 omarojo,你找到方法了吗?我也在寻找那个 API,似乎 YouTube 验证的程序,如“XSplit”和“Wirecast”可以通过 API 获取流名称。
  • @rhbc73 我设法使用 API 创建自己的直播和直播(可能与有线广播等正在做的事情相同)。尽管 Youtube 最近更新了他们的 API 文档,以在他们的 liveBroadcast.list 端点中提供 Youtube Livestream Now 功能的默认摄取数据。我仍然无法确认。
  • 我知道我们可以创建一个直播,创建一个直播流,将广播绑定到流,然后流到流名称(这是直播流的属性)。但是流名称将与“Stream now”的名称不同。这样您创建的广播就不会出现在“现在直播”中,而是出现在“活动”部分?
  • 没错。使用“立即流式传输”摄取端点的唯一好处是,实时事件的开始和结束时间是在您使用编码器开始/停止发送视频数据时。否则,使用 Live Events 需要您处理所有的直播周期,特别是过渡到 -complete- 状态(结束活动)
  • 谢谢 omarojo,没错,使用直播活动需要您在 YouTube 网页上手动“开始预览”和“开始流式传输”。您知道这两个动作是否可以通过某些 API(转换 API?)而不是在 YouTube 网页上单击鼠标来执行?您还说“Youtube 最近更新了他们的 API 文档以提供 Youtube Livestream Now 功能的默认摄取数据”,您有链接吗? (我试图通过 liveBroadcast.list 得到它,但没有返回)

标签: youtube youtube-api rtmp youtube-livestreaming-api


【解决方案1】:

可以通过 livebroadcasts.list 检索默认广播,并将 broadcastType 设置为“persistent”。

livestreams.list 可以使用 boundstreamid 检索默认直播。

【讨论】:

  • 谢谢!除非您阅读文档中的所有小字,否则无法知道您可以检索默认直播
  • 哇!它的工作就像一个魅力!有什么方法可以获取公共 URL 分发给观众?
  • 非常感谢! @ben.bourdin 我在哪里可以找到这个的官方文档?
  • @deadbeef 这是我使用的主要资源:youtube live api docs。每个端点都有一个运行良好的“API 资源管理器”,因此您可以轻松对其进行测试
【解决方案2】:

您无法检索“Live Now”提取信息,因为 API 不区分“Live Now”和“Events”。这两个选项作为 API 之上的接口提供给最终用户,因此他们不必编写自己的与 API 接口的应用程序。

您必须手动设置liveBroadcastliveStream 对象,将它们与liveBroadcasts.bind 绑定,测试您的流,然后使用status.streamStatus 过渡到liveStream 对象上直播。

【讨论】:

    【解决方案3】:

    获取“Live Now” rtmp 和 streamkey

           $broadcastsResponse = $youtube->liveBroadcasts->listLiveBroadcasts(
                'id,snippet,contentDetails',
                array(
                    'broadcastType' => 'persistent',
                    'mine' => 'true',
                ));
    
            $boundStreamId = $broadcastsResponse['items']['0']['contentDetails']['boundStreamId'];
    
            $streamsResponse = $youtube->liveStreams->listLiveStreams('id,snippet,cdn', array(
    //            'mine' => 'true',
                'id' => $boundStreamId
            ));
    
            print_r($streamsResponse);
    

    【讨论】:

      【解决方案4】:
       // Keep client_id,client_secret and redirect_uri the client_secrets.json
       UserCredential credential;
       string BoundStreamId = string.Empty;
       string StreamKey=string.Empty;
       using (var stream = new FileStream("client_secrets.json", FileMode.Open, 
         FileAccess.Read))
                  {
                      credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
                      new[] { YouTubeService.Scope.Youtube,YouTubeService.Scope.YoutubeReadonly},
                      "user",
                      CancellationToken.None,
                      new FileDataStore(this.GetType().ToString())
                   );
                  }
      if (credential != null)
                  {
                      var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                      {
                          HttpClientInitializer = credential,
                          ApplicationName = "MyApp" // your app name
                      });
       LiveBroadcastsResource.ListRequest lbRequest = youtubeService.LiveBroadcasts.List("id,snippet,contentDetails,status");
                      lbRequest.BroadcastType = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.Persistent;
                      lbRequest.MaxResults = 10;
      
                      lbRequest.Mine = true;
      
                      var bcResponse = await lbRequest.ExecuteAsync();
      
                      IEnumerator<LiveBroadcast> iLB = bcResponse.Items.GetEnumerator();
                      while (iLB.MoveNext() && string.IsNullOrEmpty(liveChatId))
                      {
                        BoundStreamId = livebroadcast.ContentDetails.BoundStreamId;
                      }
       LiveStreamsResource.ListRequest lsRequest =
                                         youtubeService.LiveStreams.List("id,snippet,cdn,status");
                      lsRequest.MaxResults = 50;                    
                      lsRequest.Id = BoundStreamId;
      
                      var srResponse = await lsRequest.ExecuteAsync();
      
                      IEnumerator<LiveStream> iLS = srResponse.Items.GetEnumerator();
       if (srResponse != null)
                      {
                       foreach(LiveStream lvStream in srResponse.Items)
                          {
                             StreamKey= lvStream.Cdn.IngestionInfo.StreamName);
                          }
                      }
                }
      

      【讨论】:

        猜你喜欢
        • 2021-09-23
        • 2015-01-31
        • 1970-01-01
        • 2015-12-01
        • 2016-01-17
        • 2012-09-08
        • 2016-05-10
        • 2014-01-26
        • 2014-06-05
        相关资源
        最近更新 更多