Skip to content

Mixing several video sources into a single one

Overview
It is possible to mix one or several TVideoGrabber components used as "normal" video sources (video capture devices and/or video clips) 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 may 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
It is possible to combine the alternated and mosaic modes, e.g. to display 16 cameras in groups of 4 cameras displayed alternately in a 4 X 4 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, just set it to 0
  • the 3rd parameter is the mosaic line where the source will be displayed (set it to 0 for an "alternated only" use).
  • the 4th parameter is the mosaic column where the source will be 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)

This mode makes it possible to have a 2nd component that 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 that 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()

and VideoGrabber2 will receive 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
Similar to 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 that will run 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' 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)

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

Activating the mixer component in automatic alternated mixing mode
Let's take an example where the mixer component is named "Mixer1", and the source components "Source1", "Source2" and "Source3".

E.g if (group 1 = 1500 ms, group 2 = 2000 ms, 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()
 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.

Let's take an example where the mixer component is named "Mixer1", and the source components "Source1", "Source2", "Source3" and "Source4" will be 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 each source is displayed alternately in a single video window.

Let's take an example where the mixer component is named "Mixer1", and the source components "Source1", "Source2", "Source3" and "Source4" will be displayed alternately in 2 layouts of 1 x 2 source components.

We will use 2 groups named "55" and "66" (the number is not significant, it must simply be different for each group). The group 55 will be 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()

**Remark: it is possible to also invoke Mixer1.StartPreview before starting or associating the sources; in this case an empty window with a BackgroundColor will be displayed.