NGINX搭建流媒体后,RTMP可以听,但是HLS始终没法使用

[复制链接]
查看11 | 回复2 | 2021-1-27 05:07:18 | 显示全部楼层 |阅读模式
用NGINX搭建流媒体服务器做音频直播。NGINX解压到D盘的WWW下。用FlashMediaLiveEncoder推流后,RTMP可以正常听,但是HLS连不上,而且在服务器上也找不到文件切片。
PS,我之前用的是FMS5.0做流媒体服务器,但是也是RTMP能听,HLS怎么设置都不行,网上的教程看来看起也都是觉得很茫然。
请各位大神给予指导帮助,谢谢。
NGINX的配置文件内容如下:

#usernobody;
#multipleworkersworks!
worker_processes2;
error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
pidlogs/nginx.pid;
events{
worker_connections51200;
}
rtmp{
server{
listen1935;
chunk_size4000;
#HLS
#ForHLStoworkpleasecreateadirectoryintmpfs(/tmp/apphere)
#forthefragments.ThedirectorycontentsisservedviaHTTP(see
#http{}sectioninconfig)
#
#IncomingstreammustbeinH264/AAC.ForiPhonesusebaselineH264
#profile(seeffmpegexample).
#ThisexamplecreatesRTMPstreamfrommoviereadyforHLS:
#
#ffmpeg-loglevelverbose-re-imovie.avi-vcodeclibx264
#-vprofilebaseline-acodeclibmp3lame-ar44100-ac1
#-fflvrtmp://localhost:1935/hls/movie
#
#Ifyouneedtotranscodelivestreamuse'exec'feature.
#
applicationhls{
liveon;
hlson;
hls_path/www/html/hls;
hls_fragment5s;
}
}
}

http{
includemime.types;
default_typeapplication/octet-stream;
#
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
gzipon;
server{
listen88;
server_namelocalhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
roothtml;
indexindex.htmlindex.htm;
}
location~\.flv${
root/usr/local/html/media/;
flv;
}
location~\.mp4${
root/usr/local/html/media/;
mp4;
}
location/stat{
rtmp_statall;
#UsethisstylesheettoviewXMLaswebpage
#inbrowser
rtmp_stat_stylesheetstat.xsl;
}
location/stat.xsl{
#XMLstylesheettoviewRTMPstats.
#Copystat.xslwhereveryouwant
#andputthefulldirectorypathhere
root/path/to/stat.xsl/;
}
location/hls{
#ServeHLSfragments
types{
application/vnd.apple.mpegurlm3u8;
video/mp2tts;
}
alias/www/hls/test/;
expires-1;
add_headerCache-Controlno-cache;
}

root/tmp;
add_headerCache-Controlno-cache;
}
#error_page404/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
roothtml;
}

#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#proxy_passhttp://127.0.0.1;
#}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
#location~\.php${
#roothtml;
#fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.php;
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
#includefastcgi_params;
#}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#denyall;
#}

#HTTPSserver
#
#server{
#listen443ssl;
#server_namelocalhost;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_cacheshared:SSL:1m;
#ssl_session_timeout5m;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}

http{
server{
listen8080;
location/hls{
#ServeHLSfragments
types{
application/vnd.apple.mpegurlm3u8;
video/mp2tts;
}
roothtml;
expires-1;
}
}
}
分 -->
回复

使用道具 举报

千问 | 2021-1-27 05:07:18 | 显示全部楼层
nginx-rtmp-win32-master
#使用方法
双击nginx.exe
#简要说明
conf/nginx.conf为配置文件实例
RTMP监听1935端口,启用live和hls两个application
HTTP监听8080端口,
*:8080/stat查看stream状态
*:8080/index.html为一个直播播放与直播发布测试器
*:8080/vod.html为一个支持RTMP和HLS点播的测试器

worker_processes1;
error_loglogs/error.logdebug;
events{
worker_connections1024;
}
rtmp{
server{
listen1935;
applicationlive{
liveon;
}
applicationhls{
liveon;
hlson;
hls_pathtemp/hls;
hls_fragment8s;
}
}
}
http{
server{
listen80;
location/{
roothtml;
}
location/stat{
rtmp_statall;
rtmp_stat_stylesheetstat.xsl;
}
location/stat.xsl{
roothtml;
}
location/hls{
#serverhlsfragments
types{
application/vnd.apple.mpegurlm3u8;
video/mp2tts;
}
aliastemp/hls;
expires-1;
}
}
}

回复

使用道具 举报

千问 | 2021-1-27 05:07:18 | 显示全部楼层
引用楼主ttv308he的回复:用NGINX搭建流媒体服务器做音频直播。NGINX解压到D盘的WWW下。用FlashMediaLiveEncoder推流后,RTMP可以正常听,但是HLS连不上,而且在服务器上也找不到文件切片。
PS,我之前用的是FMS5.0做流媒体服务器,但是也是RTMP能听,HLS怎么设置都不行,网上的教程看来看起也都是觉得很茫然。
请各位大神给予指导帮助,谢谢。
NGINX的配置文件内容如下:

#usernobody;
#multipleworkersworks!
worker_processes2;
error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
pidlogs/nginx.pid;
events{
worker_connections51200;
}
rtmp{
server{
listen1935;
chunk_size4000;
#HLS
#ForHLStoworkpleasecreateadirectoryintmpfs(/tmp/apphere)
#forthefragments.ThedirectorycontentsisservedviaHTTP(see
#http{}sectioninconfig)
#
#IncomingstreammustbeinH264/AAC.ForiPhonesusebaselineH264
#profile(seeffmpegexample).
#ThisexamplecreatesRTMPstreamfrommoviereadyforHLS:
#
#ffmpeg-loglevelverbose-re-imovie.avi-vcodeclibx264
#-vprofilebaseline-acodeclibmp3lame-ar44100-ac1
#-fflvrtmp://localhost:1935/hls/movie
#
#Ifyouneedtotranscodelivestreamuse'exec'feature.
#
applicationhls{
liveon;
hlson;
hls_path/www/html/hls;
hls_fragment5s;
}
}
}

http{
includemime.types;
default_typeapplication/octet-stream;
#
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
gzipon;
server{
listen88;
server_namelocalhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location/{
roothtml;
indexindex.htmlindex.htm;
}
location~\.flv${
root/usr/local/html/media/;
flv;
}
location~\.mp4${
root/usr/local/html/media/;
mp4;
}
location/stat{
rtmp_statall;
#UsethisstylesheettoviewXMLaswebpage
#inbrowser
rtmp_stat_stylesheetstat.xsl;
}
location/stat.xsl{
#XMLstylesheettoviewRTMPstats.
#Copystat.xslwhereveryouwant
#andputthefulldirectorypathhere
root/path/to/stat.xsl/;
}
location/hls{
#ServeHLSfragments
types{
application/vnd.apple.mpegurlm3u8;
video/mp2tts;
}
alias/www/hls/test/;
expires-1;
add_headerCache-Controlno-cache;
}

root/tmp;
add_headerCache-Controlno-cache;
}
#error_page404/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
roothtml;
}

#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#proxy_passhttp://127.0.0.1;
#}
#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
#location~\.php${
#roothtml;
#fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.php;
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
#includefastcgi_params;
#}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#denyall;
#}

#HTTPSserver
#
#server{
#listen443ssl;
#server_namelocalhost;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_cacheshared:SSL:1m;
#ssl_session_timeout5m;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}

http{
server{
listen8080;
location/hls{
#ServeHLSfragments
types{
application/vnd.apple.mpegurlm3u8;
video/mp2tts;
}
roothtml;
expires-1;
}
}
}

我之前做可视门铃的项目,用的和你的一样的,服务器和终端都是我弄的,肯定是你配置不对,仔细找找看
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行