将RTSP转换为HLS Nginx进行流式处理时出现问题

时间:2019-01-14 03:07:01

标签: nginx streaming rtsp rtmp hls

im对于nginx和Ubuntu来说确实很新。我试图建立一个网站,将网络摄像机视频流式传输到互联网。我目前正在使用nginx 1.14和ubuntu 18.04。

我从相机获取了RTSP网址,并在我的nginx conf中成功地使用ffmpeg将其转换为RTMP。我可以在VLC中正常播放视频(rtsp和rtmp url)。 问题是当我想将RTMP转换为HLS时,可以在html5播放器(如videojs)中播放它。请在下面查看我的代码。

Nginx Conf。

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {worker_connections 768;
    # multi_accept on;}


rtmp {
server {

        listen 1935;

        chunk_size 4096;

application live {
live on;
record off;
hls on;
hls_nested on;
hls_path /tmp/hls/;
hls_fragment 3;
hls_playlist_length 60;
exec_pull /usr/bin/ffmpeg -i rtsp://025164132:jose1992@192.168.0.16:554/onvif1 -vcodec libx264 -acodec copy -f flv rtmp://192.168.0.14:1935/live/stream1;
}    }}http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {     
listen    80;

location /hls {
    # Serve HLS fragments

    # 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/dash+xml mpd;
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
    }
    root /tmp/;
}
location / {
    root   html;
    index  index.html index.htm;

}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}}}

因此,当我在浏览器或Vlc中尝试使用此网址http://ip-server/hls/stream1.m3u8时,没有任何反应,

我验证了每次nginx在文件夹tmp / hls / stream1 /(ts和index.m3u8中的文件)中运行nginx时都创建了.ts和m3u8文件,我不知道为什么m3u8文件是命名索引而不是stream1。

请帮助您,并在需要时更正我的任何代码。我已经尝试了3天,但没有运气:(

谢谢!

0 个答案:

没有答案