如何启动和停止使用NGINX RTMP和DJANGO的流
我是NGINX和RTMP模块的绝对初学者。我正在研究一个涉及实时流应用程序的项目。我想将此NGINX RTMP服务器链接到我的Django服务器,该服务器在端口8000上运行。这是通过多个教程后我编制的nginx.conf文件。从教程遵循教程中,我了解的是,应用程序是RTMP中的端点,因此我将URL放在旁边,我也知道HLS视频将存储在我沿push/hls_path提供的文件夹路径中。我现在有疑问,我是否需要为开始流和停止流定义两个应用程序(如它所做的那样),否则它们可以将它们一起粘贴到一个应用程序中。 请澄清我的疑问并纠正我。
Nginx configuration for RTMP upstream and HLS downstream
worker_processes auto;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application rtmp://localhost/api/livevideostreams/startstream {
# Live status
live on;
# Turn on HLS
hls on;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
# Push the stream to the local HLS application
push rtmp://localhost:1935/api/livevideostreams/hls_live/;
}
application rtmp://localhost:1935/api/livevideostreams/stopstream {
# Live status
live off;
# Turn on HLS
hls on;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
# Push the stream to the local HLS application
push rtmp://localhost:1935/api/livevideostreams/hls_live/;
}
}
}
application hls {
live on;
# Only accept publishing from localhost.
# (the `app` RTMP ingest application)
allow publish 127.0.0.1;
deny publish all;
deny play all;
# Package streams as HLS
hls on;
hls_path rtmp://localhost:1935/api/livevideostreams/hls_live/;
hls_nested on;
hls_fragment_naming system;
hls_datetime system;
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location http://localhost:1935/api/livevideostreams/hls_live/; {
# 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/;
}
}
}
I am an absolute beginner with NGINX and RTMP module. I am working on a project which involves a live streaming app. I want to link this Nginx rtmp server to my django server which runs on port 8000. This is what I made up my nginx.conf file after going through multiple tutorials. What I understood from following the tutorials is that application is endpoint in rtmp so i put the url next to it, also I understand that hls video will be stored in the folder path that I provide along push/hls_path. I have a doubts now, do I need to define two applications(as it done) for start stream and stop stream or they can be clubbed together into one application.
Please clarify my doubts and correct me.
Nginx configuration for RTMP upstream and HLS downstream
worker_processes auto;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application rtmp://localhost/api/livevideostreams/startstream {
# Live status
live on;
# Turn on HLS
hls on;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
# Push the stream to the local HLS application
push rtmp://localhost:1935/api/livevideostreams/hls_live/;
}
application rtmp://localhost:1935/api/livevideostreams/stopstream {
# Live status
live off;
# Turn on HLS
hls on;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
# Push the stream to the local HLS application
push rtmp://localhost:1935/api/livevideostreams/hls_live/;
}
}
}
application hls {
live on;
# Only accept publishing from localhost.
# (the `app` RTMP ingest application)
allow publish 127.0.0.1;
deny publish all;
deny play all;
# Package streams as HLS
hls on;
hls_path rtmp://localhost:1935/api/livevideostreams/hls_live/;
hls_nested on;
hls_fragment_naming system;
hls_datetime system;
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location http://localhost:1935/api/livevideostreams/hls_live/; {
# 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/;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论