【问题标题】:hls stream not working in nginx-rtmp-modulehls 流在 nginx-rtmp-module 中不起作用
【发布时间】:2020-08-10 16:18:05
【问题描述】:

我使用nginx-rtmp-module创建了媒体流服务

nginx.config 文件

worker_processes  auto;

events {
    worker_connections  1024;
}

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


    server {
        listen 3002;
        server_name  localhost;

        location /live {
            # Disable cache
            add_header Cache-Control no-cache;

            # CORS setup
                add_header 'Cache-Control' 'no-cache';
                add_header 'Access-Control-Allow-Origin' '*' always;
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
                add_header 'Access-Control-Allow-Headers' 'Range';

            # allow CORS preflight requests
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                       add_header 'Access-Control-Allow-Headers' 'Range';
                       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 /Users/dev/Desktop/stream/storage/;
            add_header Cache-Control no-cache;  
        }
    }

    include servers/*;
}

# RTMP Config
rtmp {
    server {
        listen 1935; # Listen on standard RTMP port
        chunk_size 4000;
        ping 30s;
        notify_method get;
        application live{
            live on;
            exec_pull ffmpeg -re -i http://127.0.0.1/$app/$name
  -vcodec libx264 -threads 0 -vprofile baseline -acodec aac -strict -2 -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://127.0.0.1:1935/show/${name}_720
  -vcodec libx264 -threads 0 -vprofile baseline -acodec aac -strict -2 -b:v 1024k -b:a 128k -vf "scale=854:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://127.0.0.1:1935/show/${name}_480
  -vcodec libx264 -threads 0 -vprofile baseline -acodec aac -strict -2 -b:v 300k -b:a 96k -vf "scale=426:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://127.0.0.1:1935/show/${name}_240;
        }
        application show {
            live on;
            # Turn on HLS
            hls on;
            hls_nested on;
            record off;
            hls_path /Users/dev/Desktop/stream/storage/live/;
            
            # Instruct clients to adjust resolution according to bandwidth
            hls_variant _720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
            hls_variant _480 BANDWIDTH=448000; # Medium bitrate, SD resolution
            hls_variant _240 BANDWIDTH=288000; # Low bitrate, sub-SD resolution
        }
    }
}
# End RTMP Config

我正在使用 ffmpeg 命令创建流文件

ffmpeg -re -i sample.mp4  -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://127.0.0.1/live/my_video

当我检查 stream/storage/live/ 文件夹时,我没有看到在文件夹上创建任何 .tsindex.m3u8 文件.

我尝试在 VLC 播放器中播放 rtmp 视频,但它没有播放,我没有收到任何错误,但视频仍然无法在 VLC 播放器上播放。

【问题讨论】:

    标签: nginx rtmp nginx-config mediastream


    【解决方案1】:

    检查 nginx 是否需要写入hls_path /Users/dev/Desktop/stream/storage/live/ 的权限。或者,你可以在你的 nginx 配置文件的第一行添加user root;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-20
      • 2017-11-23
      • 2015-03-08
      • 2013-10-22
      • 1970-01-01
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多