iamscottxu / obs-rtspserver

RTSP server plugin for obs-studio
https://obsproject.com/forum/resources/obs-rtspserver.1037/
GNU General Public License v2.0
441 stars 55 forks source link

Programmatically starting obs-rtspserver #23

Closed AWilco closed 3 years ago

AWilco commented 3 years ago

Hi iamscottxu,

I am working to combine OBS-RTSPServer with OBS-Websocket, to remotely start and stop the RTSP server.

RTSP server is installed and working, I can start and stop it using the Tools Menu dialog box. I have not enabled the autostart option.

OBS-Websocket has command build in to start and stop outputs. This calls obs_output_start(). If I try and run this after starting OBS, the command fails with can't begin data capture

Looking into your code, before you call obs_output_start() you call:

rtspOutputHelper->UpdateEncoder();

I'm currently assuming that this isn't called when the websocket plugin tries to start the RTSP output and this is what is causing it to fail. Is there are reason this is not called either in rtsp_output_create or rtsp_output_start? I assume if it was called in one of these functions it would be created if the output was programmatically created by the websocket.

My alternative option is I'm going to edit rtsp_output_auto_start to always update the encoders even if it does not automatically start streaming. Hopefully this will mean they are available when the websocket starts

void rtsp_output_auto_start(RtspOutputHelper *rtspOutputHelper)
{
    auto *config = rtsp_properties_open_config();
    auto autoStart = false;

    rtspOutputHelper->UpdateEncoder();

    if (config) {
        autoStart =
            config_get_bool(config, CONFIG_SECTIION, "AutoStart");
        config_close(config);
    }
    if (!autoStart)
        return;
    rtspOutputHelper->Start();
}

I'm not necessarily asking you to make a change to accomodate this. If there are drawbacks to either of the options I'm going to try then I'll look to just make it work for my use case. Just wanted to make you aware of my use case and see if you had any advice on the best way to make the change.

Thanks.

iamscottxu commented 3 years ago

First of all, thank you for asking this question.

To start an OBS output successfully, its encoder must be configured correctly. The current version configures the encoder when the output is started, so if you want to start the output programmatically, you must refer to the code in rtspOutputHelper for initialization.

As for use with OBS-websocket, I'm still studying it. I will also consider solving this problem in a later version.

iamscottxu commented 3 years ago

https://github.com/iamscottxu/obs-rtspserver/releases/tag/v1.4.0-rc1