Nginx搭建RTMP服务器
1 分钟 6443 字 |
Nginx搭建RTMP服务器
转RTMP/HLS(学习)
1 安装nginx
- 拉取镜像(定制版):
docker pull alqutami/rtmp-hls
- 启动:
docker run -d -p 1935:1935 -p 8080:8080 alqutami/rtmp-hls
- 自定义配置:
docker run -d --name rtmp -p 1935:1935 -p 8080:8080 -v ~/Documents/nginx-1.19.2/conf/nginx.conf:/etc/nginx/nginx.conf alqutami/rtmp-hls
2 配置文件
自带,无需更改
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
# ping 30s;
# notify_method get;
# This application is to accept incoming stream
application live { # live为rtmp服务器应用名,用在推流rtmp://localhost:1935/live/cam01
live on; # Allows live input
# for each received stream, transcode for adaptive streaming
# This single ffmpeg command takes the input and transforms
# the source into 4 different streams with different bitrates
# and qualities. # these settings respect the aspect ratio.
exec_push /usr/local/bin/ffmpeg -i rtmp://localhost:1935/$app/$name -async 1 -vsync -1
-c:v libx264 -c:a aac -b:v 256k -b:a 64k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_low
-c:v libx264 -c:a aac -b:v 768k -b:a 128k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_mid
-c:v libx264 -c:a aac -b:v 1024k -b:a 128k -vf "scale=960:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_high
-c:v libx264 -c:a aac -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_hd720
-c copy -f flv rtmp://localhost:1935/show/$name_src;
drop_idle_publisher 10s;
}
# This is the HLS application
application show { # show为http服务器应用名,用在推流rtmp://localhost:1935/show/cam01
live on; # Allows live input from above application
deny play all; # disable consuming the stream from nginx as rtmp
hls on; # Enable HTTP Live Streaming
hls_fragment 3;
hls_playlist_length 20;
hls_path /mnt/hls/; # hls fragments path
# Instruct clients to adjust resolution according to bandwidth
hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
hls_variant _hd720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution
hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution
# MPEG-DASH
dash on;
dash_path /mnt/dash/; # dash fragments path
dash_fragment 3;
dash_playlist_length 20;
}
}
}
3 转流
//rtsp --> rtmp
ffmpeg -re -i rtsp://admin:qwe123qwe@10.18.30.218:554/h264/ch1/main/av_stream -c copy -f flv rtmp://localhost:1935/live/cam01
//rtsp --> hls
ffmpeg -re -i rtsp://admin:qwe123qwe@10.18.30.218:554/h264/ch1/main/av_stream -c copy -f flv rtmp://localhost:1935/show/cam01
4 访问
RTMP流:rtmp://localhost:1935/live/cam01
转RTMP/HTTP-FLV(采用)
安装
docker pull rebaltair/nginx-http-flv-module(基于alqutami/rtmp-hls)
运行
docker run -idt -p 8080:9000 -p 1935:1935 rebaltair/nginx-http-flv-module
推流
ffmpeg -re -i rtsp://admin:qwe123qwe@10.18.30.183:554/h264/ch1/main/av_stream -c copy -f flv rtmp://localhost:1935/live/[stream]
访问
- rtmp://ip[:port]/live/[stream]
- http://ip:8080/live?app=live&stream=[stream]
参考
[ 1 ] https://github.com/mugennsou/http-flv/blob/master/README_CN.md
[ 2 ] https://github.com/TareqAlqutami/rtmp-hls-server
[ 3 ] https://bbs.huaweicloud.com/blogs/314023
[ 4 ] https://www.cnblogs.com/xuey/p/9244434.html
[ 5 ] JavaCV
~ ~ The End ~ ~
分类标签:技术,nginx
文章标题:Nginx搭建RTMP服务器
文章链接:http://120.46.217.131:82/archives/61/
最后编辑:2023 年 5 月 16 日 16:23 By Yang
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
文章标题:Nginx搭建RTMP服务器
文章链接:http://120.46.217.131:82/archives/61/
最后编辑:2023 年 5 月 16 日 16:23 By Yang
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)