效果

空闲

推流

录制

实现

编写 lua 脚本,在 OBS 产生事件 obs.OBS_FRONTEND_EVENT_<EVENT>.START/STOP 时,修改源的显示状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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_iconlive_iconfree_icon 源,分别设置为录制、推流、空闲状态的图标

头图、封面来源:Unsplash - Grace Brauteseth