Reputation: 59
I've installed nginx with RTMP module on my linux server where I want it to receive a RTMP stream from Open Broadcaster Software, convert it to HLS and play it on my private website with some HTML5 player. Receiving the stream trough RTMP works, but the HLS stream doesn't seem to work. My current config is like so:
worker_processes 1;
events {
worker_connections 1024;
}
http {
#include mime.types;
#default_type application/octet-stream;
sendfile off;
#keepalive_timeout 65;
server {
listen 8080;
#server_name localhost;
#location / {
# root html;
# index index.html index.htm;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}
#*********************************************************************************************************************************
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
}
root /mnt/;
add_header Cache-Control no-cache;
# To avoid issues with cross-domain HTTP requests (e.g. during development)
#add_header Access-Control-Allow-Origin *;
}
#*********************************************************************************************************************************
}
}
rtmp {
server {
listen 1935;
chunk_size 4096;
application stream {
live on;
#record off;
hls on;
hls_path /mnt/hls;
#hls_fragment 6s;
}
}
}
To recieve the RTMP stream I use rtmp://ip/stream/streamname
which works fine, for receiving HLS I try to use http://ip:8080/hls/streamname.m3u8
which gives me the .m3u8 file if I type it in a browser, but doesn't seem to work on the webpage when I try to play the file in a HTML5 player. I'm testing via these pages: https://videojs.github.io/videojs-contrib-hls/ and https://demo.theoplayer.com/test-hls-mpeg-dash-stream
Can anyone help me understand what I'm doing wrong?
Upvotes: 0
Views: 9171
Reputation: 1
nginx-1.21.1
location /hls/ {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
**root /tmp;** -> **alias /tmp;**
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*';
}
Upvotes: 0
Reputation: 1
Under the line: #hls_fragment 6s; Add the code: deny_play_all;
Apparently you can't play the hls or dash files if the rtmp stream can be played. I don't know why. It just worked for me.
Upvotes: 0
Reputation: 512
It would help if you shared what type of console or network errors you get when testing your HLS stream on those pages.
It might provide some insight for you to troubleshoot. For example, you might be getting Access Control Allow Origin errors by accessing your stream from a different domain. Try uncommenting this line in your nginx.conf and reloading.
#add_header Access-Control-Allow-Origin *;
I also have a reference to "video/mp2t ts;" in my hls location block.
location /hls/ {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*';
}
Cheers. Ian
Upvotes: 1