Issues detecting stream start in LUA

Wuzi

New Member
I am trying to detect when OBS starts streaming in a LUA script. I've used a similar approach for recording and there it seems to work reliably.
This is the code I am using:
Lua:
obs = obslua

function streaming_start(calldata)
   print("streaming_start called")
end

function script_load(settings)
    streaming_output = obs.obs_frontend_get_streaming_output()
    streaming_ouput_handler = obs.obs_output_get_signal_handler(streaming_output)
    obs.signal_handler_connect(streaming_ouput_handler, 'start', streaming_start)  
end
The issue is, it only works if I load/reload the script in OBS after having streamed. If the current instance of OBS hasn't streamed before loading the script, streaming_output is nil and streaming_start never gets called.
Am I using a wrong approach to detecting when OBS starts streaming, or is there something else going on?

Any help is greatly appreciated!
 
You might try using obs_frontend_add_event_callback instead of a signal handler. Process the event OBS_FRONTEND_EVENT_STREAMING_STARTED
 

Wuzi

New Member
You might try using obs_frontend_add_event_callback instead of a signal handler. Process the event OBS_FRONTEND_EVENT_STREAMING_STARTED
That works, thanks.
Still a bit curious why my approach isn't working, but that's not too important.
 
Top