我尝试通过 API 创建 YT 流。我只是想创建一个公共可见流。我想稍后通过其他软件通过 RTMP 发送的数据。
我写了这个脚本来创建流:
import google.oauth2.credentials
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
import subprocess
# Set up the OAuth2 credentials
# Replace CLIENT_SECRETS_FILE with the path to your client_secret.json file
CLIENT_SECRETS_FILE = "client_secret.json"
SCOPES = ["https://www.googleapis.com/auth/youtube.force-ssl"]
API_SERVICE_NAME = "youtube"
API_VERSION = "v3"
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
flow.redirect_uri = 'http://localhost:8080/'
authorization_url, state = flow.authorization_url(access_type='offline')
credentials = flow.run_local_server(port=8080)
# Create a new YouTube client using the credentials
youtube = googleapiclient.discovery.build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
# Define the parameters for the new live stream
stream_title = "My Live Stream"
stream_description = "This is a live stream created with the YouTube API"
stream_privacy_status = "public"
stream_body = {
'snippet': {
'title': stream_title,
'description': stream_description,
},
'status': {
'privacyStatus': stream_privacy_status
},
'cdn': {
'ingestionType': 'rtmp',
'frameRate': '30fps', # Frame-Rate hinzufügen
'resolution': '1080p',
}
}
# Call the YouTube API to create the new live stream
live_stream_response = youtube.liveStreams().insert(part="snippet,status,cdn", body=stream_body).execute()
# Get the RTMP ingest URL and stream key from the API response
status_info = live_stream_response["status"]
ingestion_info = live_stream_response["cdn"]["ingestionInfo"]
rtmp_url = ingestion_info["streamName"]
stream_key = ingestion_info["ingestionAddress"]
status = status_info["streamStatus"]
# Print the RTMP URL and stream key
print(f"Status: {status}")
print(f"RTMP URL: {rtmp_url}")
print(f"Stream Key: {stream_key}")
脚本看起来很有效……OAuth 同意屏幕打开,我选择我的 youtube 频道…… 然后它创建 live_stream,我还可以使用 youtube.liveStreams().list 列出实时流 ... 如果我向流发送一个 rtmp,我也可以通过 youtube.liveStreams().list 看到流接收我的数据.
但我无法在我的 YouTube 频道中找到该流……不在工作室中,也无处可寻。 怎么解决?
我尝试创建一个 youtube 直播流。
我希望在我的 youtube 频道上可以看到创建的蒸汽。
如果我列出我返回的频道,例如:
Channel-ID: [HERE IS MY CHANNEL ID]
Status: inactive
Ingestion Type: rtmp
Resolution: variable
Frame Rate: variable
Ingestion Info:
Stream Name: [HERE IS MY STREAM KEY]
Ingestion Address: rtmp://a.rtmp.youtube.com/live2
Backup Ingestion Address: rtmp://b.rtmp.youtube.com/live2?backup=1
Health Status:
Status: noData
Configuration Issues:
Title: Default stream key
Description: Description for default stream key
ID: [HERE IS MY ID]
ChannelId 是正确的....但它显示我的频道没有流。