【直播】nginx搭建rtmp流直播环境

By Heanny
2020-05-06
2436 read

环境搭建

windows

windows下很容易搭建,只需要下载nginx-1.7.11.3-Gryphon就可以了,解压之后运行run_ngnix.bat
能力强的同学自己编译最新版本nginx并使用吧

centos

只在centos下测试了,其他Linux环境基本相同

安装环境,有的略过

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

下载nginx-1.17.10,然后下载nginx-rtmp-modulegit clone https://github.com/arut/nginx-rtmp-module.git
解压nginx,将nginx-rtmp-module放到nginx里面

然后configure

./configure --prefix=/usr/local/nginx  --add-module=./nginx-rtmp-module  --with-http_ssl_module

http2协议可添加

--with-http_stub_status_module --with-http_v2_module

然后make && make install

make的时候可能会报错

如果错误如下,则将文件objs/Makefile里面的-Werror删除即可

html5播放rtmp

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
    <title>HTML5 直播</title>
    <link href="http://vjs.zencdn.net/5.19/video-js.min.css" rel="stylesheet">
    <script src="http://vjs.zencdn.net/5.19/video.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/videojs-flash@2/dist/videojs-flash.min.js"></script>
</head>
<body>
        <video id="myvideo" class="video-js vjs-default-skin" controls preload="auto"
                width="1280" height="720" poster="http://vjs.zencdn.net/v/oceans.png" data-setup="{}">
            <source src="rtmp://127.0.0.1:1935/livetv/1234" type="rtmp/flv">
            //src里面填的是rtmp的地址rtmp://192.168.0.221/live跟密钥1234
            <p class="vjs-no-js">
            To view this video please enable JavaScript, and consider upgrading to a web browser that
                       <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
            </p>
        </video>
</body>

</html>

其他rtmp源

1.香港财经
香港财经,rtmp://202.69.69.180:443/webcast/bshdlive-pc(推荐,信号好不卡顿)
2.湖南卫视(推荐)
湖南卫视,rtmp://58.200.131.2:1935/livetv/hunantv (实测可用)
3.hls地址
http://playertest.longtailvideo.com/adaptive/bipbop/gear4/prog_index.m3u8
https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8
http://live.hkstv.hk.lxdns.com/live/hks/playlist.m3u8 (香港卫视)

ffmpeg使用

1.windows下载:
ffmpeg
2.centos7:
Install the Nux Dextop YUM repo

rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm
yum install ffmpeg ffmpeg-devel -y

3.centos8

yum install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
yum install http://rpmfind.net/linux/epel/7/x86_64/Packages/s/SDL2-2.0.10-1.el7.x86_64.rpm
yum install ffmpeg ffmpeg-devel -y

将视频推送到rtmp

ffmpeg.exe -re -i "1.mp4" -vcodec copy -acodec aac -f flv "rtmp://192.168.8.120:1935/live/1234"
#添加文字
ffmpeg -re -i "{video}" -vf drawtext=fontcolor=red:fontsize=25:fontfile=font.ttf:text="喜欢的话点个关注,喂点小礼物,本直播间支持点播":x=80:y=10 -c:v libx264 -crf 30 -f flv "rtmp://192.168.8.120:1935/live/1234"
【直播】使用python控制b站直播视频
centos引入cv2报错No such file or directory

Comments

Heanny #1

我的直播间:https://live.bilibili.com/178604
点播平台:http://live.heanny.cn

Leave a Reply