首页 > 编程知识 正文

nginx作为web服务器(webrtc视频流传输)

时间:2023-05-05 20:36:59 阅读:71916 作者:3114

1 .环境准备Linux centos7.6 nginx-1.18.0软件包wget http://nginx.org/download/nginx-1.8.1.tar.gz nginx-rtmp-modd

1.1环境相关安装[根@ imagesrsdata ] # yuminstallgitgcc-copensslopenssl-develpcrepcre-devel zlib-devel-y 2.1源包实例

[ root @ imagesrsdata ] # useradd-r-s/sbin/nolog in nginx 2.2解压缩nginx-rtmp-module-master

[ root @ imagesrsnginx-1.18.0 ] # unzip nginx-rtmp-module-master.zip 2.3安装nginx

[ root @ imagesrsdata ] # tar-xvf nginx-1.18.0.tar.gz [ root @ imagesrsdata ] # cdnginx-1.18.0/[ root @ imar ] - add-module=/data/nginx-rtmp-module-master (模块源包位置)创建软链接(根@ centos7sbin ) ) ln-s/usr /

[ root @ imagesrsconf ] # CD/usr/local/nginx/conf [ root @ imagesrsconf ] # vim nginx.confusernginx; 工作器_ processes 1; 事件{ worker _ connections 1024; }rtmp { server { listen 1935; #端口号chunk_size 4000; 应用程序HLS { live on; hls on; HLS _ path/usr/local/nginx/html/HLS; #切片保管场所hls_fragment 5s; hls_playlist_length 15s; hls_continuous on; hls_cleanup on; hls_nested on; } } }http { include mime.types; efault _ type应用程序/octet-stream; sendfile on; keepalive_timeout 65; 服务器{ listen 80; server_name localhost; 位置/{ root/usr/local/nginx/html; 索引索引. html index.htm; } error _ page 500502503504/50x.html; location=/50x.html {根html; } location/HLS { types } application/vnd.apple.mpegurlm 3u 8; } alias/usr/local/nginx/html/HLS; expires -1; add _ header cache-control no-cache; }location /stat {rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location/stat.xsl { root/usr/local/extend _ module/nginx-rtmp-module/} }

nginx [root@imagesrs conf]# nginx开始重新加载: [ root @ images RS conf ] # nginx-s reload检查配置文件: [ root @ images RS conf ]

有关更多rtmp参数的信息,请参见:

3359 github.com/arut/nginx-rtmp-module/wiki

3 .实时服务器和推送、抽取操作需要下载两个程序

拉流: VLC https://VLC-media-player.en.softonic.com /

现场分发(OBS https://obsproject.com/

推送客户端:

活动流端使用rtmp协议推送流,端口为1935。 URL格式为rtmp://ip:端口/hls。 流媒体软件推荐开源的OBS。 https://obsproject.com/流名称推送流,使其与为观看实时而写的页面上的xxxx.m3u8名称相匹配:

点击开始推送流程;

浏览器输入http :/xx.xx.xx.xx/HLS/111/index.m3 u8即可查看直播

111目录名根据最终生成目录决定

拉式操作:

VLC --打开介质- -打开网络流- -输入rtmp /或hls地址

在/usr/local/nginx/html/hls/111目录中生成的片文件

浏览器显示:

HlS地址: http://192.168.197.133/HLS/111/index.m3 u8

LVC检查:正常

查看前端HTML代码:

! doctypehtmlhtmllang=' en ' headmetacharset=' utf-8 ' metaname=' viewport ' content=' width=device-width, initial-scale=1.0 ' meta http-equiv=' x-ua-compatible ' content=' ie=edge ' titlepchlsvideo/titlelinkhref=' 要在video-js-cdn.min.CSS ' rel=' style sheet '/headbodyh1PC端播放HLS (代码. m3u8代码)视频/h1p,请访问video.js和viadbodyh 设置浏览器跨域/pvideoid=' HLS -视频' width=' 300 ' height=' 200 ' class='视频- jsvjs-default-skin ' playsining -直播视频源--- source src=' http://192.168.197.133/HLS/111/index.m3 u8 ' type=' application/x-mpegurl '! -按需视频源- -! - source src=' http://dev streaming.apple.com/videos/wwdc/2015/413 EFL f3lr h1 tyo/413/HLS _ VOD _ MVP.m3 u8 ' videos -PC端浏览器不支持播放hls文件(m3u8 )。 需要videojs-contrib-hls才能进行解码--- script src=' http://cdn.boot CSS.com/video js-contrib-HLS/5.3.3/video video.m3 u8.no ' access-control-allow-origin ' headerispresentontherequestedresource.origin ' 3358192.168.198 请设置浏览器以运行跨域var player=视频js (HLS-video )。 player.play (; /script/body参考站点:

3359 www.cn blogs.com/woai yunwei/p/13128917.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。