如何在YouTube直播中添加字幕?

问题描述 投票:1回答:1

YouTube提供了在视频流中发送字幕的可能性,如文件所示 此处. 然而,这个指南提到的Youtube Studio Classic的链接已经不存在了。在新的直播控制室里,我只能找到一个字幕的链接,它看起来像是

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

而不包含像 nssparams.

我如何使用实时控制室提供字幕?在其他页面上也有一些误导性的信息--我可以只使用一个简单的HTTP POST还是需要购买一个 支持的软件?

如果不能使用POST,我可以使用Livestreaming API吗?

http post youtube live-streaming youtube-livestreaming-api
1个回答
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)

基本上,其他的就不需要了。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.