nginx rtmp模块无法流式传输MP4格式

时间:2019-04-23 21:08:48

标签: nginx ffmpeg rtmp

我在Nginx rtmp模块+ ffmpeg上运行媒体服务器 使用FLV格式,它可以100%正常工作,但使用MP4时,它不会创建.m3u8文件和流块。 这是nginx.conf文件:

worker_processes  auto;

events {
    worker_connections  1024;
    multi_accept on;
}

rtmp {
  server {
    listen 1935;
    chunk_size 4000;

    application live {
        live on;
        record off;

        hls on;
    hls_path        /HLS/live;

        hls_keys on;
        hls_key_path       /HLS/keys;
        hls_key_url        https://fakeurl:8441/keys/;
    hls_fragments_per_key   10;

        hls_fragment 3s;
        hls_playlist_length 10s;
        deny play all;
    }
  }
}

http {
    include       mime.types;
    tcp_nopush on;
    directio 512;
    default_type  application/octet-stream;
    sendfile      off;

    server {
        listen       8441 ssl;
    server_name  fakeurl;

        ssl_certificate /home/ubuntu/Keys/server.crt;
        ssl_certificate_key /home/ubuntu/Keys/server.key;

        location /keys {
            root /HLS/;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /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/vnd.apple.mpegurl m3u8;
            }

            root /HLS/;
        }


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

这是FFmpeg命令,用于创建将我的RTP流转换为MP4并将其流传输到RTMP服务器的方法:

ffmpeg -protocol_whitelist 'file,udp,rtp' -i input.sdp -c:v libx264 -pix_fmt yuv420p -profile:v baseline -level 3.0 -g 30 -r 30 -c:a aac -b:v 400k -preset ultrafast -tune zerolatency -movflags frag_keyframe -f mp4 rtmp://0.0.0.0:1935/live/stream1

我可以确认ffmpeg可以正常工作并且对输入流稳定,如果我将输出格式更改为flv,则rtmp服务器会创建stream1.m3u8文件,一切都很好。但是对于mp4,mov或m4v格式,nginx不会创建任何内容。

0 个答案:

没有答案