设为首页 收藏本站
查看: 1055|回复: 0

[经验分享] nginx rtmp模块 实现hls

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-8 09:05:20 | 显示全部楼层 |阅读模式
nginx rtmp  ffmpeg 组合模仿hls直播

前几天老总说搞了一个局域网内的直播,想到了之前提到的rtmp模块,抱着试试看的的心态 开干了

系统环境:
1
2
3
4
[iyunv@localhost html]# uname -a
Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 athlon i386 GNU/Linux
[iyunv@localhost html]# getconf LONG_BIT
32




NGINX环境:
1、nginx下载地址:
http://nginx.org/download/
本测试环境系统版本是1.4.7

2、nginx模块rtmp下载地址
https://github.com/arut/nginx-rtmp-module/archive/master.zip

3、多媒体视频处理工具→ffmpeg下载地址
http://ffmpeg.org/releases/ffmpeg-2.6.1.tar.bz2

首先解释一些东西
rtmp:RTMP(Real Time Messaging Protocol)实时消息传送协议是Adobe Systems公司为Flash播放器和服务器之间音频、视频和数据传输 开发的开放协议。
然后nginx的rtmp模块
战斗民族俄罗斯人民开发的一款NGINX的流媒体插件,除了直播发布音视频流之外具备流媒体服务器的常见功能
比如推拉流媒体资源
基于HTTP的FLV/MP4 VOD点播
HLS (HTTP Live Streaming) M3U8的支持
基于http的操作(发布、播放、录制)
可以很好的协同现有的流媒体服务器以及播放器一起工作
在线调用ffmpeg对流媒体进行转码
H264/AAC音视频编码格式的支持
linux/BSD/MAC系统的支持
(来自于网络)


安装步骤、
nginx安装
下载好rtmp模块
1
2
3
4
5
6
7
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip  master.zip
wget http://nginx.org/download/nginx-1.4.7.tar.gz
tar xvf nginx-1.4.7.tar.gz
cd nginx-1.4.7
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module  --add-module=/usr/local/src/nginx-rtmp-module-master  --with-pcre=/usr/local/src/pcre-8.11
make;make install




ffmpeg安装
1
2
3
wget http://ffmpeg.org/releases/ffmpeg-2.6.1.tar.bz2
tar xvf ffmpeg-2.6.1.tar.bz2
cd ffmpeg-2.6.1



在这一个编译的话肯定是会报错的 具体报什么错就是说缺乏东西,需要安装yasm
1
2
3
4
5
6
7
8
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make;make install
cd ffmpeg-2.6.1
./configure
make; make instal



l



改装的东西都装好了,现在来改改配置文件
nginx的配置文件需要换一换了 nginx rtmp的模块里面有一个nginx的主配置文件
[
1
2
3
4
5
6
7
8
9
10
11
root@localhost test]# pwd
/usr/local/src/nginx-rtmp-module-master/test
[iyunv@localhost test]# ll
total 56
-rwxr-xr-x 1 root root   49 Mar 24 03:30 dump.sh
-rwxr-xr-x 1 root root   84 Mar 24 03:30 ffstream.sh
-rw-r--r-- 1 root root 1245 Mar 24 03:30 nginx.conf
-rwxr-xr-x 1 root root   59 Mar 24 03:30 play.sh
-rw-r--r-- 1 root root  499 Mar 24 03:30 README.md
drwxr-xr-x 2 root root 4096 Mar 24 03:30 rtmp-publisher
drwxr-xr-x 4 root root 4096 Mar 24 03:30 www



将上面的主配置文件拷贝到nginx目录就好

nginx主配置文件如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
worker_processes  1;
error_log  logs/error.log debug;
events {
    worker_connections  1024;
}
rtmp {
    server {
        listen 1936;
        application myapp {
            live on;
            #record keyframes;
            #record_path /tmp;
            #record_max_size 128K;
            #record_interval 30s;
            #record_suffix .this.is.flv;
            #on_publish http://localhost:8080/publish;
            #on_play http://localhost:8080/play;
            #on_record_done http://localhost:8080/record_done;
        }
    }
}
rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        #HLS
        application hls {
            live on;
            hls on;
            hls_path /usr/local/nginx/html/hls;
            hls_fragment 5s;
        }
    }
}
http {
    server {
        listen  8080;
        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root html;
            expires -1;
        }
    }
}
http {
    server {
        listen      8081;
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root /html/nginx-rtmp-module/;
        }
        location /control {
            rtmp_control all;
        }
        #location /publish {
        #    return 201;
        #}
        #location /play {
        #    return 202;
        #}
        #location /record_done {
        #    return 203;
        #}
        #location /rtmp-publisher {
        #    root /html/nginx-rtmp-module/test;
       # }
        location / {
            root /html/nginx-rtmp-module/test/www;
        }
    }
}




上传一个flv格式的文件到html目录
执行
1
ffmpeg -re -i sample.flv -vcodec copy -acodec copy -f flv rtmp://192.168.3.105/hls/mystream



然后页面观看地址
http://192.168.3.105:8080/hls/mystream.m3u8



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-54858-1-1.html 上篇帖子: keepalived+nginx 下篇帖子: nginx增加modsecurity模块
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表