抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

服务器设置

关闭防火墙或者开放端口1935,80端口

关闭防火墙

systemctl stop firewalld.service

禁⽌firewall开机启动

systemctl disable firewalld.service

#查看默认防⽕墙状态(关闭后显示notrunning,开启后显示running)

firewall-cmd --state

安装FFmpeg
1、安装yasm编译器

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -xvf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make
make install

2、安装FFmpeg

wget http://www.ffmpeg.org/releases/ffmpeg-3.4.tar.gz
tar -xvf ffmpeg-3.4.tar.gz
cd ffmpeg-3.4/
./configure --enable-shared --prefix=/usr/local/ffmpeg
make
make install

3.安装yum

sudo yum install epel-release -y
sudo rpm –import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

4、安装FFmpeg和FFmpeg开发包

sudo yum install ffmpeg ffmpeg-devel -y

5、安装libx264解码包

sudo yum install x264 x264-devel -y

6、验证ffmpeg是否安装成功

ffmpeg -version

安装nginx

1、安装基本的编译⼯具

yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

2、下载rtmp模块

cd /usr/local/src  # 保存⽬录
git clone https://github.com/arut/nginx-rtmp-module.git

3、下载nginx

wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar zxvf nginx-1.18.0.tar.gz

4、编译nginx

cd nginx-1.18.0
./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/nginx-rtmp-module
make && make install

5、设置启动脚本

vi /etc/init.d/nginx

填写⼀下内容

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
    echo -n $"Starting $prog: "
    mkdir -p /dev/shm/nginx_temp
    daemon $NGINX_SBIN -c $NGINX_CONF
    RETVAL=$?
    echo
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    killproc -p $NGINX_PID $NGINX_SBIN -TERM
    rm -rf /dev/shm/nginx_temp
    RETVAL=$?
    echo
    return $RETVAL
}
reload(){
    echo -n $"Reloading $prog: "
    killproc -p $NGINX_PID $NGINX_SBIN -HUP
    RETVAL=$?
    echo
    return $RETVAL
}
restart(){
    stop
    start
}
configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}
case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    reload)
    reload
    ;;
    restart)
    restart
    ;;
    configtest)
    configtest
    ;;
    *)

echo $"Usage: $0 {start|stop|reload|
restart|configtest}"
RETVAL=1
esac
exit $RETVAL

编辑完成后保存

5、 更改权限

chmod 755 /etc/init.d/nginx

6、 添加到启动项配置

chkconfig --add nginx

7、 开机启动

chkconfig nginx on

8、 基本命令

service nginx start
service nginx stop
service nginx restart

6、配置nginx⽀持rtmp和hls协议

vim /usr/local/nginx/conf/nginx.conf

在HTTP标签同级添加RTMP配置内容

7、 RTMP配置

rtmp {
 server {
  listen 1935;
  chunk_size 4096;
 
  application live {
   live on;
   record off;
  }
 }
}

8、修改完成配置后,需要重启nginx服务器

service nginx reload

ffmpeg推流Nginx

FFmpeg能够讲数据流“推流”到已经搭建好的Nginx流媒体服务器上。

Nginx已经增加了RTMP协议的⽀持,因此借助FFmpeg推流成功后,在Nginx服务器上可以得到两种视频流:RTMP流。

需要注意,不管是哪种流,在推流过程中是RTMP流形式体现的。

RTMP流,推流⾄live

ffmpeg -re -i {input-source} -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10
rtmp://localhost:1935/live/test

或者

ffmpeg -i {input-source} -f flv -r 25 -s 1280*720 -an rtmp://localhost:1935/live/test

例如:

ffmpeg -i rtsp://摄像头登录账号:密码@摄像头ip:554 -f flv -r 25 -an rtmp://localhost:1935/hls/mystream

拉流地址

RTMP流:

rtmp://localhost:1935/rtmplive/test

评论