Skip to content

Mixing several video sources into a single one

Overview

One or several TVideoGrabber components used as "normal" video sources (video capture devices and/or video clips) can be mixed into a single TVideoGrabber component used as mixer.

This mixer component works independently of the source component: it can be stopped, previewed, recorded, paused, etc. while the 1st component sends it the video frames continuously.

The source components can be displayed in the mixer component:

  • as a basic "copy": a 2nd component in mixer mode receives and displays the video from the 1st component,
  • by switching several sources into a single one when needed,
  • as a mosaic layout (e.g. 4 cameras displayed at the same time on a 2x2 layout),
  • as an alternated display (e.g. the 4 cameras are displayed alternately, one after the other),
  • in a mosaic/alternated layout (e.g. the 16 cameras are displayed in 4 alternated mosaic layouts of 2x2 cameras).

Combined mosaic / alternated mixing

The alternated and mosaic modes can be combined, e.g. to display 16 cameras in groups of 4 cameras displayed alternately in a 2 x 2 video window.

Parameters of the Mixer_AddToMixer function

  • The 1st parameter is the UniqueID of the source component.
  • The 2nd parameter is not used for the moment: set it to 0.
  • The 3rd parameter is the mosaic line where the source is displayed (set it to 0 for an "alternated only" use).
  • The 4th parameter is the mosaic column where the source is displayed (set it to 0 for an "alternated only" use).
  • The 5th parameter is the display group number (set it to 0 for a "mosaic only" use).
  • The 6th parameter is the display group duration in milliseconds (set it to 0 for a "mosaic only" use).
  • The 7th parameter should be set to TRUE.
  • The 8th parameter should be set to TRUE.

See Mixer_AddToMixer.

Basic mixing (a 2nd component receives the video frames from the 1st component)

In this mode, a 2nd component uses the first component as video source. E.g. the first component runs the preview, and the 2nd component starts/stops/pauses/resumes the recording independently of the 1st component, which does a continuous preview.

E.g.:

VideoGrabber1.VideoSource = vs_VideoCaptureDevice;
VideoGrabber1.StartPreview();
VideoGrabber2.VideoSource = vs_Mixer;
VideoGrabber2.Mixer_AddToMixer (VideoGrabber1.UniqueID, 0, 0, 0, 0, 0, true, true);
VideoGrabber2.StartPreview();

VideoGrabber2 then receives as video source the video displayed and sent by VideoGrabber1.

Choosing the mixer video size

By default, the mixer uses the following video size:

  • if the source has been started before starting the mixer, the mixer uses the source size,
  • if the source has not been started, the mixer starts in 320x240.

To choose the video size, invoke UseNearestVideoSize on the mixer before StartPreview or StartRecording.

E.g. to start the mixer in 640x480, invoke:

VideoGrabberMixer.VideoSource = vs_Mixer
VideoGrabberMixer.UseNearestVideoSize (640, 480, true)
VideoGrabberMixer.StartPreview()

Switching several sources into a single one when needed

As with the basic mixing, but with more than one video source: the sources can be switched by invoking Mixer_Activation, e.g.:

  1. Start the preview of the 1st capture device:

    VideoGrabber1.VideoSource = vs_VideoCaptureDevice
    VideoGrabber1.VideoDevice = 0
    VideoGrabber1.StartPreview()
    
  2. Start the preview of the 2nd capture device:

    VideoGrabber2.VideoSource = vs_VideoCaptureDevice
    VideoGrabber2.VideoDevice = 1
    VideoGrabber2.StartPreview()
    
  3. Start the 3rd component, which runs the preview or recording in mixer mode:

    VideoGrabber3.VideoSource = vs_Mixer;
    int MixerId1 = VideoGrabber3.Mixer_AddToMixer (VideoGrabber1.UniqueID, 0, 0, 0, 0, 0, true, true);
    int MixerId2 = VideoGrabber3.Mixer_AddToMixer (VideoGrabber2.UniqueID, 0, 0, 0, 0, 0, true, true);
    VideoGrabber3.Mixer_Activation (MixerId2, false); // let's start with MixerId1 activated only
    VideoGrabber3.StartPreview();
    
  4. Then, to switch between the inputs, activate one and deactivate the other:

    VideoGrabber3.Mixer_Activation (MixerId1, false)
    VideoGrabber3.Mixer_Activation (MixerId2, true)
    

    or:

    VideoGrabber3.Mixer_Activation (MixerId2, false)
    VideoGrabber3.Mixer_Activation (MixerId1, true)
    

Activating the mixer component in automatic alternated mixing mode

In the following example, the mixer component is named "Mixer1", and the source components "Source1", "Source2" and "Source3".

E.g. with group 1 = 1500 ms, group 2 = 2000 ms and group 3 = 2500 ms:

Mixer1.Mixer_AddToMixer (Source1.UniqueID, 0, 0, 0, 1, 1500, True, True)
Mixer1.Mixer_AddToMixer (Source2.UniqueID, 0, 0, 0, 2, 2000, True, True)
Mixer1.Mixer_AddToMixer (Source3.UniqueID, 0, 0, 0, 3, 2500, True, True)

Then invoke e.g.:

Source1.StartPreview()
Source2.StartPreview()
Source3.StartPreview()
Mixer1.StartPreview()

See the remark below.

Activating the mixer component in mosaic mixing mode

In this mode, the destination component window is split into x lines and y columns, and each source is displayed at a predefined (x,y) location.

In the following example, the mixer component is named "Mixer1", and the source components "Source1", "Source2", "Source3" and "Source4" are displayed in a 2 x 2 layout.

Mixer1.Mixer_AddToMixer (Source1.UniqueID, 0, 1, 1, 0, 0, True, True)
Mixer1.Mixer_AddToMixer (Source2.UniqueID, 0, 1, 2, 0, 0, True, True)
Mixer1.Mixer_AddToMixer (Source3.UniqueID, 0, 2, 1, 0, 0, True, True)
Mixer1.Mixer_AddToMixer (Source4.UniqueID, 0, 2, 2, 0, 0, True, True)

Then invoke e.g.:

Source1.StartPreview()
Source2.StartPreview()
Source3.StartPreview()
Source4.StartPreview()
Mixer1.StartPreview()

See the remark below.

Activating the mixer component in alternated/mosaic mixing mode

In this mode, the groups of sources are displayed alternately in a single video window, each group as a mosaic.

In the following example, the mixer component is named "Mixer1", and the source components "Source1", "Source2", "Source3" and "Source4" are displayed alternately in 2 layouts of 1 x 2 source components.

The example uses 2 groups named "55" and "66" (the number is not significant, it must simply be different for each group). The group 55 is displayed with a duration of 1500 milliseconds, and the group 66 with a duration of 2500 milliseconds.

Mixer1.Mixer_AddToMixer (Source1.UniqueID, 0, 1, 1, 55, 1500, True, True)
Mixer1.Mixer_AddToMixer (Source2.UniqueID, 0, 1, 2, 55, 1500, True, True)
Mixer1.Mixer_AddToMixer (Source3.UniqueID, 0, 1, 1, 66, 2500, True, True)
Mixer1.Mixer_AddToMixer (Source4.UniqueID, 0, 1, 2, 66, 2500, True, True)

Then invoke e.g.:

Source1.StartPreview()
Source2.StartPreview()
Source3.StartPreview()
Source4.StartPreview()
Mixer1.StartPreview()

Note

Mixer1.StartPreview can also be invoked before starting or associating the sources; in this case, an empty window with a BackgroundColor is displayed.

Audio

The mixer mixes the video only: the audio of the source components is not received by the mixer component.