使用nginx搭建一个rtmp直播服务器,来实现一天24小时播放音乐的电台


title: 使用nginx搭建一个rtmp直播服务器,来实现一天24小时播放音乐的电台
date: 2023-03-08 16:58:05.588
updated: 2023-03-11 17:38:50.116
url: https://hexo.start237.top/archives/使用nginx搭建一个rtmp直播服务器来实现一天24小时播放音乐的电台
categories:

  • IT技术
    tags:

搭建rtmp服务

https://github.com/TheQuib/dji-obs-stream 参考这个链接。
里面有现成的window下集成好的nginx程序。

使用ffmpeg推流

参考文章
https://xuan-ming.github.io/2020/06/04/ffmpeg/

 ffmpeg -re -i  ./m.wav -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/live/abc

nginx.conf关键配置项

nginx hls配置参考文章
https://blog.csdn.net/Harry_z666/article/details/114984077

worker_processes  1;

events {
   worker_connections  1024;
}

rtmp {
   server {
       listen 1935;
       application live {
           hls on;
           live on;
           interleave on;
           record off;
           hls_path E:/dji-obs-stream-main/Windows/html/hls;
           hls_fragment 5s;		
           hls_playlist_length 15s;
           hls_continuous on; 
           hls_cleanup on;
           hls_nested on;
       }


   }
}

http {
   include       mime.types;
   default_type  application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;

   server {
       listen       80;
       server_name  localhost;

       location / {
           root   html;
           index  index.html index.htm;
       }

       location /hls {
           types {
               application/vnd.apple.mpegurl m3u8;
           }
           alias E:/dji-obs-stream-main/Windows/html/hls;
           expires -1;
           add_header Cache-Control no-cache;
       }


       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }
   }
}

写一个拉流页面


<!DOCTYPE html>
<html lang="en">

<head>
   <title>HTML5 直播</title>

   <head>
       <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.15.2/skins/default/aliplayer-min.css" />

       <script charset="utf-8" type="text/javascript"
           src="https://g.alicdn.com/de/prismplayer/2.15.2/aliplayer-min.js"></script> //(必须)引入js文件。
   </head>

</head>

<body>

   <body>
       <div id="J_prismPlayer"></div>
   </body>
</body>

</html>
<script>
   var player = new Aliplayer({
       id: 'J_prismPlayer',
       format: "hls",
       source: "http://localhost/hls/abc/index.m3u8",
       autoplay: true,
       isLive: true,
   }, function (player) {
       console.log('The player is created.')
   })

   // 也可以使用replayByMediaAuth函数切换不同的mediaAuth播放(前提是已经使用mediaAuth初始化播放器)。
   // player.replayByMediaAuth('another mediaAuth');
</script>

搞定!
这是windows的环境,在linux环境中还要细化,另外还要写脚本来实现把音频循环播放的功能。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值