Nginx
為什麼無法使用 hls url 打開流?
我根據nginx官方手冊在本地電腦上搭建RTMP伺服器:
video-streaming-for-remote-learning-with-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
?
改變
hls_path /mnt/hls;
至
hls_path /mnt/hls/tv;
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; }