1. #net-tool 查本地IP
  2. #wget 下载安装包
  3. #unzip 解压zip包
  4. #gcc gcc-c++ perl 编译软件包用
  5. yum install -y net-tools wget unzip gcc gcc-c++ perl
  1. #备份yum源
  2. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  3. #下载阿里源
  4. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  5. #清空缓存
  6. yum makecache

将当前目录切换的 /home

  1. #切换的homme目录
  2. cd /home
  1. #下载pcre包
  2. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
  3. #解压pcre包
  4. tar -zxvf pcre-8.41.tar.gz
  1. #下载zlib包
  2. wget http://www.zlib.net/zlib-1.2.11.tar.gz
  3. #解压zlib包
  4. tar -zxvf zlib-1.2.11.tar.gz
  1. #下载openssl包
  2. wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1i.tar.gz
  3. #解压openssl包
  4. tar -zxvf openssl-1.0.1i.tar.gz
  5. #切换到openssl里
  6. cd openssl-1.0.1i
  7. #生成配置文件 默认配置
  8. ./configure
  9. #编译程序
  10. make
  11. #安装程序
  12. make install
  1. #下载rtmp包
  2. wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
  3. #解压下载包
  4. unzip -o master.zip
  5. #修改文件夹名
  6. mv master nginx-rtmp-module
  1. #下载nginx
  2. wget http://nginx.org/download/nginx-1.12.2.tar.gz
  3. #解压nignx
  4. tar -zxvf nginx-1.12.2.tar.gz
  5. #切换到nginx中
  6. cd nginx-1.12.2
  7. #生成配置文件,将上述下载的文件配置到configure中
  8. ./configure --prefix=/usr/local/nginx --with-pcre=/home/pcre-8.41 --with-zlib=/home/zlib-1.2.11 --with-openssl=/home/openssl-1.0.1i --add-module=/home/nginx-rtmp-module
  9. #编译程序
  10. make
  11. #安装程序
  12. make install
  13. #查看nginx模块
  14. nginx -V
  1. #安装epel包
  2. yum install -y epel-release
  3. #导入签名
  4. rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  5. #导入签名
  6. rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
  7. #升级软件包
  8. rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
  9. #更新软件包
  10. yum update -y
  11. #安装ffmpeg
  12. yum install -y ffmpeg
  13. #检查版本
  14. ffmpeg -version
  1. vi /usr/local/nginx/conf/nginx.conf

修改之后的配置

  1. #工作进程
  2. worker_processes 1;
  3. #事件配置
  4. events {
  5. worker_connections 1024;
  6. }
  7. #RTMP配置
  8. rtmp {
  9. server {
  10. #监听端口
  11. listen 1935;
  12. #
  13. application myapp {
  14. live on;
  15. }
  16. #hls配置
  17. application hls {
  18. live on;
  19. hls on;
  20. hls_path /tmp/hls;
  21. }
  22. }
  23. }
  24. http {
  25. include mime.types;
  26. default_type application/octet-stream;
  27. sendfile on;
  28. keepalive_timeout 65;
  29. gzip on;
  30. server {
  31. listen 80;
  32. server_name localhost;
  33. location / {
  34. root html;
  35. index index.html index.htm;
  36. }
  37. #配置hls
  38. location /hls {
  39. types {
  40. application/vnd.apple.mpegurl m3u8;
  41. video/mp2t ts;
  42. }
  43. root /tmp;
  44. add_header Cache-Control no-cache;
  45. }
  46. error_page 500 502 503 504 /50x.html;
  47. location = /50x.html {
  48. root html;
  49. }
  50. }
  51. }
  1. /usr/local/nginx/sbin/nginx
  1. /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
  1. #查看IP
  2. ifconfig
  3. #在home下上传一个test.mp4视频
  4. #推送rtmp流 下载一个VLC测试
  5. ffmpeg -re -i "/home/test.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://{IP}:1935/myapp/test1
  6. #推送hls流 写个HTML测试
  7. ffmpeg -re -i "/home/test.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://{IP}:1935/hls/test2
  1. <script src="https://cdn.jsdelivr.net/hls.js/latest/hls.min.js"></script>
  2. <video id="video"></video>
  3. <script>
  4. if(Hls.isSupported()) {
  5. var video = document.getElementById(\'video\');
  6. var hls = new Hls();
  7. hls.loadSource(\'http://{IP}/hls/test2.m3u8\');
  8. hls.attachMedia(video);
  9. hls.on(Hls.Events.MANIFEST_PARSED,function() {
  10. video.play();
  11. });
  12. }
  13. </script>

四、然后就开始推流啦

  配好后就用推流软件啦,我用的是OBS,按照OBS操作就可以 啦!

 

在设置->串流 中填写信息:URL为 rtmp://xxx:1935/hls,xxx为你的服务器的IP地址,hls是用来存放流媒体的。

秘钥可以随便填写一个,用来播放的时候识别播放哪个流媒体的,例如填写test等。

填写完毕后,点击开始串流,就说明我们的流媒体服务器搭建成功了。

 

五、看直播

  如果是mac直接浏览器可以访问http://xxx:81/hls/test.m3u8来观看直播,其中xxx为你的服务器IP地址,

  手机端直接访问文件也可以看!

  然后其他的H5的vadio需要下载支持m3u8格式的播放啦,我是在https://github.com/huangyaoxin/hLive这下的,挺好用的!找了好多不行,这个可以!

 

 六、看直播肯定会很卡  

        如果降低延迟也不是没有方法,可以设置切片生成的大小以及访问的速度,但是这样大大增加了服务器的压力。

       当然,我们也可以用rtmp拉流工具(VLC等)来看该直播,延迟大概在2-5S左右,拉流地址与推流地址一致。

版权声明:本文为caicaizi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/caicaizi/p/10241817.html