-
-
Notifications
You must be signed in to change notification settings - Fork 985
Customize Stream Path
Herein we describe streaming (VOD) video-on-demand files from a directory other than the default location (streams). Using an implementation of the IStreamFilenameGenerator allows your files to be in any application accessible location; whether it be a folder inside your Web application, or an NFS mounted directory.
In Red5, the generator provides a service functionality to a particular scope. Each scope can have its own IStreamFilenameGenerator to generate the file name of the VOD stream for recording or playback.
Shown below is an example implementation
import org.red5.server.api.scope.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 files */
public String playbackPath = "videoStreams/";
/** Set if the path is absolute or relative */
public boolean resolvesAbsolutePath;
public String generateFilename(IScope scope, String name, GenerationType type) {
// Generate the file name without the 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 the extension
filename += extension;
}
return filename;
}
public boolean resolvesToAbsolutePath() {
return resolvesAbsolutePath;
}
public void setRecordPath(String path) {
recordPath = path;
}
public void setPlaybackPath(String path) {
playbackPath = path;
}
public void setAbsolutePath(boolean absolute) {
resolvesAbsolutePath = absolute;
}
}
The class above generates a file name such as recordedStreams/red5RecordDemo1234.flv for stream to be recorded and uses the directory videoStreams as playback source for all VOD requests.
The next step is to add the custom generator to the configuration file for the desired application. You will need to edit your application configuration located here: yourApp/WEB-INF/red5-web.xml.
<bean id="streamFilenameGenerator" class="Path.To.Your.CustomFilenameGenerator" />
To modify the paths used for playback and recording, they must be set via the bean as shown below. For absolute paths, ensure that absolute paths are supplied and that the absolutePath property is set to true.
<bean id="streamFilenameGenerator" class="Path.To.Your.CustomFilenameGenerator">
<property name="recordPath" value="/home/myuser/recordings" />
<property name="playbackPath" value="/home/public/streams" />
<property name="absolutePath" value="true" />
</bean>
This is an example of application relative paths:
<bean id="streamFilenameGenerator" class="Path.To.Your.CustomFilenameGenerator">
<property name="recordPath" value="recordings/" />
<property name="playbackPath" value="playback/" />
</bean>