《Red5 用户参考手册》之十:Red5 核心技术第三章 自定义流路径
来源:互联网 发布:影吧点播软件 编辑:程序博客网 时间:2024/05/01 01:31
转自:http://blog.csdn.net/defonds/article/details/7776311
官方最新《Red5 用户参考手册》全套下载地址
本文介绍了如何使应用流化或录制按需视频(VOD)到指定目录,而不是默认的 webapp 下的 streams 目录。
文件名生成器服务
Red5 使用一个叫做域服务的概念为一个特定的域提供功能服务。这些域服务之一是 IStreamFilenameGeneratorhttp://dl.fancycode.com/red5/api/org/red5/server/api/stream/IStreamFilenameGenerator.html 生成可以播放和录制的 VOD 流的文件名。
自定义生成器
要在不同的文件里生成文件名,必须实现一个新的文件名生成器:
- import org.red5.server.api.IScope;
- import org.red5.server.api.stream.IStreamFilenameGenerator;
- public class CustomFilenameGenerator implements IStreamFilenameGenerator {
- /** Path that will store recorded videos. */
- public String recordPath = "recordedStreams/";
- /** Path that contains VOD streams. */
- public String playbackPath = "videoStreams/";
- /** Set if the path is absolute or relative */
- public boolean resolvesAbsolutePath = false;
- public String generateFilename(IScope scope, String name, GenerationType type) {
- // Generate filename without an extension.
- return generateFilename(scope, name, null, type);
- }
- public String generateFilename(IScope scope, String name, String extension, GenerationType type) {
- String filename;
- if (type == GenerationType.RECORD)
- filename = recordPath + name;
- else
- filename = playbackPath + name;
- if (extension != null)
- // Add extension
- filename += extension;
- return filename;
- }
- public boolean resolvesToAbsolutePath()
- {
- return resolvesAbsolutePath;
- }
- }
以上类将会为录制的流生成类似 recordedStreams/ red5RecordDemo1234.flv 的文件名,并使用 videoStreams 目录作为所有 VOD 流的源。
激活自定义生成器
下一步,自定义生成器必须得在配置文件中为所需的应用程序激活。
将以下定义添加到 yourApp/WEB-INF/red5-web.xml:
- <bean id="streamFilenameGenerator"
- class="path.to.your.CustomFilenameGenerator" />
这将使用以上定义的类来生成流的文件名。
通过配置修改存放路径
当以上所述的类按预期工作时,如若修改代码里定义的路径不是太方便,因为每一次改变都需要对它进行重新编译。
所以你可以在上一步配置文件里里定义的 bean 里传入参数来定义用到的路径。
添加三个方法到你的类,这些方法会在配置文件被解析时执行:
- public void setRecordPath(String path) {
- recordPath = path;
- }
- public void setPlaybackPath(String path) {
- playbackPath = path;
- }
- public void setAbsolutePath(Boolean absolute) {
- resolvesAbsolutePath = absolute;
- }
现在你可以在 bean 定义里设置路径了:
- <bean id="streamFilenameGenerator"
- class="path.to.your.CustomFilenameGenerator">
- <property name="recordPath" value="recordedStreams/" />
- <property name="playbackPath" value="videoStreams/" />
- <property name="absolutePath" value="false" />
- </bean>
- <bean id="streamFilenameGenerator"
- class="path.to.your.CustomFilenameGenerator">
- <property name="recordPath" value="/path/to/recordedStreams/" />
- <property name="playbackPath" value="/path/to/videoStreams/" />
- <property name="absolutePath" value="true" />
- </bean>
你也可以把路径放到 yourApp/WEB-INF/red5-web.properties 文件里并使用参数对它们进行访问:
- <bean id="streamFilenameGenerator"
- class="path.to.your.CustomFilenameGenerator">
- <property name="recordPath" value="${recordPath}" />
- <property name="playbackPath" value="${playbackPath}" />
- <property name="absolutePath" value="${absolutePath}" />
- </bean>
这时你需要把以下行添加到你的 properties 文件(red5-web.properties):
- recordPath=recordedStreams/
- playbackPath=videoStreams/
- absolutePath=false
- recordPath=/path/to/recordedStreams/
- playbackPath=/path/to/videoStreams/
- absolutePath=true
原文链接:http://trac.red5.org/wiki/Documentation/UsersReferenceManual/Red5CoreTechnologies/03-Customize-Stream-Paths。
- 《Red5 用户参考手册》之十:Red5 核心技术第三章 自定义流路径
- 《Red5 用户参考手册》之十:Red5 核心技术第三章 自定义流路径
- 《Red5 用户参考手册》之十:Red5 核心技术第三章 自定义流路径
- 《Red5 用户参考手册》之十一:Red5 核心技术第四章 安全
- 《Red5 用户参考手册》之十三:Red5 核心技术第六章 集群
- 《Red5 用户参考手册》之十四:Red5 核心技术第七章 管理
- 《Red5 用户参考手册》之十一:Red5 核心技术第四章 安全
- 《Red5 用户参考手册》之十三:Red5 核心技术第六章 集群
- 《Red5 用户参考手册》之十四:Red5 核心技术第七章 管理
- 《Red5 用户参考手册》之十五:Red5 核心技术第八章 自定义的 bean 定义列表
- 《Red5 用户参考手册》之十五:Red5 核心技术第八章 自定义的 bean 定义列表
- 《Red5 用户参考手册》之九:Red5 核心技术第二章 将 Red5 部署到 Tomcat
- 《Red5 用户参考手册》之九:Red5 核心技术第二章 将 Red5 部署到 Tomcat
- 《Red5 用户参考手册》之十二:Red5 核心技术第五章 脚本实现
- 《Red5 用户参考手册》之十二:Red5 核心技术第五章 脚本实现
- 《Red5 用户参考手册》之八:Red5 核心技术第一章 在 Red5 里创建新应用
- 《Red5 用户参考手册》之八:Red5 核心技术第一章 在 Red5 里创建新应用
- 《Red5 用户参考手册》之四:入门第三章 迁移指南
- 用于子空间分割的低秩表达的background knwolodges
- Ubuntu 12.04 输入法托盘图标消失
- Makefile
- Exchange Server 2013 一步步安装图解
- 做为技术人员为什么要写博客
- 《Red5 用户参考手册》之十:Red5 核心技术第三章 自定义流路径
- 再探java基础——对面向对象的理解(1)
- 由专业兴趣引起对“通识教育”的期望
- hdu 1724 Ellipse simpson积分
- POJ-1010-STAMPS
- 抛弃 CSS Hacks 后的浏览器兼容方案
- 小小兼职
- Android保存和恢复ListView的滑动后位置
- 怎样把HTC G7的内存扩展到2GB