如何完全从 Linux 安排 YouTube 直播? [英] How can I schedule a YouTube livestream entirely from Linux?

查看:43
本文介绍了如何完全从 Linux 安排 YouTube 直播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Raspberry Pi(带有其原生相机)上进行了设置,该设置使用 cronjob 启动 ffmpeg 会话,并将其输出流传输到 YouTube.我每次都重复使用相同的流密钥,它被写入我的 ffmpeg 脚本.这一切每周都完美运行,在所需时间自动启动和停止.但是,在直播之前的每个星期,我都必须手动"进行直播.进入 YouTube 工作室并安排"一个新的未来事件.这很容易,因为它让我重用"以前的设置——我只需要更改标题、日期和时间.但我也很想找出一种方法来自动化这部分流程.我认为它涉及使用 YouTube 数据 API,但我不精通 API、JSON 等.(我确实有很强的 Linux 背景、bash 脚本技能和一般编程背景.)

I have a setup on a Raspberry Pi (with its native camera) that uses a cronjob to start an ffmpeg session with its output streaming to YouTube. I re-use the same stream key each time, which is written into my ffmpeg scripts. This all works perfectly each week, automatically starting and stopping at the desired time. However, each week PRIOR to that livestream, I have to "manually" go into YouTube Studio and "schedule" a new future event. This is easy enough, since it lets me "reuse" previous settings -- all I have to change is the Title, date, and time. But I would love to figure out a way to automate that part of the process, as well. I assume it involves using the YouTube Data API, but I'm not well versed in API's, JSON, etc. (I do have a strong Linux background, bash scripting skills, and general programming background.)

我的最终解决方案只需要:

My final solution just needs to:

  • 创建新的预定活动(可能在上线前 12 小时),包括标题、日期、时间、未列出"状态、类别等等——我在 Studio 中手动进行的所有常用设置
  • 为即将到来的流检索分配的 URL(然后我的脚本会将其通过电子邮件发送给我)

所以,基本上,我是在寻求 API 入门帮助,或者任何能够做到这一点的方法.我更愿意在执行 ffmpeg 编码的同一 Pi 上对其进行编码(尽管在紧要关头,我可以从另一台计算机(甚至是 Windows)创建计划).任何例子都会很棒.

So, basically, I'm asking for help getting started with the API, or whatever method is capable of doing this. I would prefer to code it on the same Pi that does the ffmpeg encoding (although in a pinch, I could create the schedule from another computer, even Windows). Any examples would be great.

到目前为止,我所做的只是创建我的 Google 项目,在项目中启用 YouTube 数据 API,并创建我的 API 密钥.但我不知道从哪里开始.

So far, all I have done is create my Google project, enable the YouTube Data API in the project, and create my API key. But I'm not sure where to go from there.

推荐答案

如果 Python 作为实现语言适合您,那么我建议您使用 Google 的 Python API 客户端库.

If Python as implementation language suites you, then I'd recommend to use the Google's APIs Client Library for Python.

基本上,这个库质量好并且(与其他客户端库相比)简单易用.例如,它将使您不必明确处理 REST API 调用、JSON 等.您的代码也可以在 GNU/Linux 和 Windows 下运行.

Basically, this library is of good quality and (compared to other client libraries) simple to use. It will, for example, insulate you from having to deal explicitly with REST API calls, JSON and the like. Your code will also work under both GNU/Linux and Windows.

您可以通过阅读官方入门文档开始您的旅程:YouTube Live流式 API 概述.然后我建议吸收这两个重要文件:Life of a Broadcast了解广播和流.

You may begin your journey by reading the official getting started doc: YouTube Live Streaming API Overview. Then I recommend absorbing these two important documents: Life of a Broadcast and Understanding Broadcasts and Streams.

然后去阅读、理解并运行以下来自谷歌的示例程序:create_broadcast.py.当然,您必须根据您的用例调整该代码.

Then go read, understand and run the following sample program from Google: create_broadcast.py. Of course, you'll have to adapt that code to your use case.

您必须要有耐心和毅力(因为您说您之前没有使用 YouTube 数据 API 的经验).这个 API 很重要,但它会在您(编程)旅程结束时为您带来回报(您提到精通编程).

You'll have to exercise patience and perseverance (since you say you have no prior experience using the YouTube Data API). This API is non-trivial, but it'll pay off to you at the end of your (programming) journey (you mentioned to be versed in programming).

特别说明:为了能够调用直播流 API,您首先需要熟悉与所谓的 OAuth 2.0 授权和身份验证相关的内容:实施 OAuth 2.0 身份验证.您需要阅读一份官方文档:OAuth 2.0 for Mobile &桌面应用.

A special mention: for to be able to call the live streaming APIs you will first need to get acquainted with the things related to the so-called OAuth 2.0 authorization and authentication: Implementing OAuth 2.0 Authentication. There's an official document that you need absorb: OAuth 2.0 for Mobile & Desktop Apps.

更多参考:直播 API 有一个官方文档 也是.记录客户端库的主要站点是:Google API Client Library for Python Docs.它的来源是公开的,可以在 客户端库的公共仓库下找到目录 docs.

A few more references: the live streaming API has an official documentation too. The main site documenting the client library is: Google API Client Library for Python Docs. Its source is public, to be found within the client library's public repo under the directory docs.

查看 YouTube 数据 API 也很有用所有实例方法的列表.

这篇关于如何完全从 Linux 安排 YouTube 直播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆