【问题标题】:Nginx RTMP Module is not saving live-streaming filesNginx RTMP 模块不保存直播文件
【发布时间】:2019-05-06 01:11:13
【问题描述】:

我在向服务器直播时没有遇到任何问题,但我尝试添加 VOD 功能时遇到了一些困难。记录路径“/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”目录中。

谢谢

【问题讨论】:

    标签: nginx amazon-ec2 rtmp live-streaming


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回复。我设法通过在 nginx 必须访问的每个文件夹上使用 chmod 777 来临时解决这个问题。我知道这是不好的做法,但是当我在尝试创建用户并将其添加到组时,我很难让它授予权限。我确信这是由于缺乏经验。但是,vod 模块似乎不适用于我当前的 nginx.conf 设置,所以我将不得不调查一下。
    猜你喜欢
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    相关资源
    最近更新 更多