Red5是一个相当惊人的服务器软件,Java编写的。Red5开发团队已经在努力使其成为一个开源替代Adobe FMS – Flash Media Server 的媒体服务器。
Red5是一个非常合适的视频点播技术的应用,流媒体,发布,mealtime collaboration,多玩家游戏等等…
Red5是对所有共享主机托管方案。默认情况下,red5服务器包括fitcDemo,oflaDemo,SoSample等一些简单示例应用程序的预安装。
当安装和使用red5你必须牢记某些配置和安全问题。RED5的创建仿真RTMP协议(即时消息),即使在今天许多人不知道Red5的功能或者患有java恐惧症,但我必须告诉你…一旦你使用它,你会爱上它。
有许多人与许多的RTMP方案和提出的可能性进行讨论。在这里,我们将讨论一个简单的应用程序,可以从自定义目录流。此应用程序将在服务器端,并会帮助你建立自己的基本的应用程序,它不要求您使用全局oflaDemo。
Red5在自己的本身功能为你部署服务器,不要惊讶。。。
您可以用一个很低的成本建立一个您自己的YouTube或clipshare,但要避免出现任何问题,因为你将在共享服务器共享资源,总是最好能创建自己的应用程序,要求有接受传入传出功能。
本教程不给你的从头开始创建应用程序,而是配置自定义 点播/录制 服务器流 的路径,然后,您可以安全地使用自己帐户的路径来处理流。
默认情况下 oflaDemo 用服务器”streams” 目录点播/录制 服务器流。虽然本教程给您一个同样的功能,许多人做到他仍然相当困难。因此,这里是一个比较实际的方法。
我假设你已经准备好了基本的应用程序类,这使您的应用程序有效。我们将简单地使用一个自定义文件名更改流发生器路径。
设置一个自定义文件名控件-CustomFilenameGenerator.java
package com.flashvisions; import org.red5.server.api.IScope; import org.red5.server.api.ScopeUtils; import org.red5.server.api.stream.IStreamFilenameGenerator; public class CustomFilenameGenerator implements IStreamFilenameGenerator { /** Path that will store recorded videos. */ public static String recordPath; /** Path that contains VOD streams. */ public static String playbackPath; private String getStreamDirectory(IScope scope) { final StringBuilder result = new StringBuilder(); final IScope app = ScopeUtils.findApplication(scope); while (scope != null && scope != app) { result.insert(0, “/” scope.getName()); scope = scope.getParent(); } return playbackPath result.toString(); } public String generateFilename(IScope scope, String name, GenerationType type) { return generateFilename(scope, name, null, type); } public String generateFilename(IScope scope, String name, String extension, GenerationType type) { String filename; filename = getStreamDirectory(scope) name; if (extension != null) // Add extension filename += extension; return filename; } public boolean resolvesToAbsolutePath() { return true; } /* Setters for your path variables */ public void setPlaybackPath(String path) { playbackPath = path; } public void setRecordPath(String path) { recordPath = path; } }
保存为: CustomFilenameGenerator.java 到你的应用程.
现在,我们已经建立了代码,我们需要注册我们的应用程序的类,以使它可以使用这个路径的值。现在我们编辑 red5 中的配置文件 red5-web.xml 一般来说 red5-web.xml 是这样的内容
<?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”> <beans> <bean id=”placeholderConfig” class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”> <property name=”location” value=”/WEB-INF/red5-web.properties” /> </bean> <bean id=”web.context” autowire=”byType” /> <bean id=”web.scope” init-method=”register”> <property name=”server” ref=”red5.server” /> <property name=”parent” ref=”global.scope” /> <property name=”context” ref=”web.context” /> <property name=”handler” ref=”web.handler” /> <property name=”contextPath” value=”${webapp.contextPath}” /> <property name=”virtualHosts” value=”${webapp.virtualHosts}” /> </bean> <bean id=”web.handler” class=”com.flashvisions.Application” singleton=”true” /> </beans> The last bean instructs Red5 about the main application class. So just before the </beans> closing tag .. we will add the directive for our CustomFilenameGenerator class. So our final red5-web.xml will look like this: <?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”> <beans> <bean id=”placeholderConfig” class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”> <property name=”location” value=”/WEB-INF/red5-web.properties” /> </bean> <bean id=”web.context” autowire=”byType” /> <bean id=”web.scope” init-method=”register”> <property name=”server” ref=”red5.server” /> <property name=”parent” ref=”global.scope” /> <property name=”context” ref=”web.context” /> <property name=”handler” ref=”web.handler” /> <property name=”contextPath” value=”${webapp.contextPath}” /> <property name=”virtualHosts” value=”${webapp.virtualHosts}” /> </bean> <bean id=”web.handler” class=”com.flashvisions.Application” singleton=”true” /> <bean id=”streamFilenameGenerator”> <property name=”playbackPath”> <value>C:</value> </property> <property name=”recordPath”> <value>C:</value> </property> </bean> </beans>
正如 全部的流记录将保存到c: 点播目录也为c: 。你可以为流服务器设置你自己的路径
本教程的作者是 Flash Visions 的 Rajdeep Rath