转码推流服务器安装:
基础工具:
yum install lrzsz -y yum -y install gcc automake autoconf libtool make gcc gcc-c++ bzip2 xz yum install unzip -y yum install gcc-c++ -y yum install pcre pcre-devel -y yum install zlib zlib-devel -y yum install openssl openssl-devel -y yum install wget yum install vim
nasm和yasm安装:
创建文件夹 yasm wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz tar -zxvf yasm-1.3.0.tar.gz cd yasm-1.3.0 ./configure make && make install
创建文件夹 nasm wget http://www.nasm.us/pub/nasm/releasebuilds/2.13/nasm-2.13.tar.gz tar -zxvf nasm-2.13.tar.gz cd nasm-2.13 ./configure make && make install
x264安装
在/usr/local目录 yum install git git clone https://code.videolan.org/videolan/x264.git cd x264 ./configure --enable-shared --enable-static --disable-asm make && make install
ffmpeg工具安装:
在/usr/local/创建ffmpeg文件夹,并进入. wget http://www.ffmpeg.org/releases/ffmpeg-4.1.tar.gz tar -zxvf ffmpeg-4.1.tar.gz cd ffmpeg-4.1 ./configure --enable-gpl --enable-libx264 (绑定libx264) make && make install vim /etc/ld.so.conf 末行添加/usr/local/ffmpeg/lib #刷新配置命令 ldconfig ffmpeg -version 报错 ffmpeg: error while loading shared libraries: libx264.so.164: cannot open shared object file: No such file or directory 报错处理:whereis ibx264.so.164 找文件位置. 也可以进入 /usr/local/ffmpeg/ffmpeg-4.1目录,使用ldd ffmpeg 查询缺失依赖包. vim /etc/profile 在最后PATH添加环境变量: #export PATH=$PATH:/usr/local/ffmpeg/bin (适用于下载的ffmpeg有bin目录的) export LD_LIBRARY_PATH=/usr/local/lib/ 保存退出 查看是否生效 source /etc/profile 设置生效
下载nginx及模块包:
mkdir /usr/local/nginx cd /usr/local/nginx wget https://nginx.org/download/nginx-1.14.2.tar.gz https://github.com/winshining/nginx-http-flv-module(通过github下载后上传到nginx文件夹) tar -zvxf nginx-http-flv-module-master.tar.gz -C /usr/local/nginx tar -zvxf nginx-1.14.2.tar.gz -C /usr/local/nginx cd nginx-1.14.2 ./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx/nginx-http-flv-module-master make && make install
配置nginx的配置文件:
user root; worker_processes auto; #worker_processes 2; #worker_cpu_affinity 01 10; pid /run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 1111; server_name localhost; location / { root html; index index.html; try_files $uri $uri/ /index.html; } } server { location /live { #推流后访问入口 flv_live on; chunked_transfer_encoding on; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; } } } rtmp_auto_push on; rtmp_auto_push_reconnect 1s; rtmp_socket_dir /tmp; rtmp { out_queue 4096; out_cork 8; max_streams 128; timeout 15s; drop_idle_publisher 15s; server { listen 1935; application http_flv { live on; record off; gop_cache off; } } }
进入nginx的sbin目录,启动nginx.
网络流地址:
rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4
推流地址:
ffmpeg -re -rtsp_transport tcp -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4 -vcodec libx264 -an -f flv -s 960x540 rtmp://192.168.10.98:1935/http_flv/tower
http_flv对应nginx配置文件application的名称.
tower是流的名称.
拉流地址:
方式一:
rtmp://192.168.10.98:1935/http_flv/tower
方式二:
http://192.168.10.98/live?port=1935&app=http_flv&stream=tower
live对应推流后的访问入口.
http_flv对应http_flv对应nginx配置文件application的名称和推流中的http_flv.
tower是流的名称.
流停止(注意nginx要环境变量,nginx服务停止就可以)
vim /etc/profile
source /etc/profile
末尾上 export PATH=$PATH:/usr/local/nginx/sbin
nginx结束命令 nginx -s stop