ubuntu系统入门教程-搭建Ngnix和RTMP 流媒体服务器
文章说明
- 介绍如何在ubuntu下搭建基于Ngnix和RTMP的流媒体服务器
步骤
- 安装相关软件
sudo apt update
sudo apt install -y libnginx-mod-rtmp
sudo apt install -y ffmpeg
sudo apt install -y nginx
- 配置 Nginx
- 修改/etc/nginx/nginx.conf
#http上面加rtmp 部分
rtmp {
server {
listen 1935;
application live {
live on;
hls on; # 开启 HLS
hls_path /var/www/html/hls; # 存储 HLS 切片的目录
hls_fragment 3s; # 每个切片的时长
hls_playlist_length 60s; # 播放列表的时长
}
}
}
#http 里面加server部分
http {
server {
listen 80;
server_name localhost;
location /hls/ {
root /var/www/html/;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *; # 允许跨域访问
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; # 允许请求方法
add_header Access-Control-Allow-Headers 'Origin, X-Requested-With, Content-Type, Accept, Range'; # 允许请求头
try_files $uri $uri/ =404;
}
}
......
......
- 测试推流
ffmpeg -re -i /dev/video0 -c:v libx264 -preset fast -b:v 2500k -c:a aac -b:a 128k -f flv rtmp://localhost/live/stream
测试查看
- 利用vlc订阅网络串流
rtmp://localhost/live/stream
- 利用ffmpeg查看,订阅保存30秒视频为flv文件,再通过vlc打开就可以
ffmpeg -i rtmp://localhost/live/stream -t 30 -c copy output.flv
vlc output.flv
- 利用vlc订阅网络串流
http://localhost/hls/stream.m3u8
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号