分享直播相关知识点:
http://blog.csdn.net/kingroc/article/details/50839994
#!/bin/bash
# Order Finish Startup
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Socket Sign Handler
# processname: nginx
echo -e "NGINX安装流媒体扩展RTMP开始 :host_ip"
echo -e ""
#访问IP地址(正式环境的访问地址)
host_ip="https://127.0.0.1"
#设置总执行时间5分钏
alltime=300;
#休息时间长-5分钟内执行2~3次
step=100
echo -e ""
echo "====================================================="
echo "Congratulations on your RTMP Install Host : ${host_ip}"
echo "====================================================="
echo -e ""
#编绎安装过程
echo -e ""
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module-master --with-http_ssl_module
make && make install
#启动端口打开文件(使用1935端口)
vim /etc/sysconfig/iptables
#添加一行
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT
#重启防火墙
service iptables restart
#配置相关的端口
netstat -tlun
#NGINX 配置协议
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp {
server {
listen 1935;
application vod{
#播放视频时,查找文件的路径
play /usr/local/nginx/html/flv;
}
application live {
live on;
max_connections 1024;
#record video; #只录视频
record all; #视频音频同时录制
#exec_record_done /usr/local/nginx/sbin/operator_record.py $path $addr;
#exec_record_done, 视频文件录制完成后,进行的数据库类操作
record_unique off;
#record_path /tmp/flv;
#录制视频时,视频文件生成保存的路径
record_path /usr/local/nginx/html/flv;
}
}
}
######========================================================================================================
#RTMP 线上服务器配置流媒体上传(备份代码)
#rtmp_auto_push on;
#rtmp_auto_push_reconnect 1s;
rtmp {
server {
listen 1935;
application vod{
#播放视频时,查找文件的路径
play /usr/local/nginx/html/flv;
}
application live{
live on;
max_connections 1024;
#record video; #只录视频
record all; #视频音频同时录制
record_suffix .mp4; #支持多种格式
access_log logs/rtmp_access.log;
#recorder video{ record audio; }
#exec_record_done, 视频文件录制完成后,进行的数据库类操作
exec_record_done /usr/local/nginx/html/config/rt_water.sh $path $basename;
record_unique off;
#录制视频时,视频文件生成保存的路径
record_path /usr/local/nginx/html/flv;
exec_kill_signal term;
}
}
}
######========================================================================================================
####安装FFMPEG####
#从repo导入GPG密钥:
rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms
#安装ATRPMS Repo:
rpm -ivh http://dl.atrpms.net/all/atrpms-repo-6-7.el6.x86_64.rpm
#Ffmpeg需要libdc1394-devel,它在epel库中可用。 执行以下命令安装epel存储库:
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
#从ATRPMS安装FFMpeg存储库:yum -y --enablerepo=atrpms install ffmpeg ffmpeg-devel
yum -y --enablerepo=atrpms install ffmpeg ffmpeg-devel
#版本
ffmpeg -version
#生成水印
ffmpeg -i html/flv/20170731204517649162.flv -i watermark.png -filter_complex "overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2" shiiiii.flv
#MP4加水印(加参数 -strict -2 )
ffmpeg -i html/flv/20170731221241722162.mp4 -i html/flv/123.png -strict -2 -filter_complex "overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/3" html/flv/shiiiii3.mp4
ffmpeg -i /usr/local/nginx/html/flv/2017082117163622150113.mp4 -i /usr/local/nginx/html/flv/img/water.png -strict -2 -filter_complex "overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/3" /usr/local/nginx/html/flv/20170821/2017082117163622150113.mp4
#接收流
./ffmpeg -i rtmp://192.168.1.232:1935/live/zhut -acodec copy -vcodec copy -f flv -y /usr/local/src/test.flv
#生成水印脚本加载
application myapp {
live on;
exec /var/scripts/exec_wrapper.sh $name;
exec_kill_signal term;
}
#exec /usr/local/nginx/html/config/rt_water.sh $name $path;
#######参数补充说明:
#### $name 文件名($basename) == 20170801123625987162
#### $addr 客户IP == 119.145.5.126
#### $path 文件地址 == /usr/local/nginx/html/flv/20170801123625987162.mp4
#### $filename 文件名带后缀 == 20170801123625987162.mp4
#暂停1秒
sleep 1s
echo -e ""
echo -e "Start clearUsers | lostBlackOrder"
echo -e ""
#每2分钟执行一次
for((i=0;i<alltime;i=(i+step)));do
echo -e ""
curl -k "${host_ip}/index.php?controller=flush&action=clearUsers&type=today";
curl -k "${host_ip}/index.php?controller=flush&action=lostBlackOrder&type=today";
echo -e "Once Finish ====== Sleep(${step}) Seconds"
echo -e ""
#休眠时间
sleep $step
done
echo -e "All Finish ======UPDATE"
sleep 1s
#结束
echo -e ""
echo "====================================================="
echo "Finish Handler , Total Time = ${alltime} 秒 ---END "
echo "====================================================="
echo -e ""
###编译安装PHP的Swool扩展;phpize
DOWNLOAD: wget http://pecl.php.net/get/swoole-1.9.3.tgz
# tar zxvf swoole-1.7.6-stable.tar.gz
# cd swoole-1.7.6-stable
# phpize
# ./configure --with-swoole --with-php-config=/usr/local/php/bin/php-config
# make && make install**
//ext_dir == swoole.so
extension_dir=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
服务端:命令
/usr/local/php/bin/php /usr/local/nginx/html/web/socket/server.php