五、配置Nginx, 实现LIVE、以RTMP方式进行直播
1. 配置conf/nginx.conf
...
rtmp {
server {
listen 1935;
chunk_size 4000;
application vod {
play /opt/pub/media/nginx/web/vod;
}
# Setting for LIVE
application live {
live on;
}
}
}
http
{
...
# LIVE and VOD by RTMP
server
{
listen 8080;
location /stat
{
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl
{
root /opt/nginx_http_rtmp/nginx-rtmp-module/;
}
}
}
2. 重新加载Nginx
# /opt/nginx/sbin/nginx -s reload
3. 准备网页 rtmp_live.html
下载播放器jwplayer,并新建网页
<html>
<head>
<script src="/smzy_jwplayer_v6.6/jwplayer.js"></script>
</head>
<body>
<div id='my-video'></div>
<script type='text/javascript'>
jwplayer('my-video').setup({
file:'rtmp://192.168.1.4/live/test',
width:'50%',
aspectratio:'3:2',
fallback:'false',
primary:'flash'
});
</script>
</body>
</html>
4. 在浏览器输中输入
http://10.2.175.10/rtmp_live.html
5. 使用ffmpeg推流
用ffmpeg产生一个模拟直播源,向rtmp服务器推送
# ./ffmpeg –i/usr/local/nginx/vod/flvs/a.flv-strict -2 -c:v libx264 -c:a aac -f flv rtmp://192.168.1.4/live/test
注意,
源文件必须是H.264+AAC编码的。
192.168.1.4是运行nginx的服务器IP,
live是applicatioin,
test是直播缓存流文件,需要与配置文件中的直播缓存文件名一样。
六、配置Nginx 支持HLS
暂时没有做测试,可见其它网文;
1. 配置conf/nginx.conf
...
rtmp {
server {
listen 1935;
chunk_size 4000;
application vod {
play /opt/pub/media/nginx/web/vod;
}
# Setting for LIVE
application live {
live on;
}
}
}
http
{
...
# LIVE and VOD by RTMP
server
{
listen 8080;
location /stat
{
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl
{
root /opt/nginx_http_rtmp/nginx-rtmp-module/;
}
}
}
2. 重新加载Nginx
# /opt/nginx/sbin/nginx -s reload
3. 准备网页 rtmp_live.html
下载播放器jwplayer,并新建网页
<html>
<head>
<script src="/smzy_jwplayer_v6.6/jwplayer.js"></script>
</head>
<body>
<div id='my-video'></div>
<script type='text/javascript'>
jwplayer('my-video').setup({
file:'rtmp://192.168.1.4/live/test',
width:'50%',
aspectratio:'3:2',
fallback:'false',
primary:'flash'
});
</script>
</body>
</html>
4. 在浏览器输中输入
http://10.2.175.10/rtmp_live.html
5. 使用ffmpeg推流
用ffmpeg产生一个模拟直播源,向rtmp服务器推送
# ./ffmpeg –i/usr/local/nginx/vod/flvs/a.flv-strict -2 -c:v libx264 -c:a aac -f flv rtmp://192.168.1.4/live/test
注意,
源文件必须是H.264+AAC编码的。
192.168.1.4是运行nginx的服务器IP,
live是applicatioin,
test是直播缓存流文件,需要与配置文件中的直播缓存文件名一样。
六、配置Nginx 支持HLS
暂时没有做测试,可见其它网文;
配置Nginx进行实时流媒体直播与HLS支持
本文详细介绍了如何配置Nginx实现实时流媒体直播(RTMP方式),包括设置conf/nginx.conf文件,配置Live与VOD服务,以及准备网页播放器实现直播预览。同时,文章还指导了如何启用HLS支持,为不同需求提供全面的流媒体解决方案。
1845

被折叠的 条评论
为什么被折叠?



