Nginx RTMP模块未保存实时流文件

时间:2019-05-06 01:11:13

标签: nginx amazon-ec2 rtmp live-streaming

我在向服务器进行实时流传输时没有任何问题,但是我试图添加VOD功能有些困难。即使我在运行服务器之前创建目录,服务器也不会创建或写入record_path“ / mnt / film/"。

我尝试添加具有root权限的用户,但这似乎无济于事。奇怪的是,错误日志也没有被创建,但是它写入“ / mnt / hls”路径却没有任何问题。

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;
        }
    }
}

我只是想让一些文件显示在上面nginx.conf中定义的“ record_path”目录中。

谢谢

1 个答案:

答案 0 :(得分:0)

您是否检查了hls_cleanup指令?默认情况下,该功能处于启用状态。在这种模式下,nginx缓存管理器进程将从HLS目录中删除旧的HLS片段和播放列表。

https://github.com/arut/nginx-rtmp-module/wiki/Directives#hls_cleanup