本文转载自:http://mp.weixin.qq.com/s?__biz=MjM5MzIwMzExMg==&mid=2664614192&idx=1&sn=41d4268a62360f0a8284740a3abae9c3&scene=4#wechat_redirect
上一篇文章发过后,有同学问在nginx下如何视频直播,有的同学就自己研究并写了博客,我们把他的全文转载到这里,供大家学习。同时欢迎大家都来投稿,到时赞赏的钱都付稿费噢!
从下面的网址分别下载nginx和nginx-rtmp-module:
http://nginx.org/en/download.html
我下载了1.10.1的版本。
https://github.com/arut/nginx-rtmp-module
我目前的现状是已经安装好了nginx 。版本号为 nginx/1.10.1,需要在它的基础上安装rtmp这个模块,可以使用如下的方法实现:
cd
/date/tools
git clone https://github.com/arut/nginx-rtmp-module.git
(克隆 nginx-rtmp-module)
cd /date/tools/nginx-1.10.1
./configure --prefix=/usr/local/nginx --add-module=/date/tools/nginx-rtmp-module --with-http_ssl_module
--with-debug
make
make install
2.nginx配置
https://github.com/arut/nginx-rtmp-module/wiki/Directives
在原有的/usr/local/nginx/conf/nginx.conf中加入如下配置
-
rtmp {
-
-
server {
-
-
listen 1935;
-
-
chunk_size 4000;
-
-
#HLS
-
-
# For HLS to work please create a directory in tmpfs (/tmp/app here)
-
# for the fragments. The directory contents is served via HTTP (see
-
# http{} section in config)
-
#
-
# Incoming stream must be in H264/AAC. For iPhones use baseline H264
-
# profile (see ffmpeg example).
-
# This example creates RTMP stream from movie ready for HLS:
-
#
-
# ffmpeg -loglevel verbose -re -i movie.avi -vcodec libx264
-
# -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
-
# -f flv rtmp://localhost:1935/hls/movie
-
#
-
# If you need to transcode live stream use 'exec' feature.
-
#
-
application hls {
-
live on;
-
hls on;
-
hls_path /usr/local/nginx/html/hls;
-
hls_fragment 5s;
-
}
-
}
-
}
-
-
http {
-
-
server {
-
-
listen 8080;
-
location /hls {
-
# Serve HLS fragments
-
types {
-
application/vnd.apple.mpegurl m3u8;
-
video/mp2t ts;
-
}
-
root html;
-
expires -1;
-
}
-
}
-
}
nginx -t 检查一下语法。
nginx -s reopen重启nginx。
netstat -an |grep 1935 查看1935端口是否开启
tcp 0 0 0.0.0.0:1935 0.0.0.0:* LISTEN
netstat -an |grep 8080
cp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
这种状态就说明成功了。
在freeswitch中配置mod_av(编解码的模块) 下载vc.tar.gz(注:FreeSWITCH源代码里有个 html5/verto/verto_communicator 目录,安装verto
cd html5/verto/verto_communicator
./debian8-install.sh
执行完将生成dist目录。)
cd /usr/local/freeswitch/conf/autoload_configs/
vim verto.conf.xml打开后添加
<vhosts>
<vhost domain="localhost">
<param name="alias" value="seven.local freeswitch.org"/>
<param name="root" value="/date/tools/vc"/>
<param name="index" value="index.html"/>
<!--
<param name="auth-realm" value="FreeSWITCH"/>
<param name="auth-user" value="freeswitch"/>
<param name="auth-pass" value="rocks"/>
-->
</vhost>
</vhosts>
在</profile>前,如图:
其中里面的<param name = "root" value="date/tools/vc"> 这是vc解压后的地址 这样mod_verto就变成了一个服务器了
这样在freeswitch中load mod_av
用Chrome浏览器访问: https://你的ip:8082/
每一次访问,需要输入你的姓名和电子邮件。
呼叫3500,就可以进入视频会议了。
这时候在freeswitch中执行
conference 3500-121.41.105.36 record rtmp://192.168.3.203/hls
如果你觉得很麻烦
apt-get install crtmpserver -y
/etc/init.d/crtmpserver start
在freeswitch中conference 3500-121.41.105.36 record rtmp://192.168.3.203/live/1
然后就可以在https://www.hlsplayer.net/rtmp-player中输入 rtmp://192.168.3.203/live/1进行观看了
因为之前虚拟机用了1个cpu 1G的内存,所以在转码的时候cpu使用率达到96%,所以要用多个cpu 更大的内存才能流畅的使用。