• Miscellaneous

Red5 Media Streaming Custom Files Location

  • August 31, 2015
  • Muhammad Ahmad
  • POSTED ON August 31, 2015
  • POSTED BY Muhammad Ahmad

Red5 is a media streaming server and it has been used as a core streaming engine for most popular video conferencing solutions like Apache OpenMeetings, BigBlueButton and many others. Sometimes you have to use the core engine just to stream files without adding extra layers on top of it. The way you can do so is as follows: Install Red5 Server, Create New Application for....

Red5 is a media streaming server and it has been used as a core streaming engine for most popular video conferencing solutions like Apache OpenMeetings, BigBlueButton and many others. Sometimes you have to use the core engine just to stream files without adding extra layers on top of it. The way you can do so is as follows:

  • Install Red5 Server
  • Create New Application for Red5
  • Install the Red5 application
  • Restart the Red5 Server

Red5 Server Installation:

Installing Red5 on Debian based machines is quite simple. You need to run the following command:

sudo apt-get install red5-server

For Ubuntu 14.04, there is a known bug due to which standard installation does not work. You can simply download the release from this site and can start server from sudo red5.sh.

Create A New Application For Red5:

For creating a new application for Red5, you need to install Eclipse for Java EE and create a standard dynamic web application. Setup the file structure as given below:


Now follow the steps given below:

  1. Set WEB-INF\classes\ as default build target
  2. Right click on src and choose Build Path -> Configure Output Folder. Paste WEB-INF/classes in the “Specify output folder” field
  3. Right click on Project and choose Properties from the Menu. Click on Java Build Path and choose Librarise tab
  4. Click on Add External JARs. You should add red5.jar from your red5 directory (/usr/share/red5/red5.jar). You may add all the files from lib directory (/usr/share/red5/lib) as External JARs to let your new application see all the available Red5 classes methods

Now start building your application in src directory. Below is the default application class:

package org.nb.red5;

import java.util.Map;

import org.red5.server.adapter.ApplicationAdapter;<br>import org.red5.server.api.IConnection;<br>import org.red5.server.api.scope.IScope;<br>import org.red5.server.api.stream.IServerStream;

public class Application extends ApplicationAdapter {

   private IScope appScope;

   private IServerStream serverStream;

   /** {@inheritDoc} */
   public boolean appStart(IScope app) {
       log.info("oflaDemo appStart");
       System.out.println("NextStreamer appStart");
       appScope = app;
       return true;

   /** {@inheritDoc} */
   public boolean appConnect(IConnection conn, Object[] params) {
       log.info("NextStreamer appConnect");
       IScope appScope = conn.getScope();
       log.debug("App connect called for scope: {}", appScope.getName());
       // getting client parameters
       Map<String, Object> properties = conn.getConnectParams();
       if (log.isDebugEnabled()) {
           for (Map.Entry<String, Object> e : properties.entrySet()) {
               log.debug("Connection property: {} = {}", e.getKey(), e.getValue());

       return super.appConnect(conn, params);

   /** {@inheritDoc} */
   public void appDisconnect(IConnection conn) {
       log.info("NextStreamer appDisconnect");
       if (appScope == conn.getScope() && serverStream != null) {

The file which actually makes stream from custom path is as follows:

package org.nb.red5;

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 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)
    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;
        filename = playbackPath + name;

        if (extension != null)
         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;

To get these things workable, the configuration for web.xml is as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
   xsi:schemaLocation="https://java.sun.com/xml/ns/j2ee https://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"














The configuration for Red5 is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="https://www.springframework.org/schema/beans"
    xsi:schemaLocation="https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    https://www.springframework.org/schema/lang https://www.springframework.org/schema/lang/spring-lang-3.0.xsd">

    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="location" value="/WEB-INF/red5-web.properties" />

    <bean id="web.context" class="org.red5.server.Context" autowire="byType" />

    <bean id="web.scope" class="org.red5.server.scope.WebScope" 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 id="web.handler" class="org.nb.red5.Application" />

    <bean id="demoService.service" class="org.nb.red5.Service" />

    <bean id="streamFilenameGenerator" class="org.nb.red5.CustomFilenameGenerator">
       <property name="recordPath" value="/home/deploy/backup/streams/" />
       <property name="playbackPath" value="/home/deploy/backup/streams/" />
       <property name="absolutePath" value="true" />


At the end, build the project from Eclipse, upload full directory to /usr/share/red5/webapps/. After uploading the directory, start the server by using sudo service red5 restart command. All the files present in /home/deploy/backup/streams/ will now be ready for stream.


Muhammad Ahmad

Currently serving as the SEO Manager at vteams, Ahmed is a highly skilled individual with several years of experience of Digital Marketing.


Leave a Reply

More Related Article
We provide tips and advice on delivering excellent customer service, engaging your customers, and building a customer-centric business.