TheAstropath
New Member
Hey all,
I'm working on what I had thought would be a simple script in Python for OBS Studio, and am now repeatedly hitting dead ends. Here's what I'm trying to accomplish:
When you start streaming or recording, make a call to a URL to turn on a physical light switch
When you stop streaming or recording, make another call to a different URL to turn off that light switch.
I got all the configuration options set up so the URLs can be defined in the Scripts menu, with buttons to test the URLs (And it does, in fact, turn the light on and off). So far so good.
The first step to proceeding is obviously to get some sort of callback setup to execute my code when the stream (or recording) starts or stops. In the API, there are "obs_frontend_event"s defined that looked great:
-OBS_FRONTEND_EVENT_STREAMING_STARTED
-OBS_FRONTEND_EVENT_STREAMING_STOPPED
-OBS_FRONTEND_EVENT_RECORDING_STARTED
-OBS_FRONTEND_EVENT_RECORDING_STOPPED
I would just need to register a callback using obs_frontend_add_event_callback... Except there isn't a binding for that API call in obspython. OK, next option then.
I saw there was an actual way to get to the signal handler for an output and receive start/stop events for individual outputs (obs_output_get_signal_handler and signal_handler_connect). I got that all rigged up, and everything seemed to be working great - lights went on when I started streaming/recording, lights went off when I stopped. That is, until I switched to a different profile in OBS. At that point, my callbacks weren't getting called. I assume when you switch profiles, the outputs get destroyed and new ones created with the new profile settings.
OK then, I just need to know when you switch profiles so that I can re-register my callbacks, that shouldn't be too bad. Except it looks like the only way to get a notification of a profile change is through the frontend events, which I already discovered couldn't be done in Python.
I even went so far as to try just removing and re-adding the callbacks every 5 seconds using the timer callbacks. For some reason though, despite using signal_handler_disconnect before doing another signal_handler_connect, I was still getting more and more callbacks per start/stop the longer I waited (as though the signal_handler_disconnect wasn't actually removing the callback?).
Is my only option here really to just periodically poll obs_frontend_streaming_active and obs_frontend_recording_active to see if OBS is alive? Is there any particular reason I can't register for frontend events?
I'm working on what I had thought would be a simple script in Python for OBS Studio, and am now repeatedly hitting dead ends. Here's what I'm trying to accomplish:
When you start streaming or recording, make a call to a URL to turn on a physical light switch
When you stop streaming or recording, make another call to a different URL to turn off that light switch.
I got all the configuration options set up so the URLs can be defined in the Scripts menu, with buttons to test the URLs (And it does, in fact, turn the light on and off). So far so good.
The first step to proceeding is obviously to get some sort of callback setup to execute my code when the stream (or recording) starts or stops. In the API, there are "obs_frontend_event"s defined that looked great:
-OBS_FRONTEND_EVENT_STREAMING_STARTED
-OBS_FRONTEND_EVENT_STREAMING_STOPPED
-OBS_FRONTEND_EVENT_RECORDING_STARTED
-OBS_FRONTEND_EVENT_RECORDING_STOPPED
I would just need to register a callback using obs_frontend_add_event_callback... Except there isn't a binding for that API call in obspython. OK, next option then.
I saw there was an actual way to get to the signal handler for an output and receive start/stop events for individual outputs (obs_output_get_signal_handler and signal_handler_connect). I got that all rigged up, and everything seemed to be working great - lights went on when I started streaming/recording, lights went off when I stopped. That is, until I switched to a different profile in OBS. At that point, my callbacks weren't getting called. I assume when you switch profiles, the outputs get destroyed and new ones created with the new profile settings.
OK then, I just need to know when you switch profiles so that I can re-register my callbacks, that shouldn't be too bad. Except it looks like the only way to get a notification of a profile change is through the frontend events, which I already discovered couldn't be done in Python.
I even went so far as to try just removing and re-adding the callbacks every 5 seconds using the timer callbacks. For some reason though, despite using signal_handler_disconnect before doing another signal_handler_connect, I was still getting more and more callbacks per start/stop the longer I waited (as though the signal_handler_disconnect wasn't actually removing the callback?).
Is my only option here really to just periodically poll obs_frontend_streaming_active and obs_frontend_recording_active to see if OBS is alive? Is there any particular reason I can't register for frontend events?