博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx实现rtmp,flv,mp4流媒体服务器
阅读量:5972 次
发布时间:2019-06-19

本文共 7622 字,大约阅读时间需要 25 分钟。

hot3.png

过了个年,突然忘了很多事情,可能我真是上了年龄。

一.安装编译时说需要的扩展

yum install automake autoconf make gcc gcc-c++

 

二.安装nginx-rtmp-module

2.1第一种方式比较简单

yum install pcre pcre-devel  yum install zlib zlib-devel  yum install openssl openssl--devel

然后下载nginx,nginx-rtmp-module模块,并解压

git clone https://github.com/arut/nginx-rtmp-module.git
 wget http://nginx.org/download/nginx-1.7.4.tar.gz 

解压略(我们这里假定解压目录在 /usr/tmp中)

注册并安装nginx

cd nginx-1.7.4#../configure --prefix=/usr/local/nginx --with-http_stub_status_module[可选] --with-http_ssl_module[可选] --with-http_gzip_static_module[可选] --with-http_flv_module[可选] --with-http_mp4_module  [可选]--add-module=/usr/tmp/nginx-rtmp-module-master#make#make install

注:如果使用flv,MP4点播的话,要注意nginx 1.1.3之后已经默认支持mp4,flv模块,无须第三方模块支持,如果这里不配置,那么mp4和flv视频点播播放将会很慢

2.2第二种方式

需要下载的阔扩展():

   1. wget http://www.openssl.org/source/openssl-0.9.8l.tar.gz (系统默认带有openssl)   2. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.00.tar.bz2   3. wget http://www.zlib.net/zlib-1.2.3.tar.bz2   4. git clone https://github.com/arut/nginx-rtmp-module.git   5. wget http://nginx.org/download/nginx-1.7.4.tar.gz 

把这些玩意都缩后,就会有(假定解压目录/usr/tmp/):

   1. openssl-0.9.8l   2. pcre-8.00   3. zlib-1.2.3   4. nginx-rtmp-module-master   5. nginx-1.7.4

注册并安装nginx

cd nginx-1.7.4#./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module  --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-pcre=/usr/tmp/pcre-8.00 --with-openssl=/usr/tmp/openssl-0.9.8l --with-http_ssl_module --with-zlib=/usr/tmp/zlib-1.2.3 --add-module=/usr/tmp/nginx-rtmp-module#make#make install

三.配置nginx.conf

rtmp {    server {        listen 1935;        chunk_size 4000;        # TV mode: one publisher, many subscribers 电视直播模式,1对多        application mytv {            # enable live streaming            live on;            # record first 1K of stream            record all;            record_path /tmp/av;            record_max_size 1K;            # append current timestamp to each flv            record_unique on;            # publish only from localhost            allow publish 127.0.0.1;            deny publish all;            #allow play all;        }        # Transcoding (ffmpeg needed)        application big {            live on;           #将推过来的媒体文件流转码至small            exec ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec flv -acodec copy -s 32x32                        -f flv rtmp://localhost:1935/small/${name};        }        application small {            live on;             # Video with reduced resolution comes here from ffmpeg        }        application webcam {            live on;            # Stream from local webcam            exec_static ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an                               -f flv rtmp://localhost:1935/webcam/mystream;        }        application mypush {            live on;            # Every stream published here            # is automatically pushed to            # these two machines            push rtmp1.example.com;            push rtmp2.example.com:1934;        }        application mypull {            live on;#拉流            # Pull all streams from remote machine            # and play locally            pull rtmp://rtmp3.example.com pageUrl=www.example.com/index.html;        }        application mystaticpull {            live on;            # Static pull is started at nginx start            pull rtmp://rtmp4.example.com pageUrl=www.example.com/index.html name=mystream static;        }        # video on demand#点播        application vod {            play /var/flvs;        }             application vod2 {            play /var/mp4s;        }        # Many publishers, many subscribers        # no checks, no recording#视频聊天        application videochat {            live on;            # The following notifications receive all            # the session variables as well as            # particular call arguments in HTTP POST            # request            # Make HTTP request & use HTTP retcode            # to decide whether to allow publishing            # from this connection or not            on_publish http://localhost:8080/publish;            # Same with playing            on_play http://localhost:8080/play;            # Publish/play end (repeats on disconnect)            on_done http://localhost:8080/done;            # All above mentioned notifications receive            # standard connect() arguments as well as            # play/publish ones. If any arguments are sent            # with GET-style syntax to play & publish            # these are also included.            # Example URL:            #   rtmp://localhost/myapp/mystream?a=b&c=d            # record 10 video keyframes (no audio) every 2 minutes            record keyframes;            record_path /tmp/vc;            record_max_frames 10;            record_interval 2m;            # Async notify about an flv recorded            on_record_done http://localhost:8080/record_done;        }        # HLS        # For HLS to work please create a directory in tmpfs (/tmp/hls here)        # for the fragments. The directory contents is served via HTTP (see        # http{} section in config)        #        # Incoming stream must be in H264/AAC. For iPhones use baseline H264        # profile (see ffmpeg example).        # This example creates RTMP stream from movie ready for HLS:        #        # ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264        #    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1        #    -f flv rtmp://localhost:1935/hls/movie        #        # If you need to transcode live stream use 'exec' feature.        #        application hls {            live on;            hls on;            hls_path /tmp/hls;        }        # MPEG-DASH is similar to HLS        application dash {            live on;            dash on;            dash_path /tmp/dash;        }    }}# HTTP can be used for accessing RTMP statshttp {    server {        listen      8080;        # This URL provides RTMP statistics in XML        location /stat {            rtmp_stat all;            # Use this stylesheet to view XML as web page            # in browser            rtmp_stat_stylesheet stat.xsl;        }        location /stat.xsl { #状态文件            # XML stylesheet to view RTMP stats.            # Copy stat.xsl wherever you want            # and put the full directory path here            root /path/to/stat.xsl/; #注意root指令的用法        }        location /hls {            # Serve HLS fragments 支持Hls直播,注意,nginx本身支持hls点播,这里是直播            types {                application/vnd.apple.mpegurl m3u8;                video/mp2t ts;            }            root /tmp;            add_header Cache-Control no-cache;        }        location /dash {            # Serve DASH fragments            root /tmp;            add_header Cache-Control no-cache;        }    location ~ \.flv$                      ---------匹配flv文件     {         flv;     }       location ~ \.mp4$                    ----------匹配mp4文件     {      mp4; #    mp4_buffer_size    1m;        #    mp4_max_buffer_size  5m;      limit_rate_after 5m;                ---------下载5m后再限速      limit_rate 100k;                    ----------限速100k #    limit_conn perip 1;     }    }}

 四.安装到此结束,其

中有个big->small转换有些问题,需要安装ffmpeg才行,如果要装ffmpeg请参考

 

五.附录

 

 

nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器

http://blog.csdn.net/redstarofsleep/article/details/45092147
http://www.cnblogs.com/cheng5x/p/5646920.html
http://blog.creke.net/801.html

转载于:https://my.oschina.net/ososchina/blog/833909

你可能感兴趣的文章
mac平台安装类似yum的工具
查看>>
PHP多种序列化/反序列化的方法(serialize和unserialize函数)
查看>>
python开发_difflib字符串比较
查看>>
被解放的姜戈01 初试天涯
查看>>
mongodb基本数据类型
查看>>
三极管工作区在Spectre中的表示
查看>>
HT for Web的HTML5树组件延迟加载技术实现
查看>>
ASP.NET MVC 3 Razor Nested foreach with if statements
查看>>
【Mysql】命令行
查看>>
Asterisk 安装与配置
查看>>
SQL2008-中不想插入从复记录
查看>>
.Net基础
查看>>
AES加密算法原理
查看>>
《Programming WPF》翻译 第8章 4.关键帧动画
查看>>
iOS UI基础-16.0 UIButton
查看>>
屏蔽各大视频网站播放前15秒30秒广告
查看>>
进入TP-Link路由器之后利用快捷键F12查看星号路由密码的方法
查看>>
linux内核的oops
查看>>
iOS - OC 语言新特性
查看>>
基于Token的WEB后台认证机制
查看>>