为什么无法使用 hls url 打开流?

为什么无法使用 hls url 打开流?

我按照nginx官方手册在本地电脑上搭建RTMP服务器:
使用 nginx 进行远程学习的视频流

我的 nginx 设置:

sudo vim /usr/local/nginx/conf/nginx.conf    
worker_processes  1;   
error_log  logs/error.log;
worker_rlimit_nofile 8192;

events {
  worker_connections  1024;  
}  

rtmp { 
    server { 
        listen 1935; 
        application live { 
            live on; 
            interleave on;
 
            hls on; 
            hls_path /mnt/hls; 
            hls_fragment 15s; 
        } 
    } 
} 
 
http { 
    default_type application/octet-stream;
 
    server { 
        listen 80; 
        location /tv { 
            root /mnt/hls; 
        } 
    }
 
    types {
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
        text/html html;
    } 
}

设置 rtmp 网址:

output="rtmp://127.0.0.1:1935/live/sample"  

推动网络摄像头:

ffmpeg -f v4l2 -video_size 640x480 -i /dev/video0 -c:v libx264 -f flv $output

使用rtmp协议拉流:

ffplay rtmp://127.0.0.1:1935/live/sample

我成功获取视频了。

使用hls协议拉流:

ffplay http://127.0.0.1/live/sample
HTTP error 404 Not Found
http://127.0.0.1:80/live/sample.m3u8: Server returned 404 Not Found 
#It can't get video with browser.

如何修复它? http段中的以下代码片段是什么意思?

    server { 
        listen 80; 
        location /tv { 
            root /mnt/hls; 
        } 
    }

我应该去哪里mkdir /tv

答案1

改变

hls_path /mnt/hls;

hls_path /mnt/hls/tv;

该流将在http://127.0.0.1/tv/sample.m3u8

答案2

http和rtmp以及hls的push url和pull url之间有关系。第一个组设置效果很好。

Pull url  

    http://127.0.0.1/tv/sample.m3u8

Push url

    rtmp://127.0.0.1:1935/live/sample

        location /tv { 
            root /mnt/hls; 
        } 
rtmp setting

        application live { 
            live on; 
            interleave on; 
            hls on; 
            hls_path /mnt/hls; 
        } 

http setting

        location /tv { 
            root /mnt/hls; 
        } 

它也可以写成下面的对,其功能如上:

Pull url  

    http://127.0.0.1/tv/sample.m3u8

Push url

    rtmp://127.0.0.1:1935/tv/sample

        location /tv { 
            root /mnt; 
        } 
rtmp setting

        application tv { 
            live on; 
            interleave on; 
            hls on; 
            hls_path /mnt/tv; 
        } 

http setting

        location /tv { 
            root /mnt/hls; 
        } 

相关内容