使用ffmpeg推送rtmp流

服务器设置

关闭防火墙或者开放端口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

编辑完成后保存

# 更改权限

chmod 755 /etc/init.d/nginx

# 添加到启动项配置

chkconfig --add nginx

# 开机启动

chkconfig nginx on

# 启动命令

service nginx start

#

service nginx stop

service nginx restart

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

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

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

# RTMP配置

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

5、修改完成配置后,需要重启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

 

 

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

答 案

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值