
OBS 根据直播/录制状态自动切换显示状态
效果
空闲

推流

录制

实现
编写 lua 脚本,在 OBS 产生事件 obs.OBS_FRONTEND_EVENT_<EVENT>.START/STOP 时,修改源的显示状态
-- Function to toggle source visibility
function on_event(event)
if event == obs.OBS_FRONTEND_EVENT_STREAMING_STARTED then
-- show live
-- hide record and free
show_source(source_name_live)
hide_source(source_name_record)
hide_source(source_name_free)
end
if event == obs.OBS_FRONTEND_EVENT_STREAMING_STOPPED then
-- hide live
-- show free
hide_source(source_name_live)
show_source(source_name_free)
end
if event == obs.OBS_FRONTEND_EVENT_RECORDING_STARTED then
-- show record
-- hide live and free
show_source(source_name_record)
hide_source(source_name_live)
hide_source(source_name_free)
end
if event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPED then
-- hide record
-- show free
hide_source(source_name_record)
show_source(source_name_free)
end
end
安装
创建 show-status.lua 文件,将以下代码复制进去
show-status.lua
obs = obslua
source_name_record = ""
source_name_live = ""
source_name_free = ""
function hide_source(source_name)
local source = obs.obs_get_source_by_name(source_name)
if source ~= nil then
obs.obs_source_set_enabled(source, false)
end
obs.obs_source_release(source)
end
function show_source(source_name)
local source = obs.obs_get_source_by_name(source_name)
if source ~= nil then
obs.obs_source_set_enabled(source, true)
end
obs.obs_source_release(source)
end
-- Function to toggle source visibility
function on_event(event)
if event == obs.OBS_FRONTEND_EVENT_STREAMING_STARTED then
-- show live
-- hide record and free
show_source(source_name_live)
hide_source(source_name_record)
hide_source(source_name_free)
end
if event == obs.OBS_FRONTEND_EVENT_STREAMING_STOPPED then
-- hide live
-- show free
hide_source(source_name_live)
show_source(source_name_free)
end
if event == obs.OBS_FRONTEND_EVENT_RECORDING_STARTED then
-- show record
-- hide live and free
show_source(source_name_record)
hide_source(source_name_live)
hide_source(source_name_free)
end
if event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPED then
-- hide record
-- show free
hide_source(source_name_record)
show_source(source_name_free)
end
end
----------------------------------------------------------------
-- A function named script_properties defines the properties that the user
-- can change for the entire script module itself
function script_properties()
local props = obs.obs_properties_create()
obs.obs_properties_add_text(props, "source_name_record", "Record icon source name", obs.OBS_TEXT_DEFAULT)
obs.obs_properties_add_text(props, "source_name_live", "Live icon source name", obs.OBS_TEXT_DEFAULT)
obs.obs_properties_add_text(props, "source_name_free", "Free icon source name", obs.OBS_TEXT_DEFAULT)
return props
end
-- A function named script_description returns the description shown to
-- the user
function script_description()
return "Toggles visibility of sources based on streaming and recording status\n\n\nMade by Jz0ojiang"
end
-- A function named script_update will be called when settings are changed
function script_update(settings)
source_name_record = obs.obs_data_get_string(settings, "source_name_record")
source_name_live = obs.obs_data_get_string(settings, "source_name_live")
source_name_free = obs.obs_data_get_string(settings, "source_name_free")
end
-- A function named script_defaults will be called to set the default settings
function script_defaults(settings)
obs.obs_data_set_default_string(settings, "source_name_record", "record_icon")
obs.obs_data_set_default_string(settings, "source_name_live", "live_icon")
obs.obs_data_set_default_string(settings, "source_name_free", "free_icon")
end
function script_load(settings)
obs.obs_frontend_add_event_callback(on_event)
end
在 OBS - 工具 – 脚本,添加 show-status.lua 文件,保存


创建 record_icon、live_icon、free_icon 源,分别设置为录制、推流、空闲状态的图标
头图、封面来源:Unsplash - Grace Brauteseth
评论
评论加载中…