ajayalag1974
Member
Hi,
I have written my web server code which when user visits the streaming page checks if streaming exist by name via "/rest-api/stream/find", if not it publishes rtmp stream using ffmpeg command, command is executed via child_process spawn method in nodejs (ffmpeg -re -i "https://somedomain.com/somestream.m3u8" -preset ultrafast -acodec aac -vcodec h264 -f flv "rtmp://localhost:1935/live/test").
Now the issue is - once stream is published via ffmpeg and there are no active viewers of such stream, above ffmpeg command/process is still running and publishing the stream to flashphoner rtmp server and accordingly using resources.
I would ideally want it to be stopped/terminated if no active viewers of such stream, probably it could be achieved in 2 ways:
1. Implement some inactive timeout kind of thing either via flashphoner or ffmpeg command, if either supports this, which stops that rtmp being published & associated ffmpeg process after inactivity.
2. Periodically iterate & check all the streams & total count of its viewers (which is available in prometheus data - /?action=stat&format=prometheus, any other json like endpoint for this data ?) and if no viewers of stream than terminate the stream via "/rest-api/stream/terminate".
How should i go about achieving this ?
I have written my web server code which when user visits the streaming page checks if streaming exist by name via "/rest-api/stream/find", if not it publishes rtmp stream using ffmpeg command, command is executed via child_process spawn method in nodejs (ffmpeg -re -i "https://somedomain.com/somestream.m3u8" -preset ultrafast -acodec aac -vcodec h264 -f flv "rtmp://localhost:1935/live/test").
Now the issue is - once stream is published via ffmpeg and there are no active viewers of such stream, above ffmpeg command/process is still running and publishing the stream to flashphoner rtmp server and accordingly using resources.
I would ideally want it to be stopped/terminated if no active viewers of such stream, probably it could be achieved in 2 ways:
1. Implement some inactive timeout kind of thing either via flashphoner or ffmpeg command, if either supports this, which stops that rtmp being published & associated ffmpeg process after inactivity.
2. Periodically iterate & check all the streams & total count of its viewers (which is available in prometheus data - /?action=stat&format=prometheus, any other json like endpoint for this data ?) and if no viewers of stream than terminate the stream via "/rest-api/stream/terminate".
How should i go about achieving this ?
Last edited: