Autore Topic: come riprodurre un video clonando la pipeline gstreamer con gst_parse_launch  (Letto 315 volte)

Offline allegfede

  • Gran Maestro dei Gamberi
  • *****
  • Post: 738
    • Mostra profilo
Per VUOTT, se vuoi puoi integrare la WIKI con questo cosice (ho attinto all'esempio del midi modificandolo ai miei scopi):

Codice: [Seleziona]
' Gambas class file

Private video As Pointer

Private posizione As Long
Private durata As Long
Private dur As Date
Private pos As Date
Private OldPos As Date  'alle volte il video dura un tot ma il cirsore (pos) non raggiunge mai la fine anche se la riproduzione e' finita ... quindi conto piu' volte se pos=old_pos
Private threshold As Integer  'e questo controllo lo posso fallire al massimo per 3 tentativi
Const numero_massimo As Integer = 5

Library "libgstreamer-1.0"

Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
Private Const GST_FORMAT_TIME As Integer = 3
Private stato As Integer = 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

' gboolean gst_element_query_duration(GstElement *element, GstFormat format, gint64 *duration)
' Queries an element for the total stream duration in nanoseconds.
Private Extern gst_element_query_duration(gselement As Pointer, formatI As Integer, duration As Pointer) As Boolean
 
' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
' Queries an element for the stream position in nanoseconds.
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean

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


Public Sub ToggleButton1_Click()
Dim fileVideo As String

  If ToggleButton1.Value = True Then
    fileVideo = Media.URL("/home/v1p3r/Video/unboxing e recensione scarpe trekking cinesi/pubblicita ufficiale aliexpress - cunge.mp4")
   
    ToggleButton1.Text = "STOP"
   
    Print fileVideo
   
    gst_init(0, 0)
   
    video = gst_parse_launch("uridecodebin uri=" & filevideo & " name=decode decode. ! interlace field-pattern=1 ! videoconvert ! video/x-raw,format=UYVY ! videoscale ! video/x-raw,width=720,height=576 ! videorate ! video/x-raw,framerate=25/1 ! autovideosink decode. ! audioconvert ! autoaudiosink", 0)
    'video = gst_parse_launch("uridecodebin uri=" & fileVideo & " name=decode decode. ! interlace field-pattern=1 ! videoconvert ! video/x-raw,format=UYVY ! videoscale ! video/x-raw,width=720,height=576 ! videorate ! video/x-raw,framerate=25/1 ! decklinkvideosink mode=3 decode. ! audioconvert ! decklinkaudiosink", 0)
 
  ' Avviamo la riproduzione del file Midi:
    gst_element_set_state(video, GST_STATE_PLAYING)
   
    threshold = numero_massimo 'il limite delle volte che il cursore di posizione puo' rimanere fermo (dopo si da per scontato che il video e' terminato)
    Timer1.Start
    Else
      ToggleButton1.Text = "PLAY"
      gst_element_set_state(video, GST_STATE_NULL)
 
      gst_object_unref(video)
  Endif

 

End

Public Sub Button1_Click()
 
 If ToggleButton1.Value = True Then
   Timer1.Stop
   ToggleButton1.Value = False
 Endif
 
End



Public Sub Timer1_Timer()

   If (posizione = 0) Or (durata > posizione) Then
      gst_element_query_duration(video, GST_FORMAT_TIME, VarPtr(durata))
      gst_element_query_position(video, GST_FORMAT_TIME, VarPtr(posizione))
      Print "\rDurata: " & Date(0, 0, 0, 0, 0, 0, durata / 1000000) & "      Pos. " & Date(0, 0, 0, 0, 0, 0, posizione / 1000000)
      Else
        Print "\rPlay Completato"
        ToggleButton1.Value = False
        Timer1.stop
   Endif
   
     'controllo se video terminato ma posizione non aggiornata
  If (posizione > 0) And (Date(0, 0, 0, 0, 0, 0, posizione / 1000000) = OldPos) Then
      If threshold = 0 Then
        Print "\rPlay Completato"
        ToggleButton1.Value = False
        Timer1.stop
        Else
          threshold = threshold - 1
      Endif
      Else
      OldPos = Date(0, 0, 0, 0, 0, 0, posizione / 1000000)
      threshold = numero_massimo
   Endif

End


PS: io esco su una scheda video particolare (intensity pro, ma va bene anche su decklink della black magic), commentando il "video = gst_parse_launch( ..." e levando il commento all'altro potrete usare un output standard.
« Ultima modifica: 01 Aprile 2019, 18:15:31 da allegfede »
se corri, morirai stanco (motto degli sniper)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.269
  • Ne mors quidem nos iunget
    • Mostra profilo
Per VUOTT, se vuoi puoi integrare la WIKI con questo codice

« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline allegfede

  • Gran Maestro dei Gamberi
  • *****
  • Post: 738
    • Mostra profilo
non l'ho fatto mai :-(

e poi il 70% del codice e' merito tuo :D
se corri, morirai stanco (motto degli sniper)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.269
  • Ne mors quidem nos iunget
    • Mostra profilo
Mandami con un messaggio privato:

1) Titolo che deve assumere la pagina della wiki;

2) relazione introduttiva al codice (per spiegare cosa è e a che serve);

3) il codice.
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »