【问题标题】:How to caption YouTube Livestreams?如何为 YouTube 直播添加字幕?
【发布时间】:2020-07-27 08:59:45
【问题描述】:

YouTube 提供了在直播中发送字幕的可能性,如 here 所述。但是,本指南引用了来自 Youtube Studio Classic 的链接,该链接已不存在。在新的直播控制室里,我只能找到一个字幕链接,看起来像

http://upload.youtube.com/closedcaption?cid=....

并且不包含nssparams等参数。

如何为直播控制室提供字幕?其他页面上也有一些误导性信息 - 我可以只使用简单的 HTTP POST 还是需要购买 supported softwares 之一?

如果无法使用 POST,我可以使用 Livestreaming API 吗?

【问题讨论】:

    标签: http post youtube live-streaming youtube-livestreaming-api


    【解决方案1】:

    它适用于我使用下面的 python 代码。

    import time
    import requests
    from datetime  import datetime
    
    word = "this is caption " + str(seq)
    
    ytlink = "http://upload.youtube.com/closedcaption?cid=xxx-xxx-xxx-xxx="+str(seq)
    
    post_fields = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + ' \n' + word + '\n' 
    
    headers = {'content-type': 'text/plain'}
    r = requests.post(url=ytlink, data=post_fields.encode('utf-8'), headers=headers)
     
    print(ytlink)
    print(r.text)
    

    基本上不再需要其他人了。

    【讨论】:

      【解决方案2】:

      它也适用于 c#。 (对不起,我认为这不是正确的代码示例,我第一次尝试回答任何问题......)

      string CAPTION_TEXT = "This text is displayed as caption.<br>"; // note, br used for linebreak in caption
      string STREAM_ID = "aaaa-bbbb-cccc-dddd-eeee";
      int sequence = 1;
      string url = "http://upload.youtube.com/closedcaption?cid="+STREAM_ID+"&seq="+sequence; // increment sequence every time you send
      string message = dateTime.ToString("yyyy-MM-dd") + "T" +
                  dateTime.ToString("HH") + ":" +
                  dateTime.ToString("mm") + ":" +
                  dateTime.ToString("ss.fff")+
                  " region:reg1#cue1\n"+
                  CAPTION_TEXT+"\n"
      var content = new StringContent(message);
      var client = new HttpClient();
      var response = await client.PostAsync(url, content);
      int statusCode = (int)response.StatusCode;
      if(statusCode == "200") SUCCESS();
      

      【讨论】:

        猜你喜欢
        • 2017-08-31
        • 1970-01-01
        • 2023-03-18
        • 2014-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-20
        • 1970-01-01
        相关资源
        最近更新 更多