场景集合与配置文件
OBS 将其配置组织为场景集合(场景和来源的分组)与配置文件(输出、编码器及服务设置)。本指南介绍如何在它们之间切换、配置视频输出以及设置推流服务目标。
场景集合
| 函数 | 描述 |
|---|
GetSceneCollectionList() | 从 OBS 刷新场景集合列表 |
SetCurrentSceneCollection(Name) | 切换到某个场景集合(会导致 OBS 重新加载!) |
CreateSceneCollection(Name) | 创建新的场景集合并切换到它 |
GetCachedSceneCollections() | 获取本地缓存的场景集合名称 |
GetCurrentSceneCollectionName() | 获取当前场景集合名称(缓存值) |
警告: 切换场景集合会导致 OBS 重新加载所有来源,因此请预期会出现短暂停顿。
配置文件
| 函数 | 描述 |
|---|
GetProfileList() | 从 OBS 刷新配置文件列表 |
SetCurrentProfile(Name) | 切换到某个配置文件 |
CreateProfile(Name) | 创建新的配置文件并切换到它 |
RemoveProfile(Name) | 删除配置文件(无法删除当前正在使用的配置文件!) |
GetProfileParameter(Category, Name) | 获取配置文件中的某个参数 |
SetProfileParameter(Category, Name, Value) | 设置配置文件中的某个参数 |
GetCachedProfiles() | 获取本地缓存的配置文件名称 |
GetCurrentProfileName() | 获取当前配置文件名称(缓存值) |
常用配置文件参数
| 类别 | 参数 | 描述 |
|---|
Output | RecFilePath | 录制目录 |
Output | Mode | 输出模式(简单/高级) |
Stream | key | 推流密钥 |
Stream | server | RTMP 服务器 URL |
视频设置
| 函数 | 描述 |
|---|
GetVideoSettings() | 获取当前分辨率和帧率 |
SetVideoSettings(Settings) | 一次性设置多项视频设置 |
SetBaseResolution(Width, Height) | 设置画布分辨率 |
SetOutputResolution(Width, Height) | 设置输出/缩放分辨率 |
SetFPS(Numerator, Denominator) | 设置帧率 |
GetCachedVideoSettings() | 获取本地缓存的视频设置 |
警告: 在推流或录制期间无法更改视频设置!
常用帧率值
| 帧率 | 分子 | 分母 |
|---|
| 24 | 24 | 1 |
| 30 | 30 | 1 |
| 29.97(NTSC) | 30000 | 1001 |
| 60 | 60 | 1 |
| 59.94(NTSC) | 60000 | 1001 |
| 120 | 120 | 1 |
推流服务设置
| 函数 | 描述 |
|---|
GetStreamServiceSettings() | 获取当前推流目标设置 |
SetStreamServiceSettings(Settings) | 使用结构体设置推流服务 |
SetSimpleRTMPSettings(Server, StreamKey) | 快速配置自定义 RTMP |
GetCachedStreamServiceSettings() | 获取本地缓存的推流设置 |
服务类型
| 类型 | 描述 |
|---|
rtmp_custom | 自定义 RTMP 服务器(由你提供服务器 URL) |
rtmp_common | 预设服务(Twitch、YouTube 等) |
常用 RTMP 服务器
| 服务 | 服务器 URL |
|---|
| Twitch | rtmp://live.twitch.tv/app |
| YouTube | rtmp://a.rtmp.youtube.com/live2 |
| Facebook | rtmps://live-api-s.facebook.com:443/rtmp/ |
| Kick | rtmps://fa723fc1b171.global-contribute.live-video.net/app/ |
设置结构体(FOBSStreamServiceSettings)
| 字段 | 类型 | 描述 |
|---|
StreamServiceType | FString | rtmp_custom 或 rtmp_common |
Server | FString | RTMP 服务器 URL(用于 rtmp_custom) |
Key | FString | 推流密钥(敏感数据!) |
Service | FString | 服务名称(用于 rtmp_common,例如 “Twitch”) |
bUseAuth | bool | 是否使用身份验证 |
Username | FString | 身份验证用户名 |
Password | FString | 身份验证密码 |
注意事项:
- 更改需要重启推流才能生效。
- 推流密钥属于敏感数据,请妥善保管。
- OBS 不会为这些设置推送事件,因此请使用手动刷新。
事件
订阅以下事件以响应配置更改:
OnCurrentSceneCollectionChanging(SceneCollectionName):即将切换场景集合
OnCurrentSceneCollectionChanged(SceneCollectionName):场景集合已切换
OnSceneCollectionListChanged:场景集合列表已修改
OnCurrentProfileChanging(ProfileName):即将切换配置文件
OnCurrentProfileChanged(ProfileName):配置文件已切换
OnProfileListChanged:配置文件列表已修改
OnStreamServiceSettingsReceived(Settings):已获取推流服务设置
另请参阅