mediaview capture

Ask about the individual Gambas components here.
Post Reply
User avatar
sadams54
Posts: 139
Joined: Monday 9th July 2018 3:43am
Contact:

mediaview capture

Post by sadams54 »

I can't find it but is there a way to capture the stream coming in on a mediaview control so it can be saved as a video file?

if it is not possible is there a control that will do this?
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: mediaview capture

Post by cogier »

Have you thought about using Youtube.dl? This can be controlled from within Gambas very easily and is available from the software repository in Ubuntu, Mint etc. and probably other distros as well.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: mediaview capture

Post by BruceSteers »

Not easily i should think.

MediaView is limited in what it can do,
you might find something with MediaControl which is the gambas GStreamer interface

You will need to search for if it can be done with GStreamer and if yes then figure out how to get MediaControl to do the same.
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: mediaview capture

Post by vuott »

BruceSteers has correctly suggested to you to use the "MediaControl" Class of the gb.media Component, which however should be used for example in conjunction with the "MediaPipeline" Class.
Well, now I show below a simple code to capture the video - video only, no audio - played in a "MediaView" Control of the gb.media Component. From those capturated data a video file of the "Matroska" format will then be created.
The "MediaView" Control consists of "Children" and "sub-Children" (...grandchildren).
One of these "sub-Children" is a "DrawingArea", which is the Object with which the "MediaView" Control displays images and videos.
We will identify the identification number of this "DrawingArea", constitutive of the "MediaView" Control, and with a particular Property of the "ximagesrc" plugin we will capture the video it shows.
The following code is only illustrative, therefore we will capture only the video data of a video file uploaded and executed by the "MediaView" Control.
Event Evento

Public Sub Form_Open()

  Me.Show
  Wait 0.1

  MediaView1.URL = "/path/of/media/we/want/to/capture"
  
  Repeat 
     Wait 0.01
  Until MediaView1.Position > 0.0
  
  Raise Evento

End

Public Sub Form_Evento()
 
  Dim ob As Object
  Dim pn1, pn2 As Panel
  Dim DrawingArea1 As DrawingArea
  Dim pl As MediaPipeline
  Dim src, cnv, enc, mux, snk As MediaControl
 
' ...the happy "MediaView" family:
  ob = MediaView1.Children[0]
  pn1 = ob.Children[0]
  pn2 = pn1.Children[0]
  DrawingArea1 = pn2.Children[0]
 
  pl = New MediaPipeline 
 
  src = New MediaControl(pl, "ximagesrc")
' Assign to the property "xid" the "DrawingArea" identification number:
  src["xid"] = DrawingArea1.Id
  cnv = New MediaControl(pl, "videoconvert")
  enc = New MediaControl(pl, "x264enc")
  mux = New MediaControl(pl, "matroskamux") 
  snk = New MediaControl(pl, "filesink")
' Set the path of final video file of mkv format (Matroska):
  snk["location"] = "/tmp/file.mkv"
  
' Link the "GStreamer" plugins:
  src.LinkTo(cnv)
  cnv.LinkTo(enc)
  enc.LinkTo(mux)
  mux.LinkTo(snk)
 
  pl.play

  Wait MediaView1.Duration
  
  Print "Video file created"

End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
sadams54
Posts: 139
Joined: Monday 9th July 2018 3:43am
Contact:

Re: mediaview capture

Post by sadams54 »

I will have to take some time going thru that code you provided. hurts my brain right now.

Let me splain.... I have gotten very pissed off with zoneminder and monitor which are used for security cameras. both are flakey and difficult to keep working. Yes zoneminder especially. I want to write a new app that works simple and reliable. this means monitoring multiple cameras for changes and recording. So please any help in this is appreciated and anybody that is giving answers please give them with this goal in mind.
GrantXTV
Posts: 17
Joined: Tuesday 31st October 2023 9:20pm

Re: mediaview capture

Post by GrantXTV »

Hi,

I am trying to go the other way and can't seem find a way to stream out of mediaview, here what I have been working on:

Public bo As Boolean

Public Sub Form_Open()
bo = True
End

Public Sub send_Click()
Dim pl As MediaPipeline
Dim src, aco, wen, snk, rtp, udp As MediaControl
Dim flt As MediaFilter
pl = New MediaPipeline
src = New MediaControl(pl, "alsasrc")
aco = New MediaControl(pl, "audioconvert")
flt = New MediaFilter(pl, "audio/x-raw,rate=44100,depth=16,channels=2,width=16,signed=true")
rtp = New MediaControl(pl, "rtpL24pay")
udp = New MediaControl(pl, "udpsink host=192.168.3.15 port=5001")
src.LinkTo(aco)
aco.LinkTo(flt)
flt.LinkTo(rtp)
rtp.LinkTo(udp)
pl.Play()
While bo
TextBox1.Text = Str(Time(0, 0, 0, pl.Position * 1000))
Wait 0.01
Wend
pl.Stop()
pl.Close()
Quit
End

Public Sub stop_Click()
bo = False
End

Public Sub Form_Close()
bo = False
End

This is what I tested on gstreamer and it works:
'gst-launch-1.0 alsasrc ! audioconvert ! audio/x-raw,rate=48000,depth=8,channels=2,width=16 ! rtpL24pay ! udpsink host=192.168.3.15 port=5001

What is best way to do this using mediaview, as I have not found a way to get this to work?
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: mediaview capture

Post by vuott »

GrantXTV wrote: Monday 1st January 2024 10:15pm udp = New MediaControl(pl, "udpsink host=192.168.3.15 port=5001")
"HOST" and "PORT" are properties of the "udpsink " GStreamer Plugin.
Therefore they should be highlighted and separated.
......
udp = New MediaControl(pl, "udpsink")
udp["host"] = "192.168.3.15"
udp["port"] = 5001
......

GrantXTV wrote: Monday 1st January 2024 10:15pm This is what I tested on gstreamer and it works:
'gst-launch-1.0 alsasrc ! audioconvert ! audio/x-raw,rate=48000,depth=8,channels=2,width=16 ! rtpL24pay ! udpsink host=192.168.3.15 port=5001

What is best way to do this using mediaview, as I have not found a way to get this to work?
If you want to use "gst-launch-1.0 ", you will have to use its corresponding external function "gst_parse_launch()", since it has not been implemented in the Gambas gb.media Component.

Exemplum:
https://www.gambas-it.org/wiki/index.ph ... aunch()%27
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Post Reply