------------------------------------------------- HOWTO stream content to/from custom directories ------------------------------------------------- :Author: Joachim Bauch :Contact: jojo@struktur.de :Date: $Date$ :Revision: $Revision$ :Id: $Id$ .. contents:: Preface ========================== This document describes how applications can stream ondemand videos (VOD) from or record to custom directories other than the default `streams` folder inside the webapp. Filename generator service ========================== Red5 uses a concept called `scope services` for functionality that is provided for a certain scope. One of these scope services is IStreamFilenameGenerator_ that generates filenames for VOD streams that should be played or recorded. Custom generator ========================== To generate filename in different folders, a new filename generator must be implemented:: 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/"; 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; } } The above class will generate filenames for recorded streams like `recordedStreams/red5RecordDemo1234.flv` and use the directory `videoStreams` as source for all VOD streams. Activate custom generator ========================== In the next step, the custom generator must be activate in the configuration files for the desired application. Add the following definition to `yourApp/WEB-INF/red5-web.xml`:: This will use the class defined above to generate stream filenames. Change paths through configuration ================================== While the class described here works as expected, it's a bit unhandy to change the paths inside the code as every change requires recompilation of the class. Therefore you can pass parameters to the bean defined in the previous step to specify the paths to use inside the configuration file. Add two methods to your class that will be executed while the configuration file is parsed:: public void setRecordPath(String path) { recordPath = path; } public void setPlaybackPath(String path) { playbackPath = path; } Now you can set the paths inside the bean definition:: You can also move the paths to the `yourApp/WEB-INF/red5-web.properties` file and use parameters to access them:: In that case you will have to add the following lines to your properties file:: recordPath=recordedStreams/ playbackPath=videoStreams/ .. _IStreamFilenameGenerator: http://dl.fancycode.com/red5/api/org/red5/server/api/stream/IStreamFilenameGenerator.html