├── install.jpg ├── obs_ms ├── 0.png ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── 9.png └── and.png ├── README.md └── obs_ms.lua /install.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/install.jpg -------------------------------------------------------------------------------- /obs_ms/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/0.png -------------------------------------------------------------------------------- /obs_ms/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/1.png -------------------------------------------------------------------------------- /obs_ms/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/2.png -------------------------------------------------------------------------------- /obs_ms/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/3.png -------------------------------------------------------------------------------- /obs_ms/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/4.png -------------------------------------------------------------------------------- /obs_ms/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/5.png -------------------------------------------------------------------------------- /obs_ms/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/6.png -------------------------------------------------------------------------------- /obs_ms/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/7.png -------------------------------------------------------------------------------- /obs_ms/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/8.png -------------------------------------------------------------------------------- /obs_ms/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/9.png -------------------------------------------------------------------------------- /obs_ms/and.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imfuding/obs_ms_clock/HEAD/obs_ms/and.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # obs_ms_clock 2 | obs秒表时钟插件(推流时可显示毫秒级的当前电脑时间) 3 | 4 | ## 安装方法与效果: 5 | 6 | ![install](https://github.com/imfuding/obs_ms_clock/blob/master/install.jpg?raw=true) 7 | 8 | ## 感谢 9 | 10 | 在这个[obs_led_clock](https://github.com/lulersoft/obs_led_clock)的基础上改了改,增加了毫秒级,固定了时分秒为2位数. 11 | 12 | 祝你用的开心! 13 | -------------------------------------------------------------------------------- /obs_ms.lua: -------------------------------------------------------------------------------- 1 | obs = obslua 2 | bit = require("bit") 3 | 4 | source_def = {} 5 | source_def.id = "obs_ms" 6 | source_def.output_flags = bit.bor(obs.OBS_SOURCE_VIDEO, obs.OBS_SOURCE_CUSTOM_DRAW) 7 | 8 | function image_source_load(image, file) 9 | obs.obs_enter_graphics(); 10 | obs.gs_image_file_free(image); 11 | obs.obs_leave_graphics(); 12 | 13 | obs.gs_image_file_init(image, file); 14 | 15 | obs.obs_enter_graphics(); 16 | obs.gs_image_file_init_texture(image); 17 | obs.obs_leave_graphics(); 18 | 19 | if not image.loaded then 20 | print("请确保图片存在: " .. file); 21 | end 22 | end 23 | 24 | source_def.get_name = function() 25 | return "毫秒级时钟" 26 | end 27 | 28 | source_def.create = function(source, settings) 29 | local data = {} 30 | 31 | data.n0 = obs.gs_image_file() 32 | data.n1 = obs.gs_image_file() 33 | data.n2 = obs.gs_image_file() 34 | data.n3 = obs.gs_image_file() 35 | data.n4 = obs.gs_image_file() 36 | data.n5 = obs.gs_image_file() 37 | data.n6 = obs.gs_image_file() 38 | data.n7 = obs.gs_image_file() 39 | data.n8 = obs.gs_image_file() 40 | data.n9 = obs.gs_image_file() 41 | data.n = obs.gs_image_file() 42 | 43 | 44 | image_source_load(data.n0, script_path() .. "obs_ms/0.png") 45 | image_source_load(data.n1, script_path() .. "obs_ms/1.png") 46 | image_source_load(data.n2, script_path() .. "obs_ms/2.png") 47 | image_source_load(data.n3, script_path() .. "obs_ms/3.png") 48 | image_source_load(data.n4, script_path() .. "obs_ms/4.png") 49 | image_source_load(data.n5, script_path() .. "obs_ms/5.png") 50 | image_source_load(data.n6, script_path() .. "obs_ms/6.png") 51 | image_source_load(data.n7, script_path() .. "obs_ms/7.png") 52 | image_source_load(data.n8, script_path() .. "obs_ms/8.png") 53 | image_source_load(data.n9, script_path() .. "obs_ms/9.png") 54 | image_source_load(data.n, script_path() .. "obs_ms/and.png") 55 | 56 | return data 57 | end 58 | 59 | source_def.destroy = function(data) 60 | obs.obs_enter_graphics(); 61 | obs.gs_image_file_free(data.n0); 62 | obs.gs_image_file_free(data.n1); 63 | obs.gs_image_file_free(data.n2); 64 | obs.gs_image_file_free(data.n3); 65 | obs.gs_image_file_free(data.n4); 66 | obs.gs_image_file_free(data.n5); 67 | obs.gs_image_file_free(data.n6); 68 | obs.gs_image_file_free(data.n7); 69 | obs.gs_image_file_free(data.n8); 70 | obs.gs_image_file_free(data.n9); 71 | obs.gs_image_file_free(data.n); 72 | 73 | obs.obs_leave_graphics(); 74 | end 75 | 76 | source_def.video_render = function(data, effect) 77 | if not data.n.texture then 78 | return; 79 | end 80 | local time = os.date("*t") 81 | local ms = string.match(tostring(os.clock()), "%d%.(%d+)") 82 | local hours, mins, seconds = AddZeroFrontNum(2,time.hour), AddZeroFrontNum(2,time.min), AddZeroFrontNum(2,time.sec) 83 | 84 | effect = obs.obs_get_base_effect(obs.OBS_EFFECT_DEFAULT) 85 | 86 | obs.gs_blend_state_push() 87 | obs.gs_reset_blend_state() 88 | 89 | while obs.gs_effect_loop(effect, "Draw") do 90 | 91 | local number=tostring(hours) 92 | local k=string.len(number) 93 | local list1={} 94 | for i=1,k do 95 | list1[i]=string.sub(number,i,i) 96 | end 97 | obs.obs_source_draw(get_number(data,list1[1]),0, 0, 0, 0, false); 98 | obs.obs_source_draw(get_number(data,list1[2]),22, 0, 0, 0, false); 99 | obs.obs_source_draw(data.n.texture, 44, 0, 0, 0, false); 100 | 101 | local number=tostring(mins) 102 | local k=string.len(number) 103 | local list1={} 104 | for i=1,k do 105 | list1[i]=string.sub(number,i,i) 106 | end 107 | obs.obs_source_draw(get_number(data,list1[1]),66, 0, 0, 0, false); 108 | obs.obs_source_draw(get_number(data,list1[2]),88, 0, 0, 0, false); 109 | obs.obs_source_draw(data.n.texture, 110, 0, 0, 0, false); 110 | 111 | local number=tostring(seconds) 112 | local k=string.len(number) 113 | local list1={} 114 | for i=1,k do 115 | list1[i]=string.sub(number,i,i) 116 | end 117 | obs.obs_source_draw(get_number(data,list1[1]),132, 0, 0, 0, false); 118 | obs.obs_source_draw(get_number(data,list1[2]),154, 0, 0, 0, false); 119 | obs.obs_source_draw(data.n.texture, 176, 0, 0, 0, false); 120 | 121 | local number=tostring(ms) 122 | local k=string.len(number) 123 | local list1={} 124 | for i=1,k do 125 | list1[i]=string.sub(number,i,i) 126 | end 127 | obs.obs_source_draw(get_number(data,list1[1]),198, 0, 0, 0, false); 128 | obs.obs_source_draw(get_number(data,list1[2]),220, 0, 0, 0, false); 129 | obs.obs_source_draw(get_number(data,list1[3]),242, 0, 0, 0, false); 130 | 131 | end 132 | 133 | obs.gs_blend_state_pop() 134 | end 135 | 136 | function DightNum(num) 137 | if math.floor(num) ~= num or num < 0 then 138 | return -1 139 | elseif 0 == num then 140 | return 1 141 | else 142 | local tmp_dight = 0 143 | while num > 0 do 144 | num = math.floor(num/10) 145 | tmp_dight = tmp_dight + 1 146 | end 147 | return tmp_dight 148 | end 149 | end 150 | 151 | function AddZeroFrontNum(dest_dight, num) 152 | local num_dight = DightNum(num) 153 | if -1 == num_dight then 154 | return -1 155 | elseif num_dight >= dest_dight then 156 | return tostring(num) 157 | else 158 | local str_e = "" 159 | for var =1, dest_dight - num_dight do 160 | str_e = str_e .. "0" 161 | end 162 | return str_e .. tostring(num) 163 | end 164 | end 165 | 166 | 167 | function get_number(data,n) 168 | local t=data.n0.texture 169 | if n=='0' then 170 | t=data.n0.texture 171 | elseif n=='1' then 172 | t=data.n1.texture 173 | elseif n=='2' then 174 | t=data.n2.texture 175 | elseif n=='3' then 176 | t=data.n3.texture 177 | elseif n=='4' then 178 | t=data.n4.texture 179 | elseif n=='5' then 180 | t=data.n5.texture 181 | elseif n=='6' then 182 | t=data.n6.texture 183 | elseif n=='7' then 184 | t=data.n7.texture 185 | elseif n=='8' then 186 | t=data.n8.texture 187 | elseif n=='9' then 188 | t=data.n9.texture 189 | end 190 | return t 191 | end 192 | 193 | source_def.get_width = function(data) 194 | return 264 195 | end 196 | 197 | source_def.get_height = function(data) 198 | return 30 199 | end 200 | 201 | function script_description() 202 | return "obs毫秒级时钟" 203 | end 204 | 205 | obs.obs_register_source(source_def) 206 | --------------------------------------------------------------------------------