《Red5 用户参考手册》之十:Red5 核心技术第三章 自定义流路径

官方最新《Red5 用户参考手册》全套下载地址
        本文介绍了如何使应用流化或录制按需视频(VOD)到指定目录,而不是默认的 webapp 下的 streams 目录。
        文件名生成器服务
        Red5 使用一个叫做域服务的概念为一个特定的域提供功能服务。这些域服务之一是 IStreamFilenameGenerator http://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
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值