I am trying to transcode incoming live RTMP stream to HLS stream using nginx-rtmp-module.
The HLS streaming works fine for few seconds and then it starts throwing the following error:
2020/08/22 00:14:18 [error] 10#10: *3 hls: force fragment split: 10.027 sec, , client: 127.0.0.1, server: 0.0.0.0:1935
This is my nginx configuration file.
daemon off;
error_log /dev/stdout info;
events {
worker_connections 1024;
}
rtmp {
server {
listen ${RTMP_PORT};
chunk_size 4000;
application stream {
live on;
exec ffmpeg -i rtmp://localhost:1935/stream/$name -v verbose
-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 150 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_720p2628kbs;
}
application hls {
live on;
hls on;
hls_fragment_naming sequential;
hls_fragment 5s;
hls_max_fragment 10s;
hls_playlist_length 20s;
hls_path /opt/data/hls;
hls_nested on;
hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
}
}
}
http {
access_log /dev/stdout combined;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server {
listen ${HTTP_PORT};
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /opt/data;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location /live {
alias /opt/data/hls;
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet static/stat.xsl;
}
location /static {
alias /www/static;
}
location = /crossdomain.xml {
root /www/static;
default_type text/xml;
expires 24h;
}
}
}
Can someone please help me with this issue?
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;
}
}
}
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'm getting this error when trying to push m3u8 stream source to my Nginx RTMP server
this my FFmpeg command
ffmpeg -re -i https://xxxxxxxxxxxxxxx.akamaihd.net/hls/live/621275/1539097700001/master_1080p.m3u8 -c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -strict -2 -flags +global_header -bsf:a aac_adtstoasc -bufsize 700k -f flv rtmp://xx.xxx.xx.156/tmp/hls/stream
and this is my Nginx conf file:
#user nobody;
worker_processes 1;
error_log logs/rtmp_error.log debug;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
location /hls {
# Serve HLS fragments
# 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 /tmp;
add_header Cache-Control no-cache;
}
}
}
rtmp {
server {
listen 1935;
chunk_size 8192;
application hls {
live on;
meta copy;
hls on;
hls_path /tmp/hls/stream;
}
}
}
I assume this is a clear indicator of my problem.
If anyone knows, feel free to comment of course.
regards
your firewall's 1935 port is not open.
open port by:
firewall-cmd --permanent --add-service=http # permanently enable HTTP connections on port 80
firewall-cmd --zone=public --add-port=1935/tcp --permanent
firewall-cmd --list-ports # check
firewall-cmd --reload
for the whole flow of building ffmpeg in Centos, see my tutorial at https://github.com/magictomagic/magictomagic.github.io/blob/master/_posts/2020-05-04-CentOS-FFmpeg-%E6%B5%81%E5%AA%92%E4%BD%93%E6%92%AD%E6%94%BE.md
the environment is CentOS 8.
I tring to restream webcams using nginx+rtmp module on Debian machine. When i restream one cam it's works nice and smooth, but its take so much CPU:
Here is my config:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
}
rtmp_auto_push on;
rtmp {
live on;
hls on;
hls_fragment 5s;
respawn_timeout 15s;
chunk_size 8192;
server {
listen 1935;
application cam1 {
hls_path /tmp/cam1;
}
exec_static /usr/bin/ffmpeg -i http://cam-ip:8080/flv?login=user&channelid=channalid&password=pass&count=0
-acodec copy -vcodec libx264 -vprofile baseline -f flv rtmp://server-ip/cam1/stream;
}
}
http {
server {
listen 8080;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location stat.xsl {
root /stat;
}
location / {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp/;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
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;
}
}
}
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_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
}
After i add 12 webcams in config and i got terrible lags when look at cam. And 100% CPU usage:
Why i have so much ffmpeg processes in htop?
And why it's take so much CPU?