Red5 Documentation

Preprocessor

The Preprocessor is a feature that allows you to modify the incoming stream before it is published to the server. This can be useful for a variety of reasons, such as changing the profile of the video stream from Main or High to Baseline, or transcoding the stream to a different format either size, bitrate or both. In dynamic mode the preprocessor detects Main and High profiles that are not compatible with most browser based players and transcodes them to Baseline allowing for maximum compatibility.

Configuring the Preprocessor in Static Mode

In static mode the preprocessor will transcode all incoming streams based on the configuration provided.

In /webapps/live/WEB-INF/red5-web.xml uncomment/add the following bean definition:

<bean id="ipreprocessorFactory" class="com.red5pro.override.cauldron.PreprocessorFactory">
    <property name="videoWidth" value="0" />
    <property name="videoHeight" value="0" />
    <property name="videoQPMin" value="1" />
    <property name="videoQPMax" value="46" />
    <property name="videoBR" value="2000000" />
    <property name="videoBRMax" value="2000000" />
    <property name="dynamic" value="false" />
</bean>

Static Preprocessor Properties

Property Description
videoWidth The width of the video stream. Set to 0 to keep the original width.
videoHeight The height of the video stream. Set to 0 to keep the original height.
videoQPMin The minimum quantization parameter. Recommended setting is 1
videoQPMax The maximum quantization parameter. Recommended setting is 46
videoBR The bitrate of the video stream.
videoBRMax The maximum bitrate of the video stream, typically this is set to the same as videoBR
dynamic Set to false to disable dynamic mode.

Configuring the Preprocessor in Dynamic Mode

In dynamic mode the preprocessor will only transcode streams that have a profile that is not compatible with most browser based players (Main or High). When either of those profiles are detected the stream will be transcoded to Baseline.

The default transcode parameters are set in /webapps/live/WEB-INF/red5-web.xml. Uncomment/add the following bean definition:

<bean id="ipreprocessorFactory" class="com.red5pro.override.cauldron.PreprocessorFactory">
    <property name="videoWidth" value="0" />
    <property name="videoHeight" value="0" />
    <property name="videoQPMin" value="1" />
    <property name="videoQPMax" value="46" />
    <property name="videoBR" value="2000000" />
    <property name="videoBRMax" value="2000000" />
    <property name="dynamic" value="true" />
</bean>

Dynamic Preprocessor Properties

Property Description
videoWidth The output width of the preprocessed video stream. Set to 0 to keep the original width.
videoHeight The output height of the preprocessed video stream. Set to 0 to keep the original height.
videoQPMin The minimum quantization parameter. Recommended setting is 1
videoQPMax The maximum quantization parameter. Recommended setting is 46
videoBR The bitrate of the video stream.
videoBRMax The maximum bitrate of the video stream, typically this is set to the same as videoBR
dynamic Set to true to enable dynamic mode.

The dynamic preprocessor also allows customization based on the incoming height and width of the stream. You can configure multiple preprocessor configurations based on the incoming stream height and width, with the preprocessor selecting the configuration the best matches the incoming stream. If no exact match it found it will use the next configuration that is closest, but higher, in width and height. So if you have configurations for 360p and 1080p, but send a 720p stream, the 1080p configuration will be used.

To configure the dynamic preprocessor based on the incoming stream size, add bean definitions to to /conf/red5-common.xml, setting “id” to something unique for each configuration. For example:

<bean id="720p" class="com.red5pro.override.cauldron.PreprocessorConfigTable.Entry">
    <property name="width" value="1280"/>
    <property name="height" value="720"/>
    <!-- For CBR, set both bitrate and bitrateMax the same value. -->
    <property name="videoBR" value="1000000"/>
    <property name="videoBRMax" value="1000000"/>
    <!-- Quantization range. For CBR, min must not be zero -->
    <property name="videoQPMin" value="1"/>
    <property name="videoQPMax" value="46"/>
    <!-- Video using this config may be upscaled to this width and height if video is smaller. Set to true to upscale-->
    <property name="scaleOutput" value="false"/>
</bean>
Property Description
width The output width of the preprocessed video stream.
height The output height of the preprocessed video stream.
videoBR The bitrate of the preprocessed video stream.
videoBRMax The maximum bitrate of the preprocessed video stream, typically this is set to the same as videoBR
videoQPMin The minimum quantization parameter. Recommended setting is 1
videoQPMax The maximum quantization parameter. Recommended setting is 46
scaleOutput Set to true to upscale the video to the configured width and height if the incoming stream is smaller.

Add the configured resolution(s) to the configuration table bean in the same file, the below showing two resolutions, 720p and 1080p:

<bean id="preprocessorConfigTable" scope="prototype" lazy-init="true" class="com.red5pro.override.cauldron.PreprocessorConfigTable">
    <property name="resolutions">
        <list value-type="com.red5pro.override.cauldron.PreprocessorConfigTable.Entry">
            <!-- The server will order these from lowest to highest. -->
            <ref bean="720p"/>
            <ref bean="1080p"/>
        </list>
    </property> 
</bean>