0

I build RTMP server on my local pc according to the nginx official manual:
video-streaming-for-remote-learning-with-nginx

My nginx setting:

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

Set the rtmp url:

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

Push the web camera :

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

Pull the stream with rtmp protocol:

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

I get the video successfully.

Pull the stream with hls protocol:

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.

How to fix it? What does the following code snippet in http segment mean?

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

Where should i mkdir /tv ?

scrapy
  • 323
  • 4
  • 12
  • 27

2 Answers2

1

Change

hls_path /mnt/hls;

to

hls_path /mnt/hls/tv;

The stream will be available at http://127.0.0.1/tv/sample.m3u8.

Arkadiusz Drabczyk
  • 25,049
  • 5
  • 53
  • 68
0

There is a relationship between http and rtmp and push url and pull url for hls. The first group setting works fine.

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

It can also be written as the following pairs which function as the above:

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; 
        } 
scrapy
  • 323
  • 4
  • 12
  • 27