Ciao, ho un problema nell'utilizzo di una MediaPipeline.
Ho il seguente codice:
f.src = New MediaControl(f.pl, "v4l2src")
'Troviamo il percorso del device!
Dim pDev As String = Utility.GetPercorsoDevice(ModuloGenerale.settaggioCorrente.FriendlyName, ModuloGenerale.settaggioCorrente.DevPath)
f.src["device"] = pDev '"/dev/video2"
'creiamo il MediaFilter usando il formato associato al settaggio
Dim strFrmt As String = ModuloGenerale.settaggioCorrente.MajorType1
Dim strWidth As String = Str(ModuloGenerale.settaggioCorrente.Width1)
Dim strHeight As String = Str(ModuloGenerale.settaggioCorrente.Height1)
Dim strFramerate As String = Str(ModuloGenerale.settaggioCorrente.BitRate1)
Dim stringaMediaFilter As String = "video/x-raw, format=" & strFrmt & ", width=" & strWidth & ", height=" & strHeight & ", framerate=" & strFramerate & "/1"
f.ftr = New MediaFilter(f.pl, stringaMediaFilter)
omissis
f.src.LinkTo(f.ftr) 'here the error!!!
In pratica, all'istruzione "linkTo" ottengo un errore se il formato è diverso da "UYVY" (quindi con MJPEG e YUYV ad esempio).
Cosa sbaglio? Non credo dipenda dalla mancata installazione di codec su ubuntu.
Grazie
Ho una funzione, che viene chiamata all'interno di un ciclo:
Private Function TestaRisoluzione(frndName As String, dPath As String, formato As String, w As Integer, h As Integer, fps As Integer) As Boolean
Dim tmpPL As New MediaPipeline
Dim tmpSRC As New MediaControl(tmpPL, "v4l2src")
Dim tmpDEV As String = Utility.GetPercorsoDevice(frndName, dPath)
tmpSRC["device"] = tmpDEV
'creiamo il MediaFilter usando il formato associato al settaggio
Dim strFrmt As String = formato
Dim strWidth As String = Str(w)
Dim strHeight As String = Str(h)
Dim strFramerate As String = Str(fps)
Dim stringaMediaFilter As String = "video/x-raw, format=" & strFrmt & ", width=" & strWidth & ", height=" & strHeight & ", framerate=" & strFramerate & "/1"
Dim tmpFTR As New MediaFilter(tmpPL, stringaMediaFilter)
Dim tmpCNV As New MediaControl(tmpPL, "videoconvert")
Dim tmpSNK As New MediaControl(tmpPL, "xvimagesink")
Debug stringaMediaFilter
tmpSRC.LinkTo(tmpFTR)
tmpFTR.LinkTo(tmpCNV)
tmpCNV.LinkTo(tmpSNK)
'se siamo arrivati qui, non abbiamo rilevato errori ===> "buttiamo tutto" e ritorniamo True
tmpPL.Close
Return True
Catch
Debug Error.Text
Return False
End
L'esecuzione porta i seguenti messaggi (ho aggiunto di proposito le istruzioni "Debug"):
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=640, height=480, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=640, height=360, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=320, height=240, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=1024, height=768, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=1280, height=720, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=1920, height=1080, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=2048, height=1536, framerate=20/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=2592, height=1944, framerate=10/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=MJPG, width=1280, height=960, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=640, height=480, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=640, height=360, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=320, height=240, framerate=30/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=1024, height=768, framerate=10/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=1280, height=720, framerate=10/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=1920, height=1080, framerate=5/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=2048, height=1536, framerate=4/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=2592, height=1944, framerate=2/1
Utility.TestaRisoluzione.176: Unable to link controls
Utility.TestaRisoluzione.167: video/x-raw, format=YUYV, width=1280, height=960, framerate=5/1
Utility.TestaRisoluzione.176: Unable to link controls
Ritengo il problema sia nel collegare opportunamente i filtri. Ma come si fa a sapere COSA e COME collegare? la documentazione GStreamer sui Pad? (nella quale ad esempio il formato MJPG non viene mai citato)... Io proprio non capisco!! :hatecomputer: :hard:
EDIT: ho provato a togliere il set di "format", ad esempio:
video/x-raw, width=1280, height=960, framerate=30/1
funziona, ma così non ho controllo di quale formato venga utilizzato...
Devi fare una ricerca su internet e provare gli esempi, in primo luogo in terminale usando il comando "gst-launch-1.0".
Per esempio riguardo a MJPG noto che il filtro è "image/jpeg,width=...etc...etc."
https://stackoverflow.com/questions/61887211/using-v4l2loopback-and-gstreamer-with-mjpeg-cameras
https://stackoverflow.com/questions/51740966/gstreamer-capture-and-store-mjpeg-from-webcam
Se io uso questo codice, funziona sostanzialmente, ma il video è lentissimo:
Public Sub Main()
Dim pl As New MediaPipeline
Dim src As New MediaControl(pl, "v4l2src")
Dim ftr As New MediaFilter(pl, "image/jpeg, width=640, height=360, framerate=30/1")
Dim par As New MediaControl(pl, "jpegparse")
Dim jdc As New MediaControl(pl, "jpegdec")
Dim snk As New MediaControl(pl, "xvimagesink")
src["device"] = "/dev/video0"
src.LinkTo(ftr)
ftr.LinkTo(par)
par.LinkTo(jdc)
jdc.LinkTo(snk)
pl.play()
While True
Wait 0.01
Wend
End
Se lo provo in terminale, infatti, mi dice:
There may be a timestamping problem, or this computer is too slow.
E come faccio a sapere/scoprire queste cose?
Oltre agli esempi in giro per internet devi anche dare uno sguardo alla risorsa GStreamer, sulla quale ovviamente si base il Componente gb.media di Gambas, e studiarla:
https://gstreamer.freedesktop.org/documentation/tutorials/index.html?gi-language=c