Skip to content

Question/FR about stream key #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
drajvver opened this issue Apr 8, 2025 · 2 comments
Open

Question/FR about stream key #81

drajvver opened this issue Apr 8, 2025 · 2 comments
Labels
question Further information is requested

Comments

@drajvver
Copy link

drajvver commented Apr 8, 2025

Hello!

First of all, congratulations on amazing library, it's the best one I've used for RTMP anc C# integration.

I have hit a roadblock though and wanted to ask if that's even possible. I'm using the OutputPathResolver from docs and it's not really working with my setup and I would like to understand why (and maybe how to fix this).

My RTMP endpoint is rtmp://127.0.0.1/ingest so pretty standard. The "Stream Key" as OBS calls it is more complicated though and looks like this: ?key=<guid>&vid=<guid>&lid=123.

When using this Stream Key, the recording with FFMpeg does not work, as it tries to connect to rtmp://localhost:1935/ingest?code=34534D62596330306764436D34317063675733785A5A4D34506269494F644E77664D357A65697930494645377A50506C57345936314A42454F77586B4F465251, which is missing the whole Stream Key part.
I know I can utilize the IInputPathResolver interface to achieve what I want, but I think it would be good to have it working out of the box.

Thanks!

@josephnhtam
Copy link
Owner

josephnhtam commented Apr 8, 2025

Hi @drajvver

RTMP URI has the format: rtmp://hostname/<app-name>/<stream-name> and this library parses RTMP URI rtmp://127.0.0.1/ingest?key=<guid>&vid=<guid>&lid=123 into the following components:

  • App name: ingest
  • Stream name: (empty)
  • Stream path: /<app-name>/<stream-name> = /ingest
  • Stream arguments:
    {
      key: <guid>,
      vid: <guid>,
      lid: 123
    }
    

The RTMP protocol provides the <app-name> during connection handshake and delivers the <stream-name> with the subsequent Publish command.

Each stream is uniquely identified by its stream path, and the stream arguments can be utilized for authorization purposes with IAuthorizationHandler.

The spawned FFmpeg process connects to the stream using the URI rtmp://localhost:1935/ingest?code=<code> by default, because the <code> is a generated authorization token for bypassing custom authorization with IAuthorizationHandler.

So, it is recommended to use a RTMP URI like rtmp://127.0.0.1/ingest/<key-guid>?vid=<guid>&lid=123 instead or you can try to implement the IAuthorizationHandler and provide the StreamPathOverride in the AuthorizationResult.

rtmp://127.0.0.1/ingest/<key-guid>?vid=<guid>&lid=123 is more recommended, because it is found that VLC player may treat ingest?key=<guid>&vid=<guid>&lid=123 as the app name unless the URI is ingest/?key=<guid>&vid=<guid>&lid=123

Example code:

private class AuthorizationHandler : IAuthorizationHandler
{
    public Task<AuthorizationResult> AuthorizePublishingAsync(ISessionInfo client, string streamPath, IReadOnlyDictionary<string, string> streamArguments, string publishingType)
    {
        return HandleAuthorizationAsync(streamPath, streamArguments);
    }

    public Task<AuthorizationResult> AuthorizeSubscribingAsync(ISessionInfo client, string streamPath, IReadOnlyDictionary<string, string> streamArguments)
    {
        return HandleAuthorizationAsync(streamPath, streamArguments);
    }

    private Task<AuthorizationResult> HandleAuthorizationAsync(string streamPath, IReadOnlyDictionary<string, string> streamArguments)
    {
        if (!string.Equals(streamPath, "/ingest", StringComparison.OrdinalIgnoreCase))
        {
            return Task.FromResult(AuthorizationResult.Unauthorized("Invalid stream path"));
        }

        if (!streamArguments.TryGetValue("key", out var key))
        {
            return Task.FromResult(AuthorizationResult.Unauthorized("Missing key parameter"));
        }

        return Task.FromResult(AuthorizationResult.Authorized(streamPathOverride: $"/ingest/{key}"));
    }
}

@josephnhtam josephnhtam added the question Further information is requested label Apr 8, 2025
@drajvver
Copy link
Author

drajvver commented Apr 8, 2025

Ah, didn't know you can "redirect" in the Auth response, that's nice and actually looks like will solve my issue :)

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants