音视频入门系列-服务器篇(nginx-rtmp 的部署)

本篇文章,我们详细介绍下使用nginx-rtmp来部署一套流媒体服务器,并用FFmpeg来推流,VLC来拉流。

RTMP是Real Time Messaging Protocol(实时消息传输协议)的首字母缩写。该协议基于TCP,是一个协议族,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种。RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进行音视频和数据通信。支持该协议的软件包括Adobe Media Server/Ultrant Media Server/red5等。RTMP与HTTP一样,都属于TCP/IP四层模型的应用层。

1.下载nginx 和 nginx-rtmp-module

https://nginx.org/en/download.html
https://github.com/arut/nginx-rtmp-module.git

2.解压压缩包

$tar xvf nginx-1.20.1.tar.gz
$unzip nginx-rtmp-module-master.zip

3.创建build目录

$cd nginx-1.20.1
$mkdir build

4.config & make & make install

$./configure --prefix=/home/fly/work/nginx-rtmp/nginx-1.20.1/build --add-module=/home/fly/work/nginx-rtmp/nginx-rtmp-module-master
$make
$make install

5.config过程中错误及错误处理

error : ./configure: error: the HTTP rewrite module requires the PCRE library.
error :./configure: error: SSL modules require the OpenSSL library.
error :./configure: error: the HTTP gzip module requires the zlib library.
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install openssl libssl-dev
sudo apt-get install zlib1g-dev

6.配置文件:/home/fly/work/nginx-rtmp/nginx-1.20.1/build/conf/nginx.conf

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        # live on
        application rtmp_live {
            live on;
            # hls on; #这个参数把直播服务器改造成实时回放服务器。
            # wait_key on; #对视频切片进行保护,这样就不会产生马赛克了。
            # hls_path ./sbin/html; #切片视频文件存放位置。
            # hls_fragment 10s;     #每个视频切片的时长。
            # hls_playlist_length 60s;  #总共可以回看的时间,这里设置的是1分钟。
            # hls_continuous on; #连续模式。
            # hls_cleanup on;    #对多余的切片进行删除。
            # hls_nested on;     #嵌套模式。
        }

        # play videos
        application rtmp_play{
            play ./videos;  #build directory
        }
    }
}

7.启动 nginx

~/home/fly/work/nginx-rtmp/nginx-1.20.1/build$ sudo ./sbin/nginx

8.ffmpeg推流

ffmpeg -i test.flv -vcodec libx264 -acodec aac -f flv rtmp://192.168.2.128:1935/rtmp_live/mystream


9.VLC拉流(直播、点播)

直播:rtmp://192.168.2.128:1935/rtmp_live/mystream
点播:rtmp://192.168.2.128:1935/rtmp_play/test.flv

 音视频入门系列文章已同步在微信公众号(可扫下方二维码关注):八小时码字员

音视频入门系列,同步录制了学习视频,已上传至bilibili(八小时码字员):音视频入门系列(图像、音频、字幕、视频封装格式,FFmpeg、ffplay源码分析,解码、编码、转码,流媒体协议,服务器部署)_哔哩哔哩_bilibili

音视频学习交流QQ群:693316541

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值