-
Notifications
You must be signed in to change notification settings - Fork 215
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
Add RTMPS relay support #344
base: dev
Are you sure you want to change the base?
Conversation
When the initial push to a target fails in the relay module we can segfault since the relay ctx is NULL. THe segfault occurs in the if which sets up the timer for the push_reconnect method. In this patch we set the context using the existing create local ctx method passing in a NULL target as the target is unused in this method.
@mannyamorim This is great work. When this would be merged into the main repository? |
Thanks @yildizsc. Merging is up to @sergey-dryabzhinsky. |
When the notify module receives a 3xx response to the on_publish callback we will now support sending the stream to an rtmps target and we will support resolving the domain name.
Does it support tiktok? |
@RainNameless I've verified the code against Youtube and Facebook, but it should support any RTMPS target. Please test and let me know if there are any issues with Tiktok. |
@mannyamorim Tiktok and instagram works! Thanks for adding rtmps! |
Telegram doesn't work. Any ideas what is the reason?
relay: SSL certificate does not match "dc4-1.rtmp.t.me/s/1234567890", client: dc4-1.rtmp.t.me/s/1234567890:xxxxxxxxxxxxxxxxx, server: ngx-relay |
@Be1erafon it looks like the SSL name is being calculated incorrectly. This is used for the TLS SNI field and for certificate hostname validation hence the failure to validate. This is happening since there is a colon in the URL that is not denoting a port number. Apparently this is legal, so I will need to tweak the code a bit to handle these cases correctly. I anticipate that I can have a fix available sometime tomorrow. As a stopgap measure you could set: |
Remove the custom logic for computing the SSL name as it is unnessary and replace it with the standard URL parsing logic found in NGINX. Also add one missing #undef directive.
@Be1erafon I've pushed a commit which should fix the issue you were experiencing. Please test again and let me know the results. |
@mannyamorim Connection is working. Doesn't work
Works via ffmpeg
Looks like Telegram has changed something. Worked with nginx a few days ago. |
@Be1erafon thanks for letting me know. I'll try to work out what the difference is between the NGINX module and the FFMPEG implementation. Will post back once I have a better understanding of this problem. |
this is really cool. could you give me a quick guide on how to install nginx with your version of nginx-rtmp module? I tried downloading your repo ssl branch
and then following nginx guide https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#sources and then do
but when I run nginx with your configuration I get
any ideas? |
You should build dynamic module:
|
@Rosstarz you can read a bit about dynamic modules in NGINX here: https://www.nginx.com/resources/wiki/extending/converting/. You can use the commands that @sergey-dryabzhinsky posted to build as a dynamic module. If you would like to use it as a static module instead (the way you were originally trying), you will just need to remove the line at the top of the sample config file |
Hi @mannyamorim, Thanks again for this great afford. This setup is actually working for AWS IVS. But I need to make Here is my configuration:
And here is the code which proceses self-signed SSL: mkdir /certs && cd /certs && openssl req \
-newkey rsa:2048 -nodes -keyout domain.key -subj "/C=FR/O=krkr/OU=Domain Control Validated/CN=*.domain.com" \
-x509 -days 365 -out domain.crt Do I need an authoritative SSL? |
@yildizsc from Nginx's point of view there is no difference between authoritative SSL and self-signed certificates. Both should work just fine. In this case, I believe you need to create a CA certificate (self-signed of course) first and then use it to sign a client certificate for your application. The CA certificate would then be what you pass into the If you're still having trouble, please post the error logs that you get. If nothing descriptive, please add the |
This is what I get with debug mode. Btw, could you elaborate on creating the certificate first? Does it matter? I could get the point. |
@yildizsc please ignore my earlier comments about needing to have a CA certificate. It appears that this is not necessary. The error message "unable to get local issuer certificate" didn't turn up anything terribly useful. It just seems to be a generic message that the openssl library can't load your certificate. I just ran a quick test with a single self signed certificate and it seems to be working fine. If you try out this setup, hopefully you can work towards your setup and see where the difference is that's causing the issue. Also, could you post your full Nginx config file (with anything sensitive removed/replace with dummy values), hopefully that can help to shed some more light on the problem. Test setup was Nginx relaying to an Stunnel instance with a self signed certificate with certificate generated with the following command:
Stunnel conf:
Nginx conf:
Please note that the CN (Common Name) of the certificate needs to match the name used in the |
Hi @mannyamorim, if any success with this? Faced the same issue with telegram... |
Hi @kuznetcoff777, sorry for the delay. I haven't been able to figure out this mystery yet. I ran a test with the NGINX stream module to see if it is an issue with the SSL code in this PR. I used the following configuration:
Essentially there is a single push command that pushes to a local endpoint which is then proxied to the SSL destination at Telegram using the NGINX SSL stream module. This failed with the same symptoms as with this PR. The debug error log shows that the RTMP session is operating normally but nothing is displayed in Telegram. This looks to be an issue in the main RTMP module and not with this PR. The guts of the RTMP protocol is really outside of my knowledge, so I don't think that I will be able to debug further. I have logged this issue as #350. At this point I don't consider it an issue with this PR and likely won't be looking into it any further. Please let me know if you have a different opinion or further information. |
I see that you have added a dockerfile in your fork. Could you provide a basic tutorial of how to run it? |
@bertin0 the Dockerfile that I have added to my fork is on a different branch, and I am not planning on submitting a PR for it, so not really relevant here. That being said, the usage is very simple. Basically, the container is just a standard nginx docker container plus the rtmp module added as a dynamic module. You can refer to the documentation for the nginx docker container here: https://hub.docker.com/_/nginx. I would recommend just mounting the config file directly. For the configuration file, you can refer to the documentation in the PR. |
@mannyamorim Can you pass the stream key dynamically? |
@haerong22 I am assuming that you want to relay an RTMP stream to an RTMPS target with a dynamic stream key. This is possible using the notify module and the Essentially what happens here is that you can configure the module to execute a callback to a certain URL. If that URL returns a redirect then the returned URL with the stream key appended to it, is used as the target for the rtmp relay. If you take a look at the sample configuration for the PR. The application |
@mannyamorim omg! so fast... thanks. but i can't understand ... i want OBS -> NGINX -> YOUTUBE i want like this
|
@haerong22 Sorry, that configuration is not directly supported by this module, however with a bit more work you could build something like this. When you use the This is just an idea, not something tested or supported by me, so you will need to experiment a bit. |
May need a different pull request but while you're at it with port 443 and rtmps, why not allow https on notify (like on_publish, on_play, on_publish_done, etc.)? |
@spjoes it is not trivial to add https support, rather it would require a fair amount of new code and testing. At this point I have no plans to add any such support to my fork. I understand that it would be more convenient, however you can simply have Nginx function as an RP for any https endpoints that you need to call out to, so this limitation shouldn't really impact the functionality of the module. |
I was actually never able to get a RP working. Tried for a few hours and figured it'd be a better, cleaner, and (at the time) a quicker fix to just have https as a feature. I'll continue to try with proxy_pass and such but just native https support would be a great feature |
@mannyamorim Impressive work you've done. I've been building a streaming app. I have configured the rtmp module with nginx on Fedora 40. Streams are being pushed from https://blueirissoftware.com/ to my server at rtmp://ip-address/hls/dynamic-keys for testing which works fine. Now I want to implement RTMPS and want to get the streams by giving rtmps://ip-address/hls/dynamic-keys to the third party softwares. But I'm not able to setup rtmps with nginx configuration. When I try to implement ssl within RTMP block. It gives [ssl parameter not found](nginx: [emerg] the invalid "ssl" parameter in). rtmp {
} |
@jazib93 the functionality that you're looking for is not present in this PR. I did eventually built it though and it's available from my fork: https://github.com/mannyamorim/nginx-rtmp-module however, I'm not planning on submitting it for inclusion here unless there is some progress made on reviewing/merging this first PR. I should also give the disclaimer that as the code is not submitted for inclusion there is no formal documentation and I may or may not be able to support it in the future. That being said the usage is straightforward. You can refer to this file: https://github.com/mannyamorim/nginx-rtmp-module/blob/master/ngx_rtmp_ssl_module.c for the list of supported directives. At a basic level the following could be used as a starting point for the config:
|
@mannyamorim Okay I have re-complied nginx with your Repo and did the above configuration but I'm not able to push my stream to my server on 'rtmps://' using ffmpeg and neither with OBS. I'm getting the error below Stream #0:1: Audio: pcm_f32le, 44100 Hz, mono, flt, 1411 kb/s I'm trying to understand how will the RTMP module will know that its accepting rtmps protocol as well. Your input will be highly appreciated. Thanks |
@jazib93 This sounds like a configuration issue. Please share your Nginx configuration as well as the commands used to invoked ffmpeg or the config used for OBS so that I can try and see what may need to be changed. |
@mannyamorim here is my configuration and the FFMPEG command
This is the ffmpeg command that I ran from my mac: When I use "rtmp://" with the same command, it works fine. |
@jazib93 You will need to set the port in your ffmpeg command to the one that is specified in Nginx:
Alternatively you could change the Nginx config to listen on the default port 443 by doing |
@mannyamorim Thank you so much, it worked by mentioning the port along with the IP address. I cannot use port 443 for nginx as its in use with apache for other apps. |
This is an attempt to add support for the relay module to directly connect to RTMPS targets. This is valuable for security and is required for certain streaming services (Facebook). Please test if you can, feedback is welcome 👍
Notes
Sample Configuration
I provide a sample configuration file below to demonstrate some of the possible options. The purpose of this config is a multi streaming server with one application that will push to YouTube and Facebook live. You will need to replace the
xxxx
with your streaming key.cc: #165 arut#1619 arut#747 arut#1605 arut#1408 arut#1587 arut#1604 arut#1397 arut#457 arut#232 arut#191 arut#68