流媒体服务器

市面上优秀的流媒体服务器解决方案有很多,比如SRS,Red5,EasyDarwin,nginx-rtmp,live555,mediasoup等等。

这些服务器框架各有优缺点,没有一款完美的流媒体服务器解决方案,在流媒体选型的时候,需要根据自己的业务选择适合的流媒体服务器。

nginx-rtmp的部署

RTMP是Real Time Messaging Protocol(实时消息传输协议)的首字母缩写。该协议基于TCP,是一个协议族,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种。RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进行音视频和数据通信。支持该协议的软件包括Adobe Media Server/Ultrant Media Server/red5等。RTMP与HTTP一样,都属于TCP/IP四层模型的应用层。

1.下载nginx 和 nginx-rtmp-module

https://nginx.org/en/download.htmlhttps://github.com/arut/nginx-rtmp-module.git

2.解压压缩包

$tar xvf nginx-1.20.1.tar.gz$unzip nginx-rtmp-module-master.zip

3.创建build目录

$cd nginx-1.20.1$mkdir build

4.config & make & make install

$./configure --prefix=/home/fly/work/nginx-rtmp/nginx-1.20.1/build --add-module=/home/fly/work/nginx-rtmp/nginx-rtmp-module-master$make$make install

5.config过程中错误及错误处理

error : ./configure: error: the HTTP rewrite module requires the PCRE library.error :./configure: error: SSL modules require the OpenSSL library.error :./configure: error: the HTTP gzip module requires the zlib library.​​
sudo apt-get updatesudo apt-get install libpcre3 libpcre3-devsudo apt-get install openssl libssl-devsudo apt-get install zlib1g-dev​​​​​​​

6.配置文件:/home/fly/work/nginx-rtmp/nginx-1.20.1/build/conf/nginx.conf​​​​​​​

rtmp {    server {        listen 1935;        chunk_size 4096;
        # live on        application rtmp_live {            live on;            # hls on; #这个参数把直播服务器改造成实时回放服务器。            # wait_key on; #对视频切片进行保护,这样就不会产生马赛克了。            # hls_path ./sbin/html; #切片视频文件存放位置。            # hls_fragment 10s;     #每个视频切片的时长。            # hls_playlist_length 60s;  #总共可以回看的时间,这里设置的是1分钟。            # hls_continuous on; #连续模式。            # hls_cleanup on;    #对多余的切片进行删除。            # hls_nested on;     #嵌套模式。        }
        # play videos        application rtmp_play{            play ./videos;  #build directory        }    }}

7.启动 nginx

~/home/fly/work/nginx-rtmp/nginx-1.20.1/build$ sudo ./sbin/nginx

8.ffmpeg推流

ffmpeg -i test.flv -vcodec libx264 -acodec aac -f flv rtmp://192.168.2.128:1935/rtmp_live/mystream

9.VLC拉流(直播、点播)​​​​​​​

直播:rtmp://192.168.2.128:1935/rtmp_live/mystream点播:rtmp://192.168.2.128:1935/rtmp_play/test.flv

SRS的部署

1.下载srs源码

https://github.com/ossrs/srs/releases

2.解压压缩包

$tar xvf srs-3.0-r8.tar.gz

3.创建build目录​​​​​​​

$cd srs-3.0-r8/trunk/$mkdir build

4.config & make & make install​​​​​​​

$./configure --prefix=/home/fly/work/srs/srs-3.0-r8/trunk/build --full$make$make install​​​​​​​

5.make过程中出现错误及解决方法​​​​​​​

In file included from ../../../objs/gtest/include/gtest/internal/gtest-port.h:197:0,                 from ../../../objs/gtest/include/gtest/internal/gtest-internal.h:40,                 from ../../../objs/gtest/include/gtest/gtest.h:57,                 from ../../../src/utest/srs_utest.hpp:36,                 from ../../../src/utest/srs_utest.cpp:24:/usr/include/c++/7/sstream:300:7: error: ‘struct std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>::__xfer_bufptrs’ redeclared with different access struct __xfer_bufptrs
$./configure --prefix=/home/fly/work/srs/srs-3.0-r8/trunk/build --full --without-utest$make$make install

6.增加配置文件:/home/fly/work/srs/srs-3.0-r8/trunk/build/conf/my_hls.conf​​​​​​​

listen              1935;max_connections     1000;daemon              on;srs_log_tank        file;srs_log_level        error;srs_log_file        ./objs/srs.log;
http_server {    enabled         on;    listen          8081;    dir             ./objs/nginx/html;}
vhost __defaultVhost__ {    hls {        enabled         on;        hls_fragment    10;        hls_window      60;        hls_path        ./objs/nginx/html;        hls_m3u8_file   [app]/[stream].m3u8;        hls_ts_file     [app]/[stream]-[seq].ts;        hls_cleanup     on;        hls_dispose     30;        hls_on_error    continue;        hls_storage     disk;        hls_wait_keyframe       on;        hls_acodec      aac;        hls_vcodec      h264;    }}

7.启动 srs

~/home/fly/work/srs/srs-3.0-r8/trunk/build$sudo ./objs/srs -c ./conf/my_hls.conf

8.ffmpeg推流

ffmpeg -i test.mp4 -vcodec libx264 -acodec aac -f flv rtmp://192.168.2.128:1935/live/index

9.生成的 m3u8 和 ts 文件路径

~/work/srs/srs-3.0-r8/trunk/build/objs/nginx/html/live

10.VLC拉流(rtmp、http)​​​​​​​

rtmp://192.168.2.128:1935/live/indexhttp://192.168.2.128:8081/live/index.m3u8

live555

1.下载live555源码

http://www.live555.com/liveMedia/public/

2.解压​​​​​​​

$tar vxf live.2021.08.24.tar.gz#cd live

3.make​​​​​​​

$./genMakefiles linux-64bit$make

4.启动live555

$cd mediaServer$sudo ./live555MediaServer

5.上传视频

将test.mkv上传至 live/mediaServer目录下

6.播放​​​​​​​

拷贝 live555 生成的 url 地址vlc拉流:rtsp://192.168.2.128:8554/test.mkv

你可能感兴趣的:(音视频入门,服务器,网络,音视频)