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
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 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
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
I explained the problem in this Video Stack Exchange Question as I don't believe this is something code related (e.g. a bug).
It may be a useful information for dev's however, that I did not compile nginx from source. I mention that explicitly, because searching the web, it seems like building from source is the recommended way for nginx/rtmp setups. I could not find a bug report, however, that would explain this behavior.
I feel like I am overseeing something stupid.
For the sake of completeness, I will post the configuration files. Also, dont miss out the live-demo and have fun playing around with the streaming server linked in the other Post ;)
Happy Coding!
nginx.conf:
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Gzip Settings
##
gzip on;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
rtmp {
include /etc/nginx/streams-enabled/*;
}
rtmp server (in streams-enabled/)
server {
listen 1935;
chunk_size 4096;
application live {
live on;
hls on;
hls_path /home/streamer/hls;
hls_nested on;
hls_fragment 3s;
hls_playlist_length 30s;
hls_base_url http://0.0.0.0:3456/hls;
on_publish http://0.0.0.0:3456/auth;
# Recent versions of IE need this for normal playback.
wait_video on; # start audio with video
# force hls
deny play all;
}
}
http-server (in sites-enabled/)
server {
listen 3456;
location /hls {
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 /home/streamer/;
}
}
The problem is with the stream configuration.
vlc -vv http://104.248.36.47:3644/hls/debug/index.m3u8 ouput revealed:
[00007f0594002580] main stream debug: connecting to 0.0.0.0 port 3644 ...
[00007f0594002580] main stream error: connection error: Connection refused
...
[00007f0594002580] adaptive stream debug: Retrieving http://0.0.0.0:3644/hlsdebug/75.ts #0
Note that it says hlsdebug instead of the expected hls/debug
After adding a '/' to the hls_base_url, and changing 0.0.0.0 to the public IP, it works.
I do not understand fully tho why 0.0.0.0 would not work..
The remote type is cached and displays an illegal ip for the new user. It helps wait 3-10 seconds or restart nginx. How to completely turn off caching?
OS: Centos 7
nginx version: nginx/1.10.2
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name test.mydomain.org;
root /etc/nginx/html;
index index.html;
location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Cache-Control' 'no-cache';
default_type text/plain;
return 200 "$remote_addr";
}
# Error page
error_page 404 /404;
}
}
The caching you are seeing is from the browser cache.
Clear the browser cache and try the page after resetting the location conf to include:
# kill cache
add_header Last-Modified $date_gmt;
add_header Cache-Control 'private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
This makes absolutely sure the browser or any intermediate proxy will not cache the output sent.
use this configuration in nginx conf file
location /path-to-files/ {
directio 0;
}
which will bypass OS level cache.