Как запустить и остановить поток, в котором используются 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/;
}
}
}
Вернуться на верх