Automatically create video source through python script

kebslau11

New Member
Hey there, I am trying to create a video source with window capture and I have been having a difficult time on how to make one through python script.
I found this link that has a code snippet for text sources but still can't figure out how to create a video source so hoping someone has found a way to do it.
 

Nom_XD

New Member
Hi, hi, so here is how I did it:

1) Creating a scene with python
myscene = obspython.obs_scene_create("my scene")

2) Adding a window capture (video source) to it
mysource = obspython.obs_source_create_private("window_capture", "my window capture", None)

3) Adding source to the new scene
obspython.obs_scene_add(myscene, mysource)

Thank you so much for the link, by the way. I discovered how to use it with you. We have to use the specific string ID of the source we want to add, and I was looking everywhere for it. The id

for text is in:
obs-studio/plugins/obs-text/gdiplus/obs-text.cpp (text_gdiplus)

for window capture is in:
obs-studio/plugins/win-capture/window-capture.c (window_capture)

So yeah, we have to find their id by going to source files and looking for them (the string id is the 1st argument of the function create); there isn't a single place with them all. For people who want to find more, they are all in this folder plugins from the obs-studio source files https://github.com/obsproject/obs-studio.git

PS: If we try to create a source with a text id of an inexistent type, nothing will show in obs, but the source is still made.
 
Last edited:

Nom_XD

New Member
By the way, it's probably best to call obspython.obs_source_create("window_capture", "my window capture", None, None) with one extra parameter for hotkeys instead of obs_source_create_private, private sources are not listed by obspython.obs_enum_sources(). But It depends on what we are doing.
 
Top