Simple GStreamer display example

Post

Posted
Rating:
#1 (In Topic #891)
Trainee
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

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

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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
Well,
if you want to use in Gambas the external functions of the GStreamer library directly, then I suggest:
   https://www.gambas-it.…ioni_esterne_di_GStreamer

If you want to use the resources of <COLOR color="#800000">gb.media</COLOR> Component (based on GStreamer) of Gambas, then I suggest:
   https://www.gambas-it.…on_il_Componente_gb.media

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
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

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!
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
vuott is in the usergroup ‘Regular’
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 "<COLOR color="#800000">Playbin</COLOR>" Element, for example as follows:

Code (gambas)

  1. Private drawingArea1 As DrawingArea
  2.  
  3. Public Sub _new()
  4.  
  5.   With Me
  6.     .W = Screen.AvailableWidth * 0.3
  7.     .H = Screen.AvailableHeight * 0.5
  8.     .Arrangement = Arrange.Fill
  9.   drawingArea1 = New DrawingArea(Me)
  10.  
  11.  
  12.  
  13. Public Sub Form_Activate()
  14.  
  15.   Dim oPipeline As MediaPipeline
  16.   Dim Pbin As MediaControl
  17.  
  18.   oPipeline = New MediaPipeline
  19.   Pbin = New MediaControl(oPipeline, "playbin")
  20.   Pbin["uri"] = "testbin://video,pattern=videotestsrc,is-live=true,horizontal-speed=1"
  21.  
  22.   Pbin.SetWindow(drawingArea1)
  23.  
  24.   oPipeline.Play
  25.   Wait 10
  26.   oPipeline.Stop
  27.   oPipeline.Close
  28.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee
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

$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:

Code (gambas)

  1. Public Sub Button5_Click()
  2.  
  3.   Dim oPipeline1 As MediaPipeline
  4.   Dim Pbin As MediaControl
  5.   oPipeline1 = New MediaPipeline
  6.   Pbin = New MediaControl(oPipeline1, "playbin")
  7.   'Pbin["uri"] = "testbin://video,pattern=videotestsrc,is-live=true,horizontal-speed=1"
  8.   Pbin["uri"] = "file:///home/chris/trailer_iphone.mp4"
  9.   Pbin.SetWindow(DrawingArea1)
  10.  
  11.   oPipeline1.Play
  12.   Wait 10
  13.   oPipeline1.Stop
  14.   oPipeline1.Close
  15.  

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.
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’

Piper984 said

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 said

I did try to run the playbin pipeline via gst-launch and got an error:

Code

$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 said

I'm using GStreamer 1.16.3 on this machine.
I also have 1.16.3 GStreamer version.


Piper984 said

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.
We need to see the code.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#7
Trainee
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:

Code (gambas)

  1. Public Sub Button1_Click()
  2.  
  3. Dim oPipeline As MediaPipeline
  4. Dim oMC As MediaControl
  5. Dim oSNK As MediaControl
  6. oPipeline = New MediaPipeline
  7. oMC = New MediaControl(oPipeline, "videotestsrc")
  8. oMC["is-live"] = True
  9. oMC["horizontal-speed"] = 1
  10. oSNK = New MediaControl(oPipeline, "ximagesink")
  11. oMC.LinkTo(oSNK)
  12. oSNK.SetWindow(drawingArea1, 10, 10, 100, 100)
  13. oPipeline.Play
  14. Wait 10
  15. oPipeline.Stop
  16. oPipeline.Close
  17.  
  18.  

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:
<IMG src="http://www.pitchpipetuner.com/gambas/screen_gui_editor.jpg"> </IMG>

and here is the form when I run the code:
<IMG src="http://www.pitchpipetuner.com/gambas/screen_gui_running.jpg"> </IMG>

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.
Online now: No Back to the top

Post

Posted
Rating:
#8
Trainee
Capuring: Replacing ximagesink with xvimagesink and I now think I am getting what I need:

Code (gambas)

  1. ...
  2. oSNK = New MediaControl(oPipeline, "xvimagesink")
  3. ...
  4.  

<IMG src="http://www.pitchpipetuner.com/gambas/screen_gui_working.jpg"> </IMG>

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+.
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
vuott is in the usergroup ‘Regular’

Piper984 said

I made some progress on my own

Code (gambas)

  1. oSNK = New MediaControl(oPipeline, "ximagesink")
Bravo, so you discovered that with "videotestsrc" you need the "ximagesink" plugin.


Piper984 said

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

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
vuott is in the usergroup ‘Regular’
…with audio (mono-tone) too:  :D

Code (gambas)

  1. Public Sub Button1_Click()
  2.  
  3.   Dim pl1, pl2 As Mediapipeline
  4.   Dim src1, src2, con, res, snk1, snk2 As MediaControl
  5.    
  6. ' "Pipeline" dedicated to video:
  7.   pl1 = New MediaPipeline
  8.   src1 = New MediaControl(pl1, "videotestsrc")
  9.   src1["is-live"] = True
  10.   src1["horizontal-speed"] = 1
  11.   snk1 = New MediaControl(pl1, "xvimagesink")
  12.   src1.LinkTo(snk1)
  13.   snk1.SetWindow(drawingArea1)
  14.  
  15. ' "Pipeline" dedicated to audio:
  16.   pl2 = New MediaPipeline
  17.   src2 = New MediaControl(pl2, "audiotestsrc")
  18.   con = New MediaControl(pl2, "audioconvert")
  19.   res = New MediaControl(pl2, "audioresample")
  20.   snk2 = New MediaControl(pl2, "autoaudiosink")
  21.   src2.LinkTo(con)
  22.   con.LinkTo(res)
  23.   res.LinkTo(snk2)
  24.  
  25.   pl1.play()
  26.   pl2.play()
  27.  
  28.   Do
  29.     Wait 0.01
  30.   Loop
  31.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.