搭建基于crtmpserver的点播解决方案

本文详细介绍了如何在Linux环境下使用crtmpserver搭建流媒体服务器,包括环境配置、配置文件修改、媒体文件存放、播放页面创建及播放流程。通过配置媒体文件位置、修改配置文件、将文件存放指定文件夹,最终通过HTML页面实现媒体文件的播放。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. linux环境下build并启动crtmpserver
这部分可以参见我写的专项详解文章
《crtmpserver流媒体服务器的介绍与搭建》

《crtmpserver配置文件详解》

2. 修改配置文件
修改配置文件: crtmpserver.lua
配置文件的具体意义见文章《crtmpserver配置文件详解》

mediaFolder用来配置媒体文件的位置
media/readme可看到支持的格式以及命名的方式(注意:MP4有的编码不支持,放不了)
+------+--------------------+----------------+
| type | naming             | target file    |
+======+====================+================+
| mp3  | mp3:file_name      | file_name.mp3  |
+------+--------------------+----------------+
| flv  | file_name          | file_name.flv  |
+------+--------------------+----------------+
| mp4  | mp4:file_name.mp4  | file_name.mp4  |
+------+--------------------+----------------+
| m4a  | mp4:file_name.m4a  | file_name.m4a  |
+------+--------------------+----------------+
| m4v  | mp4:file_name.m4v  | file_name.m4v  |
+------+--------------------+----------------+
| mov  | mp4:file_name.mov  | file_name.mov  |
+------+--------------------+----------------+
| f4v  | mp4:file_name.f4v  | file_name.f4v  |
+------+--------------------+----------------+

修改配置文件中的媒体文件的存放路径,可以是绝对路径或相对路径
applications=
{
  rootDirectory="applications",
  ...
  {
    description="FLV Playback Sample",
    name="flvplayback",
    protocol="dynamiclinklibrary",
  
    -- 改成绝对路径
    mediaFolder="/opt/crtmpserver/crtmpserver/media",
    -- 或相对路径
    mediaFolder="./media",
    ...
  }
  ...
}

保存并启动crtmpserver

3. 将媒体文件存放到指定的文件夹下
就是将文件放到/opt/crtmpserver/crtmpserver/media文件夹下(如oscar.flv)

4. 创建播放页面
test_vod.html

<html>
<head>
<script src="/jwplayer/jwplayer.js"></script>
</head>
<body>
<div id='my-video'></div> <script type='text/javascript'>    
 jwplayer('my-video').setup({       
 file: 'rtmp://192.168.1.102/live/oscar.flv',       
 width: '720',        
 height: '576'     }); 
</script>
</body>
</html>

并将这个页面存储在Http server的指定目录下

5. 播放: 需要Http server
在网页中打开就可以看到
如:在IE地址栏中输入:
http://192.168.1.2/jwplayer/test_vod.html

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
发出的红包

打赏作者

北雨南萍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值