Skip to content

Commit 23401b7

Browse files
authored
Merge pull request #139 from OPENSPHERE-Inc/dev
chore: Add sample code snipets for Lua
2 parents 4c81527 + a529459 commit 23401b7

2 files changed

Lines changed: 188 additions & 0 deletions

File tree

API.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ if bo_filter:
5656
obs.obs_source_release(bo_filter)
5757
```
5858

59+
**Lua sample code**
60+
61+
```lua
62+
local obs = obslua
63+
64+
-- Get the target Branch Output filter by UUID
65+
local bo_filter = obs.obs_get_source_by_uuid(filter_uuid)
66+
if bo_filter ~= nil then
67+
local ph = obs.obs_source_get_proc_handler(bo_filter)
68+
local cd = obs.calldata_create()
69+
obs.calldata_set_string(cd, "format", "MyShow %CCYY-%MM-%DD %hh-%mm-%ss")
70+
obs.proc_handler_call(ph, "override_recording_filename_format", cd)
71+
obs.calldata_free(cd)
72+
obs.obs_source_release(bo_filter)
73+
end
74+
75+
-- Clear the override (pass an empty string)
76+
local bo_filter = obs.obs_get_source_by_uuid(filter_uuid)
77+
if bo_filter ~= nil then
78+
local ph = obs.obs_source_get_proc_handler(bo_filter)
79+
local cd = obs.calldata_create()
80+
obs.calldata_set_string(cd, "format", "")
81+
obs.proc_handler_call(ph, "override_recording_filename_format", cd)
82+
obs.calldata_free(cd)
83+
obs.obs_source_release(bo_filter)
84+
end
85+
```
86+
5987
### Overriding the Replay Buffer Save Filename Format
6088

6189
A procedure registered on the Branch Output filter source that overrides the output filename format used when the replay buffer is saved.
@@ -96,6 +124,34 @@ if bo_filter:
96124
obs.obs_source_release(bo_filter)
97125
```
98126

127+
**Lua sample code**
128+
129+
```lua
130+
local obs = obslua
131+
132+
-- Get the target Branch Output filter by UUID
133+
local bo_filter = obs.obs_get_source_by_uuid(filter_uuid)
134+
if bo_filter ~= nil then
135+
local ph = obs.obs_source_get_proc_handler(bo_filter)
136+
local cd = obs.calldata_create()
137+
obs.calldata_set_string(cd, "format", "Replay %CCYY-%MM-%DD %hh-%mm-%ss")
138+
obs.proc_handler_call(ph, "override_replay_buffer_filename_format", cd)
139+
obs.calldata_free(cd)
140+
obs.obs_source_release(bo_filter)
141+
end
142+
143+
-- Clear the override (pass an empty string)
144+
local bo_filter = obs.obs_get_source_by_uuid(filter_uuid)
145+
if bo_filter ~= nil then
146+
local ph = obs.obs_source_get_proc_handler(bo_filter)
147+
local cd = obs.calldata_create()
148+
obs.calldata_set_string(cd, "format", "")
149+
obs.proc_handler_call(ph, "override_replay_buffer_filename_format", cd)
150+
obs.calldata_free(cd)
151+
obs.obs_source_release(bo_filter)
152+
end
153+
```
154+
99155
### Retrieving the Branch Output Filter List
100156

101157
A global procedure that returns the list of Branch Output filters currently loaded in OBS. Since the override procedures above require the target filter's UUID, this procedure is typically used to present the filter list to the user for selection.
@@ -161,6 +217,44 @@ def get_branch_output_filters():
161217
return filters
162218
```
163219

220+
**Lua sample code**
221+
222+
Since Lua does not have a built-in JSON parser, we use OBS's `obs_data_create_from_json()` to parse the returned JSON string.
223+
224+
```lua
225+
local obs = obslua
226+
227+
function get_branch_output_filters()
228+
local filters = {}
229+
local ph = obs.obs_get_proc_handler()
230+
local cd = obs.calldata_create()
231+
232+
if obs.proc_handler_call(ph, "osi_branch_output_get_filter_list", cd) then
233+
local json_str = obs.calldata_string(cd, "json")
234+
if json_str and json_str ~= "" then
235+
local data = obs.obs_data_create_from_json(json_str)
236+
local array = obs.obs_data_get_array(data, "filters")
237+
local count = obs.obs_data_array_count(array)
238+
for i = 0, count - 1 do
239+
local item = obs.obs_data_array_item(array, i)
240+
table.insert(filters, {
241+
source_name = obs.obs_data_get_string(item, "source_name"),
242+
source_uuid = obs.obs_data_get_string(item, "source_uuid"),
243+
filter_name = obs.obs_data_get_string(item, "filter_name"),
244+
filter_uuid = obs.obs_data_get_string(item, "filter_uuid"),
245+
})
246+
obs.obs_data_release(item)
247+
end
248+
obs.obs_data_array_release(array)
249+
obs.obs_data_release(data)
250+
end
251+
end
252+
253+
obs.calldata_free(cd)
254+
return filters
255+
end
256+
```
257+
164258
### Using the Sample Scripts
165259

166260
The sample scripts are written in Python. Before using them, make sure that Python Settings are properly configured in OBS under Tools → Scripts.

API_ja.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ if bo_filter:
5656
obs.obs_source_release(bo_filter)
5757
```
5858

59+
**Lua サンプルコード**
60+
61+
```lua
62+
local obs = obslua
63+
64+
-- 対象 Branch Output フィルターを UUID から取得
65+
local bo_filter = obs.obs_get_source_by_uuid(filter_uuid)
66+
if bo_filter ~= nil then
67+
local ph = obs.obs_source_get_proc_handler(bo_filter)
68+
local cd = obs.calldata_create()
69+
obs.calldata_set_string(cd, "format", "MyShow %CCYY-%MM-%DD %hh-%mm-%ss")
70+
obs.proc_handler_call(ph, "override_recording_filename_format", cd)
71+
obs.calldata_free(cd)
72+
obs.obs_source_release(bo_filter)
73+
end
74+
75+
-- オーバーライドをクリア(空文字列を渡す)
76+
local bo_filter = obs.obs_get_source_by_uuid(filter_uuid)
77+
if bo_filter ~= nil then
78+
local ph = obs.obs_source_get_proc_handler(bo_filter)
79+
local cd = obs.calldata_create()
80+
obs.calldata_set_string(cd, "format", "")
81+
obs.proc_handler_call(ph, "override_recording_filename_format", cd)
82+
obs.calldata_free(cd)
83+
obs.obs_source_release(bo_filter)
84+
end
85+
```
86+
5987
### リプレーバッファー保存ファイル名フォーマットのオーバーライド
6088

6189
Branch Output フィルターソースに登録されたプロシージャで、リプレイバッファ保存時の出力ファイル名フォーマットを実行時にオーバーライドします。
@@ -96,6 +124,34 @@ if bo_filter:
96124
obs.obs_source_release(bo_filter)
97125
```
98126

127+
**Lua サンプルコード**
128+
129+
```lua
130+
local obs = obslua
131+
132+
-- 対象 Branch Output フィルターを UUID から取得
133+
local bo_filter = obs.obs_get_source_by_uuid(filter_uuid)
134+
if bo_filter ~= nil then
135+
local ph = obs.obs_source_get_proc_handler(bo_filter)
136+
local cd = obs.calldata_create()
137+
obs.calldata_set_string(cd, "format", "Replay %CCYY-%MM-%DD %hh-%mm-%ss")
138+
obs.proc_handler_call(ph, "override_replay_buffer_filename_format", cd)
139+
obs.calldata_free(cd)
140+
obs.obs_source_release(bo_filter)
141+
end
142+
143+
-- オーバーライドをクリア(空文字列を渡す)
144+
local bo_filter = obs.obs_get_source_by_uuid(filter_uuid)
145+
if bo_filter ~= nil then
146+
local ph = obs.obs_source_get_proc_handler(bo_filter)
147+
local cd = obs.calldata_create()
148+
obs.calldata_set_string(cd, "format", "")
149+
obs.proc_handler_call(ph, "override_replay_buffer_filename_format", cd)
150+
obs.calldata_free(cd)
151+
obs.obs_source_release(bo_filter)
152+
end
153+
```
154+
99155
### Branch Output フィルター一覧取得
100156

101157
OBS にロードされている Branch Output フィルターの一覧を取得するためのグローバルプロシージャです。上記のオーバーライドプロシージャを呼び出すには対象フィルターの UUID が必要なので、このプロシージャで取得した一覧からユーザーに選択させるのが一般的です。
@@ -161,6 +217,44 @@ def get_branch_output_filters():
161217
return filters
162218
```
163219

220+
**Lua サンプルコード**
221+
222+
Lua には標準の JSON パーサーがないため、OBS が提供する `obs_data_create_from_json()` を使って返された JSON 文字列を解析します。
223+
224+
```lua
225+
local obs = obslua
226+
227+
function get_branch_output_filters()
228+
local filters = {}
229+
local ph = obs.obs_get_proc_handler()
230+
local cd = obs.calldata_create()
231+
232+
if obs.proc_handler_call(ph, "osi_branch_output_get_filter_list", cd) then
233+
local json_str = obs.calldata_string(cd, "json")
234+
if json_str and json_str ~= "" then
235+
local data = obs.obs_data_create_from_json(json_str)
236+
local array = obs.obs_data_get_array(data, "filters")
237+
local count = obs.obs_data_array_count(array)
238+
for i = 0, count - 1 do
239+
local item = obs.obs_data_array_item(array, i)
240+
table.insert(filters, {
241+
source_name = obs.obs_data_get_string(item, "source_name"),
242+
source_uuid = obs.obs_data_get_string(item, "source_uuid"),
243+
filter_name = obs.obs_data_get_string(item, "filter_name"),
244+
filter_uuid = obs.obs_data_get_string(item, "filter_uuid"),
245+
})
246+
obs.obs_data_release(item)
247+
end
248+
obs.obs_data_array_release(array)
249+
obs.obs_data_release(data)
250+
end
251+
end
252+
253+
obs.calldata_free(cd)
254+
return filters
255+
end
256+
```
257+
164258
### サンプルスクリプトの使い方
165259

166260
サンプルスクリプトは Python で書かれていますので、使用する前に OBS メニューの Tools → Scripts で Python Settings が正しく設定されているか確認してください。

0 commit comments

Comments
 (0)