Skip to content

Commit 623c129

Browse files
committed
Update source types, add browser json example
1 parent 4294aac commit 623c129

File tree

5 files changed

+151
-19
lines changed

5 files changed

+151
-19
lines changed

README.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Also check out [issues](https://github.com/upgradeQ/OBS-Studio-Python-Scripting-
1515
- [Additional input](#additional-input)
1616
- [obs_data](#obs_data)
1717
- [Print all source settings and filter names](#print-all-source-settings-and-filter-names)
18-
- [save settings as json](#save-settings-as-json)
18+
- [Save settings as json](#save-settings-as-json)
1919
- [Source's and filters with identifier string](#sources-and-filters-with-identifier-string)
2020
- [Add source](#add-source)
2121
- [Move source](#move-source)
@@ -33,6 +33,7 @@ Also check out [issues](https://github.com/upgradeQ/OBS-Studio-Python-Scripting-
3333
- [Play sound](#play-sound)
3434
- [Read and write private data from scripts or plugins](#read-and-write-private-data-from-scripts-or-plugins)
3535
- [Browser source interaction](#browser-source-interaction)
36+
- [Browser source receive JSON data](#browser-source-receive-json-data)
3637
- [Access source dB volume level](#access-source-db-volume-level)
3738
- [Get current profile settings via ffi](#get-current-profile-settings-via-ffi)
3839
- [Debug](#debug)
@@ -173,48 +174,52 @@ To identify with `obs_source_get_unversioned_id` , or creating source/filter.
173174
## Source's
174175
| Name | Source type identifier string |
175176
| --- | --- |
177+
| Application Audio Capture (BETA) | wasapi_process_output_capture |
176178
| Browser | browser_source |
177179
| Color Source | color_source |
178180
| Display Capture | monitor_capture |
179181
| Game Capture | game_capture |
180-
| Image | image_source |
181182
| Image Slide Show | slideshow |
183+
| Image | image_source |
182184
| Media Source | ffmpeg_source |
183185
| Text (GDI+) | text_gdiplus |
184186
| Window Capture | window_capture |
185187
## Filters
186188
| Name | Source type identifier string |
187189
| --- | --- |
190+
| 3-Band Equalizer | basic_eq_filter |
188191
| Async Delay | async_delay_filter |
189-
| Chroma Key | chroma_key_filter |
190192
| Chroma Key V2 | chroma_key_filter_v2 |
191-
| Color Correction | color_filter |
193+
| Chroma Key | chroma_key_filter |
192194
| Color Correction V2 | color_filter_v2 |
193-
| Color Key | color_key_filter |
194-
| Color Key V2 | color_key_filter_v2 |
195+
| Color Correction | color_filter |
195196
| Color Grade | color_grade_filter |
197+
| Color Key V2 | color_key_filter_v2 |
198+
| Color Key | color_key_filter |
196199
| Compressor | compressor_filter |
197200
| Crop/Pad | crop_filter |
198201
| Expander | expander_filter |
199-
| Gain | gain_filter |
200202
| GPU Delay | gpu_delay_filter |
203+
| Gain | gain_filter |
204+
| HDR Tone Mapping (Override) | hdr_tonemap_filter |
201205
| Image Mask/Blend | mask_filter |
202206
| Invert Polarity | invert_polarity_filter |
203207
| Limiter | limiter_filter |
204-
| Luma Key | luma_key_filter |
205208
| Luma Key V2 | luma_key_filter_v2 |
206-
| Mask | mask_filter |
209+
| Luma Key | luma_key_filter |
207210
| Mask V2 | mask_filter_v2 |
211+
| Mask | mask_filter |
208212
| Noise Gate | noise_gate_filter |
209-
| Noise Suppression | noise_suppress_filter |
210213
| Noise Suppression V2 | noise_suppress_filter_v2 |
214+
| Noise Suppression | noise_suppress_filter |
211215
| Render Delay | gpu_delay |
212216
| Scaling/Aspect Ratio | scale_filter |
213217
| Scroll | scroll_filter |
214-
| Sharpen | sharpness_filter |
215218
| Sharpen V2 | sharpness_filter_v2 |
216-
| Video Delay (Async) | async_delay_filter |
219+
| Sharpen | sharpness_filter |
220+
| Upward Compressor | upward_compressor_filter |
217221
| VST 2.x Plug-in | vst_filter |
222+
| Video Delay (Async) | async_delay_filter |
218223

219224
# Add source
220225
Create source and add it to current scene
@@ -443,7 +448,7 @@ def callback(calldata):
443448
print("on source show",S.obs_source_get_name(source))
444449
```
445450

446-
**destroy**, **remove**, **save**, **load**, **activate**, **deactivate**, **show**, **hide**, **mute**, **push_to_mute_changed**, **push_to_mute_delay**, **push_to_talk_changed**, **push_to_talk_delay**, **enable**, **rename**, **volume**, **update_properties**, **update_flags**, **audio_sync**, **audio_mixers**, **filter_add**, **filter_remove**, **reorder_filters**, **transition_start**, **transition_video_stop**, **transition_stop**, **media_started**, **media_ended**, **media_pause**, **media_play**, **media_restart**, **media_stopped**, **media_next**, **media_previous**
451+
**destroy**, **remove**, **save**, **load**, **activate**, **deactivate**, **show**, **hide**, **mute**, **push_to_mute_changed**, **push_to_mute_delay**, **push_to_talk_changed**, **push_to_talk_delay**, **enable**, **rename**, **volume**, **update_properties**, **update_flags**, **audio_sync**, **audio_mixers**, **filter_add**, **filter_remove**, **reorder_filters**, **transition_start**, **transition_video_stop**, **transition_stop**, **media_started**, **media_ended**, **media_pause**, **media_play**, **media_restart**, **media_stopped**, **media_next**, **media_previous**, **update**
447452

448453
https://obsproject.com/docs/reference-sources.html#source-signals
449454

@@ -665,6 +670,36 @@ def press_shift_tab(*p):
665670
```
666671
- [Full source](src/browser_source_interaction.py)
667672

673+
# Browser source receive JSON data
674+
```python
675+
cd = S.calldata_create()
676+
ph = S.obs_source_get_proc_handler(source)
677+
S.calldata_set_string(cd, "eventName", "my-test-event")
678+
S.calldata_set_string(cd, "jsonString", '{"key123": "\\nvalue123"}')
679+
S.proc_handler_call(ph, "javascript_event", cd)
680+
S.calldata_destroy(cd)
681+
```
682+
683+
Page source code, currently has no permission requirements.
684+
685+
```javascript
686+
687+
<!DOCTYPE html>
688+
689+
<body style="background-color:aquamarine;">
690+
<h1>HTML h1 in body element</h1>
691+
</body>
692+
693+
<script type="text/javascript">
694+
window.addEventListener('my-test-event', function(event) {
695+
document.body.innerHTML +=(event.detail['key123']);
696+
})
697+
</script>
698+
```
699+
700+
701+
- [Full source](src/browser_source_json.py)
702+
668703
# Access source dB volume level
669704
There is FFI `ctypes` module in Python to wrap native `obs` lib.
670705
However,to run it on GNU/Linux you must start obs with `LD_PRELOAD`.

src/browser_source_json.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import obspython as S
2+
from contextlib import contextmanager
3+
4+
G = lambda: ...
5+
6+
7+
@contextmanager
8+
def source_auto_release(source_name):
9+
source = S.obs_get_source_by_name(source_name)
10+
try:
11+
yield source
12+
finally:
13+
S.obs_source_release(source)
14+
15+
16+
def send_json_event(*p):
17+
with source_auto_release(G.source_name) as source:
18+
print("begin test event")
19+
cd = S.calldata_create()
20+
ph = S.obs_source_get_proc_handler(source)
21+
S.calldata_set_string(cd, "eventName", "my-test-event")
22+
S.calldata_set_string(cd, "jsonString", '{"key123": "\\nvalue123"}')
23+
S.proc_handler_call(ph, "javascript_event", cd)
24+
S.calldata_destroy(cd)
25+
print("end test event")
26+
27+
28+
def script_update(settings):
29+
G.source_name = S.obs_data_get_string(settings, "source")
30+
31+
32+
def script_properties(): # ui
33+
props = S.obs_properties_create()
34+
p = S.obs_properties_add_list(
35+
props,
36+
"source",
37+
"Browser source",
38+
S.OBS_COMBO_TYPE_EDITABLE,
39+
S.OBS_COMBO_FORMAT_STRING,
40+
)
41+
S.obs_properties_add_button(props, "button1", "Send JSON", send_json_event)
42+
sources = S.obs_enum_sources()
43+
if sources is not None:
44+
for source in sources:
45+
source_id = S.obs_source_get_unversioned_id(source)
46+
if source_id == "browser_source":
47+
name = S.obs_source_get_name(source)
48+
S.obs_property_list_add_string(p, name, name)
49+
50+
S.source_list_release(sources)
51+
return props

0 commit comments

Comments
 (0)