Catturare immagini di una finestra di un programma e farne un file audio-video OGG-Theora con le funzioni esterne del API di GStreamer

Da Gambas-it.org - Wikipedia.

Con le risorse della libreria "libgstreamer-1.0.so " è possibile catturare immagini di quanto avviene in una finestra di un programma e farne un file video OGG-Theora comprensivo di audio. Va detto che ovviamente questa possibilità è estesa anche alla Scrivania (Desktop), e che sarà catturato anche il puntatore del mouse.

Per individuare la "finestra", che si intende registrare, bisognerà passare alla proprietà "xid" del plugin "ximagesrc" il numero identificativo della finestra medesima. Per la Scrivania è anche possibile impostare più semplicemente il suo ID di default uguale a 0 (zero).

Per catturare anche l'audio, bisognerà ovviamente attivare il microfono oppure il dispositivo audio interno di sistema.

Mostriamo un esempio pratico, nel quale si cattureranno immagini di quanto accade sulla Scrivania e si produrrà con esse un file video-audio OGG:

Private video As Pointer


Library "libgstreamer-1.0"

Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING

' gst_init (int *argc, char **argv[])
' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Private Extern gst_init(argc As Pointer, argv As Pointer)

' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
' Create a new pipeline based on command line syntax.
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer

' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
' Sets the state of the element.
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer

' void gst_object_unref(gpointer object)
' Decrements the reference count on object.
Private Extern gst_object_unref(gobject As Pointer)


Public Sub Button1_Click()
  
 gst_init(0, 0)
 
' Questa pipeline consente di registrare in un file audio-video OGG:
 video = gst_parse_launch("ximagesrc xid=0x00 ! video/x-raw,framerate=1/1 ! videoconvert ! queue ! theoraenc ! queue ! " &
                          "mux. alsasrc ! audio/x-raw,rate=22050,channels=1,depth=8 ! queue ! audioconvert ! queue ! " &
                          "vorbisenc ! queue ! mux. oggmux name=mux ! filesink location=/tmp/prova.ogg", 0)
                          
' Avvia la ripresa audio-video:
 gst_element_set_state(video, GST_STATE_PLAYING)
  
End


Public Sub Button2_Click()
 
' Ferma la registrazione audio-video:
 gst_element_set_state(video, GST_STATE_NULL)
 gst_object_unref(video)
 
 Print "Registrazione video-audio fermata !"
  
End