Create video/webcam sources in a script

clementparis

New Member
Hello,

This is my first post here so sorry if I am not perfectly clear.

I try to create sources with a script, one for a webcam and a second for a rtsp video flux.
It can be in Lua or in Python if possible but it seem if I don't make a mistake that it was not possible in Python.
I have looked in the API doc and on a lot of online resources but I have found thinks for create image sources or text but I have not found any things for video or webcam.

I have read : Script Sources (Lua Only) and Use a Lua Script to Import Your Twitch Streaming Overlay Designs into OBS Studio Streaming Overlay Designs into OBS Studio and a lot of another websites

I continue tu search but if some one can help me, thank you in advance.

Best
 

stephematician

New Member
The only way I got a hint for this is to look through OBS source code (specifically the v4l2 and capture plugins).

Your Lua source will need a `video_render` function (if you use source type OBS_SOURCE_VIDEO).

Lua:
info.video_render = function(my_source_data, effect)
        [...]
end

Within this function, you'll need to:
  1. Enter a graphics context.
  2. Construct a obs_source_frame and call obs_source_output_video (see https://docs.obsproject.com/reference-sources#c.obs_source_output_video)
    1. Alternative? You could construct a texture and call obs_source_draw.
  3. Leave the graphics context.
I make no guarantee this is correct, as I got here because I was asking the very same question!
 

stephematician

New Member
  1. Enter a graphics context.
  2. Construct a obs_source_frame and call obs_source_output_video (see https://docs.obsproject.com/reference-sources#c.obs_source_output_video)
    1. Alternative? You could construct a texture and call obs_source_draw.
  3. Leave the graphics context.
I'm fairly sure that an obs_source_frame can be constructed in Lua, as SWIG (which is used to wrap the OBS C API into Lua) will export structures; see https://www.swig.org/Doc4.0/Lua.html#Lua_structures. Thus a new frame can be made via obslua.obs_source_frame(); then it'd be a matter of filling in the members as the SWIG documentation outlines.
 
Top