Table of Contents

23.9.4 MediaFilter (gb.media)

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.

23.9.4.2 Examples

23.9.4.2.1 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.

BILD1

Figure 23.9.4.2.1: 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"

23.9.4.2.2 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

BILD2

Figure 23.9.4.2.2: 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")
 
  mcSource.LinkTo(mcFilter)
  mcFilter.LinkTo(mcConvert)
  mcConvert.LinkTo(mcSink)
 
End
 
Public Sub btnShow_Click()
 
  CreatePipeline()
  mpPipeline.Play()
 
End
 
Public Sub btnStop_Click()
 
  If mpPipeline And If mpPipeline.State = Media.Playing Then
     mpPipeline.Stop()
     mpPipeline.Close()
  Endif
 
End

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