Differenze tra le versioni di "Eseguire un file Video con le funzioni esterne del API di Libmpv"

Da Gambas-it.org - Wikipedia.
(Creata pagina con "La libreria esterna '''Libmpv''' consente di eseguire diversi formati di file video. Per poter utilizzare le risorse di ''Mpv'', è necessario avere installata e richiamare i...")
 
Riga 13: Riga 13:
 
  ' ''Create a new mpv instance.''</font>
 
  ' ''Create a new mpv instance.''</font>
 
  Private Extern mpv_create() As Pointer
 
  Private Extern mpv_create() As Pointer
 
<FONT Color=gray>' ''int mpv_set_option_string(mpv_handle *ctx, const char *name, const char *data)''
 
' ''Convenience function to set an option to a string value.''</font>
 
Private Extern mpv_set_option_string(ctx As Pointer, name As String, data As String) As Integer
 
 
<FONT Color=gray>' ''int mpv_set_option(mpv_handle *ctx, const char *name, mpv_format format, void *data)''
 
' ''Set an option.''</font>
 
Private Extern mpv_set_option(ctx As Pointer, name As String, format_ As Integer, data As Pointer) As Integer
 
 
   
 
   
 
  <FONT Color=gray>' ''int mpv_initialize(mpv_handle *ctx)''
 
  <FONT Color=gray>' ''int mpv_initialize(mpv_handle *ctx)''
Riga 29: Riga 21:
 
  ' ''Send a command to the player.''</font>
 
  ' ''Send a command to the player.''</font>
 
  Private Extern mpv_command(ctx As Pointer, args As String[]) As Integer
 
  Private Extern mpv_command(ctx As Pointer, args As String[]) As Integer
 +
 +
<FONT Color=gray>' ''int mpv_set_property(mpv_handle *ctx, const char *name, mpv_format format, void *data)''
 +
' ''Set a property.''</font>
 +
Private Extern mpv_set_property(ctx As Pointer, name As String, format_ As Integer, data As Pointer) As Integer
 
   
 
   
 
  <FONT Color=gray>' ''int mpv_get_property(mpv_handle *ctx, const char *name, mpv_format format, void *data)''
 
  <FONT Color=gray>' ''int mpv_get_property(mpv_handle *ctx, const char *name, mpv_format format, void *data)''
Riga 52: Riga 48:
 
   Dim mpv As Pointer
 
   Dim mpv As Pointer
 
   Dim filevideo As String
 
   Dim filevideo As String
   Dim d, l As Long
+
   Dim d, l, v As Long
 
    
 
    
 
   filevideo = "<FONT Color=gray>''/percorso/del/file/audio''</font>"
 
   filevideo = "<FONT Color=gray>''/percorso/del/file/audio''</font>"
Riga 66: Riga 62:
 
    
 
    
 
   mpv_command(mpv, ["loadfile", filevideo, Null])
 
   mpv_command(mpv, ["loadfile", filevideo, Null])
 +
 
 +
<FONT Color=gray>' ''Imposta il volume. 0 significa silenzio, 100 significa nessuna riduzione del volume o amplificazione.''
 +
' ''Valori superiori a 100 amplificano il volume di uscita.</font>
 +
  v = 50
 +
  mpv_set_property(mpv, "volume", MPV_FORMAT_INT64, VarPtr(v))
 
    
 
    
 
   Repeat
 
   Repeat

Versione delle 17:24, 25 ago 2020

La libreria esterna Libmpv consente di eseguire diversi formati di file video.

Per poter utilizzare le risorse di Mpv, è necessario avere installata e richiamare in Gambas la libreria condivisa: "libmpv.so.1.107.0"

Mostriamo un semplice esempio:

Library "libmpv:1.107.0"

Private Enum MPV_FORMAT_NONE = 0, MPV_FORMAT_STRING, MPV_FORMAT_OSD_STRING, MPV_FORMAT_FLAG,
             MPV_FORMAT_INT64, MPV_FORMAT_DOUBLE, MPV_FORMAT_NODE, MPV_FORMAT_NODE_ARRAY,
             MPV_FORMAT_NODE_MAP, MPV_FORMAT_BYTE_ARRAY

' mpv_handle *mpv_create(void)
' Create a new mpv instance.
Private Extern mpv_create() As Pointer

' int mpv_initialize(mpv_handle *ctx)
' Initialize an uninitialized mpv instance.
Private Extern mpv_initialize(ctx As Pointer) As Integer

' int mpv_command(mpv_handle *ctx, const char **args)
' Send a command to the player.
Private Extern mpv_command(ctx As Pointer, args As String[]) As Integer

' int mpv_set_property(mpv_handle *ctx, const char *name, mpv_format format, void *data)
' Set a property.
Private Extern mpv_set_property(ctx As Pointer, name As String, format_ As Integer, data As Pointer) As Integer

' int mpv_get_property(mpv_handle *ctx, const char *name, mpv_format format, void *data)
' Read the value of the given property.
Private Extern mpv_get_property(ctx As Pointer, name As String, format_ As Integer, data As Pointer)

' void mpv_terminate_destroy(mpv_handle *ctx)
' Disconnect and destroy the mpv_handle.
Private Extern mpv_terminate_destroy(ctx As Pointer)


Library "libc:6"

Private Const LC_NUMERIC As Integer = 1

' char *setlocale (int __category, const char *__locale)
' Set and/or return the current locale.
Private Extern setlocale(__category As Integer, __locale As String) As Pointer


Public Sub Main()
 
 Dim mpv As Pointer
 Dim filevideo As String
 Dim d, l, v As Long
 
 filevideo = "/percorso/del/file/audio"
 Print "File video: "; filevideo
 Print
 
 setlocale(LC_NUMERIC, "C")
 
 mpv = mpv_create()
 If mpv == 0 Then Error.Raise("Errore !")
 
 mpv_initialize(mpv)
 
 mpv_command(mpv, ["loadfile", filevideo, Null])
 
' Imposta il volume. 0 significa silenzio, 100 significa nessuna riduzione del volume o amplificazione.
' Valori superiori a 100 amplificano il volume di uscita.
 v = 50
 mpv_set_property(mpv, "volume", MPV_FORMAT_INT64, VarPtr(v))
 
 Repeat
   mpv_get_property(mpv, "duration", MPV_FORMAT_INT64, VarPtr(d))
   Wait 0.01
 Until d > 0
 
 Repeat
   mpv_get_property(mpv, "time-pos", MPV_FORMAT_INT64, VarPtr(l))
   Write "\e[0m\rDurata: " & Date(0, 0, 0, 0, 0, 0, CInt(d) * 1000) &
         "   Tempo trascorso: \e[31m" & Date(0, 0, 0, 0, 0, 0, CInt(l) * 1000)
   Wait 0.001
 Until l >= d
 
 mpv_terminate_destroy(mpv)
 
End


Riferimenti