linux下编译与运行crtmpserver

18 篇文章 2 订阅
4 篇文章 0 订阅

目录

前言

环境准备及编译

测试


前言

RTMP是Real Time Messaging Protocol(实时消息传输协议)的首字母缩写。该协议基于TCP,是一个协议族,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种。RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进行音视频和数据通信。——摘录自百度。 如果大家想对RTMP有更深的认识,可以参看这篇文章:《带你吃透RTMP》。

本文要处理的是:用crtmpserver搭建服务器,用来做推拉流的中转。也就是ffmpeg推流到crtmpserver服务器,然后VLC从服务器拉流播放。那么这个服务器怎么搭建呢,下面就详细的记录一下。

 

环境准备及编译

1、win10上,装VMWare Workstation, 然后安装Ubuntu16.04

2、准备各种工具,看看是否需要更新。

// 如果没有cmake, 那就安装
apt-get install wget cmake

// 如果没有libssl-dev , 通信用到的库, 就先安装
apt-get install libssl-dev 

3、 准备文件并编译

// 新建一个文件夹
mkdir crtmp

// 进入这个文件夹
cd ctrmp

// 然后下载文件:
wget https://codeload.github.com/j0sh/crtmpserver/zip/centosinit

// 解压
unzip centosinit

// 得到 crtmpserver-centosinit, 进入这个文件夹
cd crtmpserver-centosinit

// 进入到builder
cd builders

// 进入到cmake
cd cmake

// 可以看到这里有Makefile文件,执行
cmake
make

// 编译完之后,执行下面这句话,就可以执行了
./crtmpserver/crtmpserver ./crtmpserver/crtmpserver.lua

// 在上面那句话执行的过程中,不要中断,就可以进行测试了。
// 如果想要结束,直接ctrl+c ,就能中断

 

测试

方式一:

准备好我们下载的ffmpeg—shared版本,进入bin,找到 ffmpeg.exe, 在这个文件中放一个flv文件。

然后在这个文件夹的目录栏中,输入 cmd, 进入命令行:

ffmpeg  -i China.flv  -f flv rtmp://192.168.87.6/live/test1

打开VLC, 媒体——>打开网络串流,输入:rtmp://192.168.87.6/live/test1, 播放。

可以看到推流的文件,进行播放了。

 

方式二:

准备好ffmpeg-dev版本,建一个win32的控制台工程,将include lib dll等,都包含进去。然后写代码,把文件读入,进行推流。拉流依然用VLC。

播放文件推流:推流端需要控制进度、速度。根据文件的fps进行控制。这一部分,还是需要特别注意的。

《代码》

C++ RTMP Server Instructions how to compile and use C++ RTMP Server (a.k.a crtmpserver) Requirements: * GCC and other C++ tools * SVN * libdl, libssl, libcrypto (make sure you have the "devel" packages of libdl, ssl and crypto installed prior to compiling) In order to get the source code, issue the following command: svn co --username anonymous https://svn.rtmpd.com/crtmpserver/trunk crtmpserver When it asks for password, hit Enter key Compile the package. Do the following steps: cd crtmpserver/builders/cmake cmake . (this step will create all the Makefile's that are required. If some package is missing, the cmake will complain) make The compilation procedure should be finished within few minutes. After you compiled the package, it's time to test it. Run the following command: ./crtmpserver/crtmpserver crtmpserver/crtmpserver.lua If everything goes well, you'll get on your console a table with IP's, ports, protocols, and application names If you see this table, then crtmpserver is working. Lets test it the server. Follow these simple steps: * Download a simple FLV or MP4 file. You can dowload a sample file from here: http://www.mediacollege.com/adobe/flash/video/tutorial/example-flv.html * Place the file you downloaded into the crtmpserver/media folder * Download an FLV player. For this example, we'll use JW Player. Get it here: http://www.longtailvideo.com/players/jw-flv-player * Extract the JW Player to a directory which is accessible through your web server * Go to the extracted directory and create an HTML file which will include the player and play the file. Here's an example: <html> <body> <script type='text/javascript' src='swfobject.js'></script> <div id='mediaspace'>This text will be replaced</div> <script type='text/javascript'> var so = new SWFObject('player.swf','mpl','640','360','9'); so.addParam('allowfullscreen','true'); so.addParam('allowscriptaccess','always'); so.addParam('wmode','opaque'); so.addVariable('file','file-download'); so.addVariable('streamer','rtmp://127.0.0.1/flvplayback/'); so.write('mediaspace'); </script> </body> </html> * Change the 127.0.0.1 to either the IP of your crtmpserver or simply use a hostname of your machine * Replace file-download with the actual filename of your sample you download. Remeber to omit the .flv if it's an FLV file * Open a web browser and point it to to the web server IP/Hostname and the directory you installed the player (example: http://127.0.0.1/player) * You should see a player. Click the play button and the video should be played. If you see the video, then everything works well. Installing crtmpserver: * Go to the directory crtmpserver/cmake * Run the following command: cmake -DCRTMPSERVER_INSTALL_PREFIX=<path> (for example /usr/local/crtmpserver) * After previous command done start build project with command: make * After build comlete run command: make install * After install you has installed crtmpserver in <path>(in our case /usr/local/crtmpserver) * Now you can start crtmpserver with command: sudo <path>/sbin/crtmpserver --uid=<UID> <path>/etc/crtmpserver.lua in our case: sudo /usr/local/crtmpserver/sbin/crtmpserver --uid=<UID> /usr/local/crtmpserver/etc/crtmpserver.lua Also look into builders/packing directory. There are several OS specific builders. * in directory "debian" builder for Debian, also can be used for Ubuntu and other distributions based on debian * in directory "freebsd" builder(port) for FreeBSD crtmpserver settings * All crtmpserver settings are located in a detailed file calle: crtmpserver.lua
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值