User Tools

Site Tools




23.9.4 MediaFilter (

This class implements a GStreamer caps filter element. The class inherits MediaControl, works like a read/write array and can be created:

Dim hMediaFilter As MediaFilter
hMediaFilter = New MediaFilter ( [ Parent As MediaContainer, Type As String ] ) [ As "EventName" ]

The MediaFilter class has the same relevant properties, methods and events as the MediaControl class. Examples Example 1

Note: Since Gambas version 3.6, the same syntax for caps filters can be used for the plugin type as is used by the gst-launch programme.


Figure Pipeline with (caps) filter

In the following example, the filter element in the GStreamer pipeline is specified as follows

gst-launch-1.0 videotestsrc ! capsfilter caps=video/x-raw,format=GRAY8 ! videoconvert ! autovideosink

or in the short form:

gst-launch-1.0 videotestsrc ! video/x-raw,format=GRAY8 ! videoconvert ! autovideosink

and implemented compactly in Gambas:

Dim hMediaFilter As MediaFilter
Dim hParent As MediaControl
hMediaFilter = New MediaFilter(hParent, "video/x-raw,format=GRAY8")

and is the equivalent of the following syntax:

Dim hMediaFilter As MediaFilter
hMediaFilter = New hMediaFilter(hParent, "capsfilter")
hMediaFilter["caps"] = "video/x-raw,format=GRAY8" Example 2

In example 2, the following GStreamer command is implemented in Gambas to display the images of a local webcam in a size of 320×240 pixels - as part of the filter:

$ gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,width=320,height=240,framerate=30/1 ! videoconvert ! ximagesink


Figure Video display of a local webcam in a separate window

The Gambas source code with a media filter is short and is shown here in full:

' Gambas class file
Private mpPipeline As MediaPipeline
Private mcSource As MediaControl
Private mcFilter As MediaFilter
Private mcConvert As MediaControl
Private mcSink As MediaControl
Public Sub CreatePipeline()
  mpPipeline = New MediaPipeline As "hPipeline"
  mcSource = New MediaControl(mpPipeline, "v4l2src")
  mcSource["device"] = "/dev/video0"
  mcFilter = New MediaFilter(mpPipeline, "capsfilter")
  mcFilter["caps"] = "video/x-raw,width=640,height=480,framerate=30/1"
  mcConvert = New MediaControl(mpPipeline, "videoconvert")
  mcSink = New MediaControl(mpPipeline, "xvimagesink")
Public Sub btnShow_Click()
Public Sub btnStop_Click()
  If mpPipeline And If mpPipeline.State = Media.Playing Then

Note: The image of the local webcam is displayed in a separate window.

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k23/k23.9/k23.9.4/start.txt · Last modified: 13.01.2024 by emma

Page Tools