obs studio自带的websocket的本地配置文件夹在哪里
时间: 2025-08-01 15:22:58 浏览: 16
<think>OBS Studio的WebSocket服务器配置信息存储在配置文件中,具体位置取决于操作系统。
下面我将分别介绍Windows、macOS和Linux系统下的配置文件位置。</think># OBS Studio WebSocket 配置文件位置详解
OBS Studio 的 WebSocket 服务器配置信息存储在特定位置的文件中,具体位置取决于操作系统。以下是各平台的详细配置信息:
## 配置文件位置
### Windows 系统
```plaintext
C:\Users\<用户名>\AppData\Roaming\obs-studio\plugin_config\obs-websocket\
```
主要配置文件:
- `obsWebSocket.txt` - WebSocket 服务器设置
- `obsWebSocketAuth.txt` - 认证密码信息
### macOS 系统
```plaintext
/Users/<用户名>/Library/Application Support/obs-studio/plugin_config/obs-websocket/
```
主要配置文件:
- `obsWebSocket.txt` - WebSocket 服务器设置
- `obsWebSocketAuth.txt` - 认证密码信息
### Linux 系统
```plaintext
/home/<用户名>/.config/obs-studio/plugin_config/obs-websocket/
```
主要配置文件:
- `obsWebSocket.txt` - WebSocket 服务器设置
- `obsWebSocketAuth.txt` - 认证密码信息
## 配置文件内容解析
### obsWebSocket.txt 文件格式
```ini
[General]
Enabled=true
ServerPort=4455
LockToIPv4=false
EnableAuthentication=true
DebugEnabled=false
AlertsEnabled=true
```
字段说明:
- `Enabled`: WebSocket 服务器是否启用 (true/false)
- `ServerPort`: WebSocket 服务器端口号
- `LockToIPv4`: 是否仅使用 IPv4 (true/false)
- `EnableAuthentication`: 是否启用密码认证 (true/false)
- `DebugEnabled`: 是否启用调试模式 (true/false)
- `AlertsEnabled`: 是否显示连接提示 (true/false)
### obsWebSocketAuth.txt 文件格式
```ini
[General]
ServerPassword=your_secure_password_here
Salt=random_salt_value
```
字段说明:
- `ServerPassword`: WebSocket 服务器密码 (明文存储)
- `Salt`: 用于密码验证的随机盐值
## 通过代码访问配置
以下 Python 脚本可以读取和修改 OBS WebSocket 配置:
```python
import os
import configparser
import platform
def get_obs_websocket_config_path():
"""获取 OBS WebSocket 配置文件路径"""
system = platform.system()
username = os.getlogin()
if system == "Windows":
return f"C:\\Users\\{username}\\AppData\\Roaming\\obs-studio\\plugin_config\\obs-websocket"
elif system == "Darwin": # macOS
return f"/Users/{username}/Library/Application Support/obs-studio/plugin_config/obs-websocket"
elif system == "Linux":
return f"/home/{username}/.config/obs-studio/plugin_config/obs-websocket"
else:
raise OSError("Unsupported operating system")
def read_websocket_config():
"""读取 WebSocket 配置"""
config_path = get_obs_websocket_config_path()
config = configparser.ConfigParser()
# 读取服务器配置
server_config = {}
with open(os.path.join(config_path, "obsWebSocket.txt"), "r") as f:
for line in f:
if "=" in line:
key, value = line.strip().split("=", 1)
server_config[key] = value
# 读取认证配置
auth_config = {}
auth_file = os.path.join(config_path, "obsWebSocketAuth.txt")
if os.path.exists(auth_file):
with open(auth_file, "r") as f:
for line in f:
if "=" in line:
key, value = line.strip().split("=", 1)
auth_config[key] = value
return {
"server": server_config,
"auth": auth_config
}
def update_websocket_config(port=None, enable_auth=None, password=None):
"""更新 WebSocket 配置"""
config_path = get_obs_websocket_config_path()
# 更新服务器配置
server_file = os.path.join(config_path, "obsWebSocket.txt")
server_lines = []
if os.path.exists(server_file):
with open(server_file, "r") as f:
server_lines = f.readlines()
updated_server_lines = []
for line in server_lines:
if port is not None and line.startswith("ServerPort="):
line = f"ServerPort={port}\n"
if enable_auth is not None and line.startswith("EnableAuthentication="):
line = f"EnableAuthentication={'true' if enable_auth else 'false'}\n"
updated_server_lines.append(line)
with open(server_file, "w") as f:
f.writelines(updated_server_lines)
# 更新认证配置
if password is not None:
auth_file = os.path.join(config_path, "obsWebSocketAuth.txt")
with open(auth_file, "w") as f:
f.write(f"ServerPassword={password}\n")
# 注意:实际应用中应生成新的随机盐值
f.write("Salt=random_salt_value\n")
# 示例:读取当前配置
current_config = read_websocket_config()
print("当前配置:")
print(f"端口: {current_config['server'].get('ServerPort', '4455')}")
print(f"启用认证: {current_config['server'].get('EnableAuthentication', 'false')}")
if 'ServerPassword' in current_config['auth']:
print(f"密码: {current_config['auth']['ServerPassword']}")
# 示例:更新配置
# update_websocket_config(port=5555, enable_auth=True, password="new_secure_password")
```
## 配置安全注意事项
1. **密码安全**:
- 密码以明文存储在 `obsWebSocketAuth.txt` 中
- 建议使用强密码并限制访问权限
- 定期更换密码
2. **权限管理**:
```bash
# Linux/macOS 设置文件权限
chmod 600 /path/to/obsWebSocketAuth.txt
# Windows 设置文件权限
icacls "C:\...\obsWebSocketAuth.txt" /inheritance:r
icacls "C:\...\obsWebSocketAuth.txt" /grant:r "%USERNAME%":R
```
3. **网络访问控制**:
- 在路由器/防火墙上限制访问 IP
- 仅允许受信任的网络访问 WebSocket 端口
## 通过 OBS API 动态配置
以下是通过 OBS WebSocket API 动态获取和修改配置的方法:
```python
import obsws_python as obs
# 连接到 OBS WebSocket
cl = obs.ReqClient(host='localhost', port=4455, password='your_password')
# 获取当前 WebSocket 设置
def get_websocket_settings():
settings = cl.get_persistent_data(realm='OBS_WEBSOCKET_DATA_REALM_GLOBAL', slot='obsWebSocketServerSettings')
return settings.slot_data
# 更新 WebSocket 设置
def update_websocket_settings(port=None, enable_auth=None, password=None):
current_settings = get_websocket_settings()
if port:
current_settings['serverPort'] = port
if enable_auth is not None:
current_settings['authenticationEnabled'] = enable_auth
if password:
current_settings['serverPassword'] = password
cl.set_persistent_data(
realm='OBS_WEBSOCKET_DATA_REALM_GLOBAL',
slot='obsWebSocketServerSettings',
slot_data=current_settings
)
print("设置已更新,需要重启 OBS 才能生效")
# 示例:获取当前设置
print("当前 WebSocket 设置:", get_websocket_settings())
# 示例:更新设置
# update_websocket_settings(port=5555, enable_auth=True, password="new_password")
```
## 配置恢复与备份
### 备份脚本
```bash
#!/bin/bash
# Linux/macOS 配置备份脚本
OBS_CONFIG_DIR="$HOME/.config/obs-studio"
BACKUP_DIR="$HOME/obs_config_backup"
DATE=$(date +%Y%m%d)
mkdir -p "$BACKUP_DIR/$DATE"
cp -r "$OBS_CONFIG_DIR/plugin_config" "$BACKUP_DIR/$DATE/"
echo "配置已备份到: $BACKUP_DIR/$DATE"
```
### Windows 批处理备份脚本
```batch
@echo off
set OBS_CONFIG_DIR=%USERPROFILE%\AppData\Roaming\obs-studio
set BACKUP_DIR=%USERPROFILE%\obs_config_backup
set DATE=%date:/=-%
mkdir "%BACKUP_DIR%\%DATE%"
xcopy /E /I "%OBS_CONFIG_DIR%\plugin_config" "%BACKUP_DIR%\%DATE%\plugin_config"
echo 配置已备份到: %BACKUP_DIR%\%DATE%
```
阅读全文
相关推荐




















