so I've configured my nginx server on azure to the point that i can in fact connect to it and stream but there is one issue i don't have the .m3u3 file in my hls directory, I'm streaming to this server via obs here is my nginx config
I found some old thread with this error but i've added user root; to file and still nothing
anyone know why it's not working
user root;
worker_processes auto; events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935 ; # Listen on standard RTMP port
chunk_size 4000;
application show {
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
}
}
}
http {
sendfile off;
tcp_nopush on;
# aio on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /nginx/;
}
}
}
this is my nginx.conf using Ubuntu 18.04../usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
application live {
live on;
interleave on;
record off;
hls on;
hls_path /mnt/hls;
hls_fragment 6s;
hls_playlist_length 60s;
deny play all;
dash on;
dash_path /mnt/dash;
dash_fragment 3s;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location / {
add_header 'Cache-Control' 'no-cache';
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
text/html html;
application/dash+xml mpd;
}
root /mnt/;
}
}
}
OBS Stream setting :
server add : rtmp://[ip-addr]/live
stream key : stream
i've tried live stream using android (larix broadcaster app), with this connection setting,
server add : rtmp//{ip-addr]:1935/live/stream
stram key : stream
and at my website, i've added playerjs.js and use this inside index.html
<section class="wrapper style1">
<div class="inner">
<div class="video">
<div class="video-wrapper">
<iframe width="100%" height="100%" src="playerjs.html?file=http://[ip-addr]:8080/hls/stream.m3u8" type="text/html" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
</section>
i'm running my server with apache2 on port:80, php, mySql..while Nginx on port:8080 to serve livestream HLS
.m3u8 will generated automaticly inside /mnt/hls
Application name define inside rtmp ..>> application live (i named it "live"), you may named it you like..while stream key, you define by yourself via streamer (OBS, Larix etc...) >> rtmp:/{ip-addr]:1935/live/stream ( i named "stream"). nginx will pull that stream name and put inside mnt/hls/ and create .m3u8 file, devide clips into 60s playlist, and load every clips by 6s fragment..
thats why i like nginx :) and still going smooth .. hope this would help
Related
I'm using nginx-rtmp module to capture RTMP streams from my cameras and transmit them to further systems.
Generally my setup is working fine and generating .m3u8 files properly. For example:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:23
#EXT-X-TARGETDURATION:50
#EXT-X-DISCONTINUITY
#EXTINF:49.957,
verification-23.ts
But the fragments that are generated are always 50s as you can see on the above example.
This is causing more than 50s delay in playback that I would like to avoid.
I tried to decrease Nginx parameters to, for example 3s for fragment and 15s for playlist:
hls_fragment 3s;
hls_playlist_length 15s;
but it didn't work. .m3u8 files were still generated with #EXTINF:49.957.
Is it possible to decrease the delay with Nginx configuration? Or it might be some kind of additional configuration on the cameras?
My current nginx.conf file:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
rtmp {
server {
listen 1935;
chunk_size 2000;
application live {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 50s;
hls_playlist_length 60s;
deny play all;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
server_name stream.mydomain.pl;
location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
}
# Certbot configuration
# ...
}
I would like to show a RTSP stream in a Web application. I successfully streamed using HLS with the following configuration:
RTSP to RTMP:
ffmpeg -stream_loop -1 -re -i "C:\RA\test.m3u8" -acodec aac -vcodec libx264 -f flv rtmp:localhost/live/stream
Nginx (1.7 on windows) configuration
# RTMP configuration
rtmp {
server {
listen 1935;
application live {
live on;
interleave on;
hls on;
hls_path C:\RA\NGINX\hls;
hls_fragment 15s;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 81;
location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root C:\RA\NGINX;
}
}
}
I cannot find the documentation or examples related to the WebRTC configuration for NGINX
I tried with the socket connection but I don't know how to defined my input stream or what would be the URL to test this...
# RTMP configuration
rtmp {
server {
listen 1935;
application live {
live on;
}
}
}
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server localhost:8010;
}
server {
listen 8020;
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
}
}
I have a nginx-rtmp server for real time hls streaming with three rtmp stream running. Right now all the hls are streaming are at 3-4mbps, is there any i can restrict the outbound data transfer rate to 1-2mpbs using directives in nginx.
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
notify_method get;
live on;
hls on;
hls_path /nginx/hls/;
hls_fragment 3;
hls_playlist_length 60;
drop_idle_publisher 10s;
meta copy;
hls_variant _low BANDWIDTH=166000;
hls_variant _mid BANDWIDTH=244000;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location / {
add_header 'Cache-Control' 'no-cache';
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /nginx/hls/;
#root /nginx/;
}
}
}
Thanks in advance
I have a ingest nginx-rtmp server which act as a single source of rtmp streams for worker nodes.
Ingest instance gets the rtmp through OBS. Now when client request a video through load balancer like https://load-balancer.com/hls/test.m3u8
Load balancer sends this request to one of the worker nodes.
The worker nodes has following nginx config file.
worker_processes auto;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
# Define the Application
application show {
live on;
pull rtmp://localhost:1935/stream/ live=1;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
}
}
}
http {
sendfile off;
tcp_nopush on;
aio on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
}
}
}
The nginx-rtmp pull of this worker node will not work until anyone request for it. Hence it will not generate the hls file for the http request.
Note: I can not push the stream to the worker nodes as the worker noders are being auto scalled and does not have a fix number.
I wasn to know a solution by which, Whenever a client request a video which and the worker node gets the https request, Some how the rtmp server application show gets a hit and pull the video from the ingest server and generates the hls block and the http request can be fulfilled.
I have had no issues in live-streaming to the server, but I am trying to add VOD functionality with some difficulty. The record_path "/mnt/film/" is not being created or written to by the server, even if I create the directory before running the server.
I have tried adding a user with root permissions, but this did not seem to help. The weird thing is that error logs are not being created as well, but it writes to the "/mnt/hls" path with no problems whatsoever.
user nginx root;
worker_processes auto;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# record stream to folder /film/
record all;
record_path /mnt/film/;
# disable consuming the stream from nginx as rtmp
deny play all;
}
}
}
http {
sendfile off;
tcp_nopush on;
default_type application/octet-stream;
server {
listen 8080;
location /hls {
# Disable cache
add_header 'Cache-Control' 'no-cache';
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
}
}
server {
listen 8384;
# vod caches
vod_metadata_cache metadata_cache 256m;
vod_response_cache response_cache 128m;
# vod settings
vod_mode local;
vod_segment_duration 2000; # 2s
vod_align_segments_to_key_frames on;
#file handle caching / aio
open_file_cache max=1000 inactive=5m;
open_file_cache_valid 2m;
open_file_cache_min_uses 1;
open_file_cache_errors on;
aio on;
location /vod/ {
alias mnt/film/;
vod hls;
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Expose-Headers' 'Server,range,Content-Length,Content-Range';
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, OPTIONS';
add_header 'Access-Control-Allow-Origin' '*';
expires 100d;
}
}
}
I am just trying to get some files to show up in the "record_path" directory defined in the nginx.conf above.
Thanks
Have you checked hls_cleanup directive ? By default the feature is on. In this mode nginx cache manager process removes old HLS fragments and playlists from HLS directory.
https://github.com/arut/nginx-rtmp-module/wiki/Directives#hls_cleanup