网页调用服务器视频代码,网页全终端视频流媒体播放器EasyPlayer之使用nginx和r。。。

⽹页调⽤服务视频代码,⽹页全终端视频流媒体播放器EasyPlayer之使⽤nginx和r。。。
使⽤ nginx 和 rtmp 模块 ,可以很容易地搭建⼀个视频直播和点播服务器出来。下⾯我们来看⼀下具体实施步骤:
1. 安装 nginx 和 rtmp 模块
有关 nginx 的编译和安装⽐较简单,这⾥就不介绍了,看参考⽂献。这⾥提⽰以下⼏点:
(1) 安装好 nginx 后,配置⽂件在这⾥:
/usr/local/nginx/f
瓶颈效应(2) 启动 nginx 的命令:
$ sudo /usr/local/nginx/sbin/nginx -s stop
$ sudo /usr/local/nginx/sbin/nginx
2. 配置 nginx 视频直播和点播服务
先看⼀下完整的 nginx 配置⽂件⾥有关视频点播和直播的配置:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
}
application live2 {
live on;
record off;
}
# video on demand
application vod {
play /var/flvs;
}
application vod_http {
}
application hls {
live on;卡盘扳手
hls on;
hls_path /tmp/hls;
}
}
保皇派
}
# HTTP can be used for accessing RTMP stats http {
server {
listen 8080;
# This URL provides RTMP statistics in XML location /stat {
rtmp_stat all;
李怀庆# Use this stylesheet to view XML as web page # in browser
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
# Copy stat.xsl wherever you want
# and put the full directory path here
root /path/to/stat.xsl/;
}
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
桂花新品种video/mp2t ts;
水在时间之下
}
root /tmp;
add_header Cache-Control no-cache;
}
location /dash {
# Serve DASH fragments
root /tmp;
add_header Cache-Control no-cache;
}
}
}
现在来解释⼀下⾥⾯各⾏代码的含义。对于视频直播服务,如果需要⽀持多路流输⼊的话,很简单,在 nginx 配置⽂件⾥多配⼏个Application 就只可以了,像下⾯这样:
application live {
live on;
record off;
}
application live2 {
live on;
record off;
}
这样就可以通过下⾯的地址来推送直播流,其它观众端也可以通过下⾯的地址来访问直播流:
rtmp://192.168.31.185/live/test
rtmp://192.168.31.185/live2/test
后⾯紧跟的 test 关键字,可以随便更换,只要你的推送流和访问流的地址⼀样就可以了。
rtmp 模块也可以直接⽀持 VOD 这种视频点播服务 ,只需要在配置⽂件⾥添加如下内容即可:
# video on demand
application vod {
play /var/flvs;
}
application vod_http {
}
然后把⼀个 mp4 或是 flv ⽂件扔到 /var/flvs ⽬录下,对于 /var/flvs/dir/file.flv 这个视频⽂件,就可以通过下⾯的⽹址来访问了:
这样直接在浏览器⾥就可以通过⽹页观看视频。对于 mp4 ⽂件,也可以实现 VOD 服务,不过需要的是采⽤ H.264 和 AAC 格式编码的mp4 ⽂件。
3. HLS 直播流的配置
如果需要使⽤ HLS 来视频直播,可以直接像配置⽂件那样,写上下⾯这⼀段:
application hls {
live on;
hls on;
hls_path /tmp/hls;
}
同时把后⾯有关 http 访问的内容写上:
# HTTP can be used for accessing RTMP stats http {
server {
listen 8080;
# This URL provides RTMP statistics in XML location /stat {
rtmp_stat all;
# Use this stylesheet to view XML as web page # in browser
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
# Copy stat.xsl wherever you want
# and put the full directory path here
root /path/to/stat.xsl/;
}
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
location /dash {
# Serve DASH fragments
root /tmp;
add_header Cache-Control no-cache;
}
}
}
配好以后,推流可以使⽤下⾯的地址:
rtmp://192.168.31.185/hls/movie
movie 关键字可以任何替换。对于观众端来说,可以有⼏种播放⽅式:
(1) ⽤ rtmp:
rtmp://192.168.31.185/hls/movie
(2) ⽤ hls 播放:
这样就可以看到主播端推出来的流。注意,如果使⽤ http ⽅式,则是监听的 8080 端⼝,这个是在配置⽂件⾥写的。
4. ⽹页播放器播放
在第⼆步⾥,除了可以直接在浏览器⾥打开⽹址来观看视频,还可以写⼀个⽹页,实现像优酷那样的视频点播业务。通过使⽤第三⽅的播放器,在⽹页⾥植⼊该播放器来实现这个功能,⽐如说使⽤ EasyPlayer播放器。
EasyPlayer是⼀款流媒体播放器系列项⽬, ⽀持RTSP、RTMP、HTTP、HLS、UDP、RTP、File等多种流媒体协议播放、 ⽀持本地⽂件播放,⽀持本地抓拍、本地录像、播放旋转、多屏播放、 倍数播放等多种功能特性,核⼼基于ffmpeg,稳定、⾼效、可靠、可控。

本文发布于:2024-09-22 13:22:47,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/82185.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:直播   播放   视频   服务   媒体播放器   配置   功能   访问
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议