Nginx rtmp live and save on s3bucket - nginx

I have successfully setup nginx-rmtp-module for live streaming, i have tested it with obs software, it works great !
But i am having trouble to save the video on s3bucket for future use.
This is what i setup:
rtmp {
server {
listen 1935;
chunk_size 4096;
allow publish 127.0.0.1;
deny publish all;
application live {
live on;
record off;
hls on;
hls_path /var/www/html/stream/hls;
hls_fragment 3;
hls_playlist_length 60;
dash on;
dash_path /var/www/html/stream/dash;
}
}
}
and this is http
server {
listen 8088;
location / {
add_header Access-Control-Allow-Origin *;
root /var/www/html/stream;
}
}
types {
application/dash+xml mpd;
}
It works great, no complain at all ! But i am finding a way to push to my s3bucket. i want when a user go live, i want to save that video on s3bucket for future use.
i have google lots but coudlnt find any solution, is it possible?

Related

nginx rtm "server_name" directive is not allowed

My nginx configuring is below:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
hls on;
hls_path /var/www/html/stream/hls;
hls_fragment 3;
hls_playlist_length 60;
}
}
}
Above code was worked well, but when I have bind domain with server_name, then it doesn't work.
rtmp {
server {
listen 1935;
server_name example.com;
chunk_size 4096;
application live {
live on;
record off;
hls on;
hls_path /var/www/html/stream/hls;
hls_fragment 3;
hls_playlist_length 60;
}
}
}
above code is not working, coz, I have added server_name
getting this error:
nginx: [emerg] "server_name" directive is not allowed here in /etc/nginx/nginx.conf:95
nginx: configuration file /etc/nginx/nginx.conf test failed
Any faced same problem before? i googled, I couldn't find any solution for this?
anyone know this? how can I restrict to specific domain

Is it possible to change the source from a pull on NGINX's RTMP module?

I have two applications on my RTMP server:
/live, which receives transmissions from a series of events, and from a series of cameras (/live/{eventId}.{transmissionId}.
/output, which pulls from the corresponding links on /live (so /live/{eventId}.{transmissionId} gets pulled to /output/{eventId}.{transmissionId})
I'd like to be able to select which of the {transmissionId} is being pulled to /output/{eventId}. In other words, in real-time, I would like to change which of the streams of the event is being transmitted in the single output of that event (/output/{eventId}).
Is this possible?
My RTMP configuration file is the following:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record all;
record_suffix .flv;
record_path /home/ubuntu/event_videos;
record_unique off;
wait_video on;
interleave on;
allow play 127.0.0.1;
deny play all;
access_log /var/log/nginx/access_live.log;
}
application output {
live on;
wait_video on;
interleave on;
record off;
allow play all;
pull rtmp://localhost/live/;
access_log /var/log/nginx/access_output.log;
}
application vod {
play /home/ubuntu/event_videos;
}
}
}
Thank you

nginx rtmp conf using argument

i configure server using nginx - rtmp plugin module.
The Problem is rtmp publish.
rtmp plugin module support "on_publish_done" command.
https://github.com/arut/nginx-rtmp-module/wiki/Directives#on_publish_done
and i want like this.
on_publish_done http://MY_SERVER/$APP/$NAME ;
In nginx configure file(nginx.conf) can use $arg_XXX value.
But my conf-file can not observe value. Observe just string "$arg_app", "$arg_name".
How to observe $arg_app, $arg_name ??
this is my conf file.
# HTTP can be used for accessing RTMP stats
http {
access_log /Users/steve/dev/workspace/nginx/logs/access.log;
server {
listen 8080;
location /local_redirect {
rewrite ^.*$ newname? permanent;
}
location /cast {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /Users/steve/dev/workspace/nginx/tmp;
add_header Cache-Control no-cache;
}
}
}
rtmp {
access_log /PATH/nginx/logs/rtmp-access.log;
server {
listen 1935;
chunk_size 4000;
application cast {
live on;
publish_notify on;
hls on;
hls_path /PATH/workspace/nginx/out;
hls_nested on;
hls_fragment 1s;
hls_playlist_length 12s;
}
notify_method get;
on_publish_done http://127.0.0.1:5000/$arg_app/$arg_name ; ##PROBLEM HERE!!
}
}
[the image below shows that a variable with an underscore which is located between character r and b works well! ][1]
for me the code below using bash command with a -c flag works! try it bro
exec_publish_done bash -c "/var/hls/ex.sh ${name}";

Live stream stops when a second viewer joins

I am trying to build a live stream platform using nginx and nginx-http-flv-module (with nginx-rtmp-module).
I have been using nginx-http-flv-module's guide.
I built an nginx server with rtmp and http-flv support.
My nginx.conf file:
#user nobody;
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
...
location /live {
flv_live on; #open flv live streaming (subscribe)
chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response
add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
add_header 'Access-Control-Expose-Headers' 'Content-Length';
}
}
}
rtmp {
server {
listen 1935;
ping 30s;
notify_method get;
application myapp {
live on;
}
}
}
I start publishing my stream using OBS and play the stream in the browser using flv.js like this:
<video id="videoElement" controls autoplay></video>
...
<script>
let videoElement = document.getElementById('videoElement');
let flvPlayer = flvjs.createPlayer({
type: 'flv',
isLive: "true",
url: 'http://192.168.1.122:8080/live?port=1935&app=myapp&stream=test'
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
</script>
And everything works great! The stream is playing in the browser as expected. But the problem is whenever a second viewer starts watching the stream (if I open it in another browser tab f.e). The player stops playing and starts infinite loading. So what can cause this problem?
I am the owner of nginx-http-flv-module, I am sorry that the bug was caused by the commit on July 7, 2019 and it has been fixed already.
You can try the latest code.

Setting up nginx to stream HLS/RTMP simultaneously

I have an nginx web server with the RTMP module running perfectly and pushing out video to several RTMP destinations (Facebook, YouTube, Periscope, etc.).
I now need the stream to output in the HLS protocol so I can build a custom player for it without flash dependency. I've tried following a few other tutorials, but I am struggling.
I have the default config file that came with the installation of nginx with the following added to the end:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
push rtmp://<streaming-service/key>
}
}
}
What exactly do I need to add to this config file to retain my ability to push out video to these RTMP destinations as well as have a HLS feed I can use in a player without Flash?
I already have FFMPEG installed on the machine in order to send video to Periscope. I've seen solutions that do not need FFMPEG, but I just wanted to add that I did have it installed and am somewhat familiar with it.
EDIT: for more information, I am sending video through the server via a Teradek encoder.
I solved this with FFMPEG. The pull directive wasn't working properly. Here's the config file that worked for me:
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name localhost;
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp/;
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*';
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
push rtmp://<location/key>
exec ffmpeg -i rtmp://localhost/live/test -vcodec libx264 -vprofile baseline -x264opts keyint=40 -acodec aac -strict -2 -f flv rtmp://localhost/hls/test;
}
application hls {
live on;
hls on;
hls_path /tmp/hls/;
hls_fragment 6s;
hls_playlist_length 60s;
}
}
}

Resources