-
先在OBS安裝 websocket
https://github.com/obsproject/obs-websocket/releases/tag/4.9.1
安裝obs-websocket-4.9.1-Windows-Installer.exe
2.OSB會出現
工具 會出現 websocket server setting
3.設定 websocket port 與 密碼
4.然後python
#!/usr/bin/env python
–
– coding: utf-8 –
–
import sys
import time
import logging
logging.basicConfig(level=logging.INFO)
sys.path.append(‘…/’)
from obswebsocket import obsws, requests # noqa: E402
host = “localhost”
port = 4444
password = “12345678”
ws = obsws(host, port, password)
ws.connect()
try:
ddd=ws.call(requests.GetSourceSettings(sourceName="test123") )
print("ddd1:",ddd.getSourceSettings()["window"])
mmm=ws.call(requests.SetSourceSettings(sourceName="test123", sourceSettings={'window':'我:Qt5152QWindowIcon:LINE.exe'} )) #OK
ddd=ws.call(requests.GetSourceSettings(sourceName="test123"))
print("ddd2:",ddd.getSourceSettings()["window"])
except KeyboardInterrupt:
pass
ws.disconnect()
5.結果 可以置換 source 項目
(facebook) C:\Users\111\qt_exam\obs>python try0203.py
INFO:obswebsocket.core:Connecting…
INFO:obswebsocket.core:Connected!
ddd1: Get Window Dropdown List for Window Capture Source? · Issue #22754 · obsproject/obs-websocket · GitHub 和其他 7 個頁面 – 設定檔 1 – Microsoft Edge:Chrome_WidgetWin_1:msedge.exe
ddd2: 我:Qt5152QWindowIcon:LINE.exe
INFO:obswebsocket.core:Disconnecting
6.補充:
ws.call(requests.GetSceneItemProperties(scene_name=“場景一”, item=“aaa”))
ws.call(requests.SetSceneItemProperties(scene_name=“場景一”, item=“aaa” , bounds={“x”:1000}))
7.補充新功能
要新增各種視覺特效,原本新增媒體來源,但是obs-websocket 沒辦法隨時更換檔案
因此用 新增瀏覽器
-
場景為scene2, 新增一個瀏覽器為browser,
畫面開關為
ws.call(requests.SetSceneItemProperties(scene_name=“scene2”, item=“browser”, visible=False))
ws.call(requests.SetSceneItemProperties(scene_name=“scene2”, item=“browser”, visible=True))
把畫面拉到視窗大小
ws.call(requests.SetSceneItemProperties(scene_name=“scene2”, item=“browser”, bounds={“type”:“OBS_BOUNDS_STRETCH”, “x”:1280,“y”:720} ))
最後播放畫面
ws.call(requests.SetBrowserSourceProperties(source=“browser”,local_file=“C:/Users/111/facebook3/effect/image/222.mp4”, shutdown=True,render=True ))
PS: 如果要重播一次 記得要把shutdown 改為False ( 每次要不一樣,才能重新執行)