Page 1 of 1

Simple GStreamer display example

Posted: Monday 22nd August 2022 1:38pm
by Piper984
I have a need to have the video output of a GStreamer pipeline rendered to a DrawingBox or similar control on a Gambas form. I've taken a look at some of the media examples, but I'm not sure I'm understanding the paradigm yet. The simple example pipeline I'm testing with:

Code: Select all

gst-launch-1.0 videotestsrc is-live=true horizontal-speed=1 ! autovideosink
I'd like the media to be rendered to a drawing area element on the Gambas form (not autovideosink popup). From some examples I've looked at this seems like it's possible, but I'm not understanding out to pass the reference to the drawing area to the MediaPipeline control. From examples I see I can make a pipeline maybe with something like:

Code: Select all

oPipeline= New MediaPipeline  
oMC = New MediaControl(oPipeline, "videotestsrc is-live=true horizontal-speed=1")
But how to link the output to a form element isn't clear to me.

Any advice/guidance welcomed! Thank you.

Re: Simple GStreamer display example

Posted: Monday 22nd August 2022 4:53pm
by vuott
Well,
if you want to use in Gambas the external functions of the GStreamer library directly, then I suggest:
https://www.gambas-it.org/wiki/index.ph ... _GStreamer

If you want to use the resources of gb.media Component (based on GStreamer) of Gambas, then I suggest:
https://www.gambas-it.org/wiki/index.ph ... e_gb.media

Re: Simple GStreamer display example

Posted: Monday 22nd August 2022 9:16pm
by Piper984
Thanks. For right now I'd like to see if I can just use the gb.media system. I've done some more testing. Here is a snip of code that will open the videotestsrc video content in a popup window:

Code: Select all

Dim oPipeline As MediaPipeline
Dim oMC As MediaControl
Dim oSNK As MediaControl 
oPipeline = New MediaPipeline
oMC = New MediaControl(oPipeline, "videotestsrc")
oMC["is-live"] = True
oMC["horizontal-speed"] = 1
oSNK = New MediaControl(oPipeline, "autovideosink")
oMC.LinkTo(oSNK)
oPipeline.Play
Sleep 10
oPipeline.Stop
But what I need to have happen is to not display the video in the window that autovideosink opens, but to display the video in a DrawingArea (or similar type component) on a Gambas form. I've read about the 'SetWindow' methods on the MediaPIpeline and MediaControl classes, but I am still not seeing/understanding how to use this so I can display the video content in the Gambas form.

Thanks to anyone who knows and can help!

Re: Simple GStreamer display example

Posted: Monday 22nd August 2022 10:50pm
by vuott
For displaying the "video-test", "autovideosink " Element does not seem to support the "DrawingArea" Control through the ".SetWindow()" Method.
I believe that you must use the "Playbin" Element, for example as follows:
Private drawingArea1 As DrawingArea

Public Sub _new()
  
  With Me
    .W = Screen.AvailableWidth * 0.3
    .H = Screen.AvailableHeight * 0.5
    .Arrangement = Arrange.Fill
  End With
  drawingArea1 = New DrawingArea(Me)
  
End


Public Sub Form_Activate()
 
  Dim oPipeline As MediaPipeline
  Dim Pbin As MediaControl
 
  oPipeline = New MediaPipeline
  Pbin = New MediaControl(oPipeline, "playbin")
  Pbin["uri"] = "testbin://video,pattern=videotestsrc,is-live=true,horizontal-speed=1"

  Pbin.SetWindow(drawingArea1)
 
  oPipeline.Play
  Wait 10
  oPipeline.Stop
  oPipeline.Close
 
End

Re: Simple GStreamer display example

Posted: Tuesday 23rd August 2022 10:59am
by Piper984
Hi Vuott,

Unfortunately when I cut/paste the playbin example into a new form, I am getting an error "Cannot set status in FMain:28" at this line:
oPipeline.Play. I made sure to add the gb.media component to the project.

Any idea what is going wrong for me? I did a quick google search of that error + gb.media but didn't see solution.

In case it's helpful, I did try to run the playbin pipeline via gst-launch and got an error:

Code: Select all

$gst-launch-1.0 playbin uri="testbin://video,pattern=videotestsrc,is-live=true,horizontal-speed=1"
Setting pipeline to PAUSED ...
ERROR: Pipeline doesn't want to pause.
Missing element: TESTBIN protocol source
ERROR: from element /GstURIDecodeBin:uridecodebin0: No URI handler implemented for "testbin".
Additional debug info:
gsturidecodebin.c(1408): gen_source_element (): /GstPlayBin:playbin0/GstURIDecodeBin:uridecodebin0
Setting pipeline to NULL ...
Freeing pipeline ...
I'm using GStreamer 1.16.3 on this machine.

EDIT: Some additional info:

I made a change to the playbin uri to play a file:
Public Sub Button5_Click()

  Dim oPipeline1 As MediaPipeline
  Dim Pbin As MediaControl
  oPipeline1 = New MediaPipeline
  Pbin = New MediaControl(oPipeline1, "playbin")
  'Pbin["uri"] = "testbin://video,pattern=videotestsrc,is-live=true,horizontal-speed=1"
  Pbin["uri"] = "file:///home/chris/trailer_iphone.mp4"
  Pbin.SetWindow(DrawingArea1)

  oPipeline1.Play
  Wait 10
  oPipeline1.Stop
  oPipeline1.Close

End
This plays the sample video, but the video takes the entire width/height of the gambas form, and not just within the location of DrawingArea1.

Re: Simple GStreamer display example

Posted: Tuesday 23rd August 2022 12:24pm
by vuott
Piper984 wrote: Tuesday 23rd August 2022 10:59am Unfortunately when I cut/paste the playbin example into a new form, I am getting an error "Cannot set status in FMain:28" at this line:
oPipeline.Play.
I don't know why it doesn't work for you.
It works regularly for me.

Piper984 wrote: Tuesday 23rd August 2022 10:59am I did try to run the playbin pipeline via gst-launch and got an error:

Code: Select all

$gst-launch-1.0 playbin uri="testbin://video,pattern=videotestsrc,is-live=true,horizontal-speed=1"
I tried this command line with "gst-launch-1.0" and it works regularly for me.

Piper984 wrote: Tuesday 23rd August 2022 10:59amI'm using GStreamer 1.16.3 on this machine.
I also have 1.16.3 GStreamer version.

Piper984 wrote: Tuesday 23rd August 2022 10:59amThis plays the sample video, but the video takes the entire width/height of the gambas form, and not just within the location of DrawingArea1.
We need to see the code.

Re: Simple GStreamer display example

Posted: Tuesday 23rd August 2022 12:28pm
by Piper984
Hello Vuott and forum,

I made some progress on my own, and I am closer with my test on what I am looking to do with Gambas, but now quite there yet.

The following code works to display the output of the videotesrc plugin from GStreamer:
Public Sub Button1_Click()

Dim oPipeline As MediaPipeline
Dim oMC As MediaControl
Dim oSNK As MediaControl 
oPipeline = New MediaPipeline
oMC = New MediaControl(oPipeline, "videotestsrc")
oMC["is-live"] = True
oMC["horizontal-speed"] = 1
oSNK = New MediaControl(oPipeline, "ximagesink")
oMC.LinkTo(oSNK)
oSNK.SetWindow(drawingArea1, 10, 10, 100, 100)
oPipeline.Play
Wait 10
oPipeline.Stop
oPipeline.Close

End
However, the video takes the entire form area, and not the location of the DrawingArea1. I've also tried to set the X,Y, W, H but this isn't working with the ximagesink.

Here is the form I created:
Image

and here is the form when I run the code:
Image

As you can see, the output of the pipeline takes the entire area of the form. But what I want is for the video to be bound by the X,Y,H,W of DrawingArea1.

Thanks for any help here.

Re: Simple GStreamer display example

Posted: Tuesday 23rd August 2022 12:35pm
by Piper984
Capuring: Replacing ximagesink with xvimagesink and I now think I am getting what I need:
...
oSNK = New MediaControl(oPipeline, "xvimagesink")
...
Image

I will post back to this thread with any additional learnings. I am hoping to use Gambas for a quick UI for a streaming application rather than using C / GTK3+.

Re: Simple GStreamer display example

Posted: Tuesday 23rd August 2022 3:00pm
by vuott
Piper984 wrote: Tuesday 23rd August 2022 12:28pmI made some progress on my own
oSNK = New MediaControl(oPipeline, "ximagesink")
Bravo, so you discovered that with "videotestsrc" you need the "ximagesink" plugin.

Piper984 wrote: Tuesday 23rd August 2022 12:35pm Capuring: Replacing ximagesink with xvimagesink and I now think I am getting what I need:

...using C / GTK3+.
However to me the video is shown within the limits of the "DrawingArea" with both "ximagesink" and "xvimagesink", both with QT and GTK+3

Re: Simple GStreamer display example

Posted: Tuesday 23rd August 2022 3:23pm
by vuott
...with audio (mono-tone) too: :D
Public Sub Button1_Click()
  
  Dim pl1, pl2 As Mediapipeline
  Dim src1, src2, con, res, snk1, snk2 As MediaControl
   
' "Pipeline" dedicated to video:
  pl1 = New MediaPipeline
  src1 = New MediaControl(pl1, "videotestsrc")
  src1["is-live"] = True
  src1["horizontal-speed"] = 1
  snk1 = New MediaControl(pl1, "xvimagesink")
  src1.LinkTo(snk1)
  snk1.SetWindow(drawingArea1)
  
' "Pipeline" dedicated to audio:
  pl2 = New MediaPipeline
  src2 = New MediaControl(pl2, "audiotestsrc")
  con = New MediaControl(pl2, "audioconvert")
  res = New MediaControl(pl2, "audioresample")
  snk2 = New MediaControl(pl2, "autoaudiosink")
  src2.LinkTo(con)
  con.LinkTo(res)
  res.LinkTo(snk2)
  
  pl1.play()
  pl2.play()
  
  Do
    Wait 0.01
  Loop
  
End