tiangolo / nginx-rtmp-docker

Docker image with Nginx using the nginx-rtmp-module module for live multimedia (video) streaming.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Executing command from directive

yentheo opened this issue · comments

I want to start off with thanking you for creating this image. It was very helpful to me already.


Creating Context (optional)

Now firstly I want to sketch my use case/setup: I have a container based on the tiangolo/nginx-rtmp-docker image running on my computer (inside of Docker of course). My mobile phone streams with an app (ManyCam) to my computer. On that same computer I also have OBS running with a Media Component that plays the stream from the Docker container. This all works.

The problem that I was having was that I was streaming from my phone via my data connection and my reception was bad at some point. At that point the stream began to stutter and the video feed froze after a while but the audio just continued to work. I stopped the stream-app (ManyCam) on the phone and restarted streaming but the Media Component stayed frozen inside of OBS. To be fair, I assume this is a problem with the Media Component in OBS. But I wanted to implement the following solution to fix this problem and support more use cases that I want.

So I wanted to see if I could subscribe to certain events on the rtmp server (the tiangolo/nginx-rtmp-docker container) on my computer so I could see when a connection drops and perhaps show something else (like a "Not streaming"-image) inside of OBS.


The problem

I found that I could change the default image you supply with a custom nginx config and add some directives to it like the exec_publish and exec_push directives. I want to communicate these events to outside of my rtmp container and I thought to do this by just executing a script on one of these events that creates a connection to a webserver running locally on my computer (not in Docker atm but we could evolve to that).

First I tried to run a node webserver inside of the rtmp container by just adding this as directive:

exec_push node /data/server.js or exec_publish node /data/server.js

I have installed node inside of the image and when I attach to the shell of the container and run node /data/server.js I can access the node web server from outside of the container (I also expanded the nginx config to proxy traffic to the web server otherwise this wouldn't work of course).

But when I publish from my mobile phone to the rtmp server, the node server isn't starting up. When I create a file in that same node script, the file is created so I know the script runs.

When this was not working, I tried a python script that makes a SignalR (websocket) connection to the web server running on my computer. Same here, the connection isn't made when I publish to the rtmp server, but when I add a piece of code that creates a file inside of the python script, I see the file is created when I stream to the rtmp server, so the script is run but I can't for the life of me figure out why the connection isn't made. Are there some constraints to the process executed by the directives?

Is there some way to see logging for this, output from the commands executed by the directives, ...?

@yentheo This doesn't help with the specific issue, but perhaps https://github.com/715209/nginx-obs-automatic-low-bitrate-switching is more what you're looking for. It's meant to do exactly the use-case you describe.

In my case nothing executes, even exec_push touch /tmp/test;