Several useful modules

This section introduces several modules which are useful in assembling OpenVIP networks.

Concat

The Concat module is used to join two or more input streams in a single output stream.

Network parameters

The following table lists the module's parameters in network file format.

Table 4.87. Concat parameters

ParameterValuesDescriptionRequired
countpositive integerinput modules countyes
typeaudio, video, datawhich stream to operate onyes

The parameter count determines the number of module's input connectors whose type is determined by the second parameter. The module has a single output connector which is of the same type as the input connectors.

The input streams must have the same properties, i.e. dimensions and FPS in case of video streams, sample rate and number of channels in case of audio streams. Otherwise you have to process them with filters such as Resize, Resample, Number of channels or modules such as FPSChanger before using Concat.

Example

Imagine you have two input files input1.avi and input2.avi of size 640x480 with 24 fps and stereo audio sampled at 44.1 kHz. The following network joins them in a single output called output.avi; the two clips are separated using a 5 seconds long pause produced by NullGenerator.

<?xml version="1.0" ?>
<!DOCTYPE network PUBLIC
          "-//OPENVIP//DTD Network Format V1.0//EN" 
          "http://openvip.sourceforge.net/dtds/openvip-network.dtd">

<network xmlns="http://openvip.sourceforge.net/network-format" version="1.0">

    <module id="loader1" class="Input">
        <param name="filename">input1.avi</param>
    </module>

    <module id="loader2" class="Input">
        <param name="filename">input2.avi</param>
    </module>

    <module id="nullgen_video" class="NullGenerator">
        <param name="type">video</param>
        <param name="length">5</param>
        <param name="frame_width">640</param>
        <param name="frame_height">480</param>
        <param name="fps">24</param>
        <param name="aspect_ratio">1</param>
    </module>

    <module id="nullgen_audio" class="NullGenerator">
        <param name="type">audio</param>
        <param name="length">5</param>
        <param name="samplerate">44100</param>
        <param name="channels">2</param>
    </module>

    <module id="concat_video" class="Concat">
        <param name="type">video</param>
        <param name="count">3</param>
    </module>

    <module id="concat_audio" class="Concat">
        <param name="type">audio</param>
        <param name="count">3</param>
    </module>

    <module id="saver" class="Output">
        <param name="filename">output.avi</param>
        <param name="format">FFMpeg</param>
    </module>

    <connect module_in="loader1" conn_in="video0" module_out="concat_video" conn_out="video0"/>
    <connect module_in="nullgen_video" conn_in="video0" module_out="concat_video" conn_out="video1"/>
    <connect module_in="loader2" conn_in="video0" module_out="concat_video" conn_out="video2"/>

    <connect module_in="loader1" conn_in="audio0" module_out="concat_audio" conn_out="audio0"/>
    <connect module_in="nullgen_audio" conn_in="audio0" module_out="concat_audio" conn_out="audio1"/>
    <connect module_in="loader2" conn_in="audio0" module_out="concat_audio" conn_out="audio2"/>

    <connect module_in="concat_video" conn_in="video0" module_out="saver" conn_out="video0"/>
    <connect module_in="concat_audio" conn_in="audio0" module_out="saver" conn_out="audio0"/>

</network>

FPSChanger

The FPSChanger module is used on an existing video stream to change their FPS.

Network parameters

The following table lists the module's parameters in network file format.

Table 4.88. FPSChanger parameters

ParameterValuesDescriptionRequired
fpspositive real numberoutput stream FPSno
output_lengthpositive integernumber of frames in the output streamno

It is necessary to specify exactly one of the two parameters. The second one is calculated using the formula output_length=(fps/input_fps)*input_length, where input_length and input_fps are properties of the input stream.

NullGenerator

The NullGenerator module produces an empty stream (i.e. black video frames or silence).

Network parameters

The following table lists the module's parameters in network file format.

Table 4.89. NullGenerator parameters

ParameterValuesDescriptionRequired
typeaudio, videowhich stream to produceyes
lengthpositive real numberlength of output (in seconds)yes

The module has always a single output connector and no input connectors.

The value of type can be either video or audio. Depending on this value you have to specify one of the two groups of parameters:

Table 4.90. Additional parameters for video

ParameterValuesDescriptionRequired
frame_widthpositive integerframe widthyes
frame_heightpositive integerframe heightyes
fpspositive real numberframes per secondyes
aspect_ratiopositive real numberaspect ratioyes
frame_formatintegerinternal frame formatno

These parameters are self-explanatory except frame_format; it identifies the internal format used by OpenVIP to store the data structure. For a list of possible values see the file IVideoFrame.idl.

Table 4.91. Additional parameters for audio

ParameterValuesDescriptionRequired
sampleratepositive integersample rate in Hzyes
channelspositive integernumber of audio channelsyes

Example

For an example see the Concat section.

Overlay

The Overlay module is used to paste semi-transparent (alpha channel) images from one video stream over another video stream.

Network parameters

The following table lists the module's parameters in network file format.

Table 4.92. Overlay parameters

ParameterValuesDescriptionRequired
static_overlayboolean (0 or 1)use only first frame from overlay stream?no (default 0)
xintegeroverlay x-positionno (default 0)
yintegeroverlay y-positionno (default 0)

The module has two input video connectors and a single output video connector. Video frames send to the second input connector are pasted over those from the first input connector; the blended image is then sent to the output.

The overlay clip and the background clip needn't have the same dimensions; the position where the overlay is placed is governed by the x and y parameters (default setting corresponds to the upper left corner).

The overlay clip can be shorter than the background clip - the last video frame from the overlay clip is then repeated. Switching static_overlay on causes that only the first video frame from the overlay clip will be used.

Example

Imagine you have a 50x50 logo called logo.png which you want to paste to the upper right corner of your 640x480 clip called input.avi. The following network does the job saving the output to output.avi.

<?xml version="1.0" ?>
<!DOCTYPE network PUBLIC
          "-//OPENVIP//DTD Network Format V1.0//EN" 
          "http://openvip.sourceforge.net/dtds/openvip-network.dtd">

<network xmlns="http://openvip.sourceforge.net/network-format" version="1.0">

    <module id="loader1" class="Input">
        <param name="filename">input.avi</param>
    </module>

    <module id="loader2" class="Input">
        <param name="filename">logo.png</param>
    </module>

    <module id="overlay" class="Overlay">
        <param name="x">590</param>
    </module>

    <module id="saver" class="Output">
        <param name="filename">output.avi</param>
        <param name="format">FFMpeg</param>
    </module>

    <connect module_in="loader1" conn_in="video0" module_out="overlay" conn_out="video0"/>
    <connect module_in="loader2" conn_in="video0" module_out="overlay" conn_out="video1"/>
    <connect module_in="overlay" conn_in="video0" module_out="saver" conn_out="video0"/>
    <connect module_in="loader1" conn_in="audio0" module_out="saver" conn_out="audio0"/>

</network>

Subset

The Subset module is used to extract a portion from an existing stream.

Network parameters

The following table lists the module's parameters in network file format.

Table 4.93. Subset parameters

ParameterValuesDescriptionRequired
typeaudio, video, datawhich stream to operate onyes
pospositive real numberbeginning of the selected block (in seconds)yes
lengthpositive real numberlength of the selected block (in seconds)yes

The module has a single input connector and a single output connector whose types are given by the first parameter. The output is identical to the part of input stream which is specified by pos and length parameters.

Example

The following network takes first 15 seconds from file input.avi and saves them to output.avi.

<?xml version="1.0" ?>
<!DOCTYPE network PUBLIC
          "-//OPENVIP//DTD Network Format V1.0//EN" 
          "http://openvip.sourceforge.net/dtds/openvip-network.dtd">

<network xmlns="http://openvip.sourceforge.net/network-format" version="1.0">

    <module id="loader" class="Input">
        <param name="filename">input.avi</param>
    </module>

    <module id="subset_video" class="Subset" >
        <param name="type">video</param>
        <param name="pos">0</param>
        <param name="length">15</param>
    </module>
    
    <module id="subset_audio" class="Subset" >
        <param name="type">audio</param>
        <param name="pos">0</param>
        <param name="length">15</param>
    </module>

    <module id="saver" class="Output">
        <param name="filename">output.avi</param>
        <param name="format">FFMpeg</param>
    </module>

    <connect module_in="loader" conn_in="video0" module_out="subset_video" conn_out="video0"/>
    <connect module_in="loader" conn_in="audio0" module_out="subset_audio" conn_out="audio0"/>

    <connect module_in="subset_video" conn_in="video0" module_out="saver" conn_out="video0"/>
    <connect module_in="subset_audio" conn_in="audio0" module_out="saver" conn_out="audio0"/>

</network>