ubuntu16.04安装nginx,nignx-rtmp-mpdule,ffmeg,搭建rtmp服务器

本文详细介绍了如何下载、编译并配置Nginx及其RTMP模块,实现流媒体服务。从源码安装Nginx,到配置RTMP模块及状态检查页面,再到使用FFmpeg进行推流与拉流测试,最后提供了CentOS 7.5下的启动脚本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,下载,编译 nignix   nignx-rtmp-mpdule

编译nginx时需要nignx-rtmp-mpdule的包加入

git clone https://github.com/arut/nginx-rtmp-module.git

wget http://nginx.org/download/nginx-1.7.5.tar.gz

放置于同一个目录

tar -xvf nginx-1.7.5.tar.gz
cd  nginx-1.7.5/

./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make
make install
安装到 /usr/local
cd /usr/local
cd nginx/
wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
chmod a+x /etc/init.d/nginx
update-rc.d nginx defaults
service nginx start
service nginx stop

默认启动80端口监听

修改监听端口
cd conf/
 cp nginx.conf nginx.conf-bak
 vi nginx.conf

修改http下的端口为8080

再次启动

浏览器打开localhost:8080

 

安装完成

 

增加nginx-rtmp 状态查看页面

解压nginx-rtmp下的html.tar.gz包

/usr/local/nginx/html

 

 

2.修改nginx配置 加入rmpt配置

rtmp {
server {
listen 1935;
chunk_size 4096;

application live {
live on;
record off;
}
application live360p {
live on;
record off;
}
}
}

 

添加stat查看相关的配置项

server {

        listen       60010;

        server_name  localhost;

        #charset koi8-r;

 

        #access_log  logs/host.access.log  main;

 

        location / {

            root   html;

            index  index.html index.htm;

        }

 

        location /stat {

            rtmp_stat all;

            rtmp_stat_stylesheet stat.xsl;

        }

        location /stat.xsl {

            root html;

        }

        location /hls { 

            #server hls fragments 

            types{ 

                application/vnd.apple.mpegurl m3u8; 

                video/mp2t ts; 

            } 

            alias temp/hls; 

            expires -1; 

        }

 

配置完成  重启nginx

 

3.使用ffmpeg推流

windows平台 下载http://ffmpeg.org/documentation.html的static包

将解压后的目录中bin目录添加到环境变量

cmd 输入

ffmpeg -stream_loop -1 -re -i rtsp://winIp/media/video/Dubai.mkv -acodec copy -vcodec libx264  -f flv rtmp://unbuntuIp:1935/live/video1

其中:

rtsp://winIp/media/video/Dubai.mkv为使用vlc播出的流

rtmp://unbuntuIp:1935/live/video1为推向ngix-rtmp服务的流

命令执行后 无报错及执行成功

 

使用

播放流 cmd 输入命令 ffmpeg -i rtmp://unbuntuIp:1935/live/video1 

播出成功。

 

 

===================

如果是centos7.5

启动脚本:

[root@~]# cat /lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 然后使用命令:

 systemctl enable nginx.service

 systemctl start nginx.service

查看启动情况

转载于:https://www.cnblogs.com/apache11/p/10076406.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值