Differenze tra le versioni di "Ottenere informazioni generali e metadati da file audio-video con le risorse del API di VLC"

Da Gambas-it.org - Wikipedia.
 
(3 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
 
Con la libreria VLC è possibile anche estrarre da un file multimediale informazioni generali ed evenuali metadati.
 
Con la libreria VLC è possibile anche estrarre da un file multimediale informazioni generali ed evenuali metadati.
  
E' necessario avere installata nel sistema e richiamare in Gambas la libreria condivisa: "''libvlc.so.5.6.0''"
+
E' necessario avere installata nel sistema e richiamare in Gambas la libreria condivisa: "''libvlc.so.5.6.1'' ".
 
 
  
 
Mostriamo un esempio:
 
Mostriamo un esempio:
  Library "libvlc:5.6.0"
+
  Library "libvlc:5.6.1"
 
   
 
   
 
  Public Struct video_track_t
 
  Public Struct video_track_t
Riga 71: Riga 70:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
   
 
   
   Dim inst, md, p1, p2 As Pointer
+
   Dim inst, md, p As Pointer
 
   Dim tm As Long
 
   Dim tm As Long
 
   Dim b As Byte
 
   Dim b As Byte
Riga 88: Riga 87:
 
                             "Transposed", "Rotated 90 degrees clockwise", "Rotated 90 degrees anti-clockwise", "Anti-transposed"]
 
                             "Transposed", "Rotated 90 degrees clockwise", "Rotated 90 degrees anti-clockwise", "Anti-transposed"]
 
   
 
   
   s = "<FONT Color=gray>''/percorso/del/file/video''</font>"
+
   s = "<FONT Color=darkgreen>''/percorso/del/file/video''</font>"
 
   Print "Nome file:  "; s
 
   Print "Nome file:  "; s
 
    
 
    
 
   inst = libvlc_new(0, Null)
 
   inst = libvlc_new(0, Null)
 +
  If inst == 0 Then Error.Raise("Errore !")
 
    
 
    
 
   md = libvlc_media_new_path(inst, s)
 
   md = libvlc_media_new_path(inst, s)
 +
  If md == 0 Then Error.Raise("Errore !")
 
    
 
    
 
   libvlc_media_parse_with_options(md, libvlc_media_parse_local, 0)
 
   libvlc_media_parse_with_options(md, libvlc_media_parse_local, 0)
 
 
  Sleep 0.1
 
 
    
 
    
 
   tm = libvlc_media_get_duration(md)
 
   tm = libvlc_media_get_duration(md)
Riga 109: Riga 108:
 
    
 
    
 
   Print "\n- Codificatore -"
 
   Print "\n- Codificatore -"
  p1 = Alloc(SizeOf(gb.Pointer), 3)
+
   p2 = VarPtr(p1)
+
   Repeat
 
+
    Wait 0.01
  i = libvlc_media_tracks_get(md, VarPtr(p2))
+
    i = libvlc_media_tracks_get(md, VarPtr(p))
 +
  Until i > 0
 +
 
   For b = 0 To i - 1
 
   For b = 0 To i - 1
     tp = Int@(Pointer@(p2 + (SizeOf(gb.Pointer) * b)) + 12)
+
     tp = Int@(Pointer@(p + (SizeOf(gb.Pointer) * b)) + 12)
     Print "Codifica:        "; libvlc_media_get_codec_description(tp, Int@(Pointer@(p2 + (SizeOf(gb.Pointer) * b))))
+
     Print "Codifica:        "; libvlc_media_get_codec_description(tp, Int@(Pointer@(p + (SizeOf(gb.Pointer) * b))))
 
     Print "Tipo media:      ";
 
     Print "Tipo media:      ";
 
     Select Case tp
 
     Select Case tp
Riga 122: Riga 123:
 
       Case 0
 
       Case 0
 
         Print "Audio"
 
         Print "Audio"
         at = Pointer@(Pointer@(p2 + (SizeOf(gb.Pointer))) + 24)
+
         at = Pointer@(Pointer@(p + (SizeOf(gb.Pointer))) + (SizeOf(gb.Pointer) * 3))
 
         With at
 
         With at
 
           Print "Canali:          "; at.i_channels
 
           Print "Canali:          "; at.i_channels
Riga 129: Riga 130:
 
       Case 1
 
       Case 1
 
         Print "Video"
 
         Print "Video"
         vt = Pointer@(Pointer@(p2) + 24)
+
         vt = Pointer@(Pointer@(p) + (SizeOf(gb.Pointer) * 3))
 
         With vt
 
         With vt
           Print "Risoluzione:     "; .i_width; "x"; .i_height
+
           Print "Dimensione:     "; .i_width; "x"; .i_height
 
           Print "Fotogrammi/sec.: "; .i_frame_rate_num
 
           Print "Fotogrammi/sec.: "; .i_frame_rate_num
 
           Print "Orientazione:    "; orient[.i_orientation]
 
           Print "Orientazione:    "; orient[.i_orientation]
Riga 140: Riga 141:
 
     Print
 
     Print
 
   Next
 
   Next
 
+
 
 
 
  <FONT Color=gray>' ''Libera la memoria:''</font>
 
  <FONT Color=gray>' ''Libera la memoria:''</font>
  Free(p1)
 
 
   libvlc_media_release(md)
 
   libvlc_media_release(md)
 
   libvlc_release(inst)
 
   libvlc_release(inst)
 
    
 
    
  '''End'''
+
  End
 
+
Il seguente codice è simile al precedente, ma un po' semplificato inserendo un'ulteriore ''Struttura'' della libreria VLC:
 
+
  Library "libvlc:5.6.1"
Il codice precedente un po' semplificato inserendo una Struttura della libreria VLC:
 
  Library "libvlc:5.6.0"
 
 
   
 
   
 
  Public Struct video_track_t
 
  Public Struct video_track_t
Riga 230: Riga 227:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
   
 
   
   Dim inst, md, p1, p2 As Pointer
+
   Dim inst, md, p As Pointer
 
   Dim tm As Long
 
   Dim tm As Long
 
   Dim b As Byte
 
   Dim b As Byte
Riga 248: Riga 245:
 
                             "Transposed", "Rotated 90 degrees clockwise", "Rotated 90 degrees anti-clockwise", "Anti-transposed"]
 
                             "Transposed", "Rotated 90 degrees clockwise", "Rotated 90 degrees anti-clockwise", "Anti-transposed"]
 
   
 
   
   s = "<FONT Color=gray>''/percorso/del/file/video''</font>"
+
   s = "<FONT Color=darkgreen>''/percorso/del/file/video''</font>"
 
   Print "Nome file:  "; s
 
   Print "Nome file:  "; s
 
    
 
    
 
   inst = libvlc_new(0, Null)
 
   inst = libvlc_new(0, Null)
 +
  If inst == 0 Then Error.Raise("Errore !")
 
    
 
    
 
   md = libvlc_media_new_path(inst, s)
 
   md = libvlc_media_new_path(inst, s)
 +
  If md == 0 Then Error.Raise("Errore !")
 
    
 
    
 
   libvlc_media_parse_with_options(md, libvlc_media_parse_local, 0)
 
   libvlc_media_parse_with_options(md, libvlc_media_parse_local, 0)
 
 
  Sleep 0.1
 
 
    
 
    
 
   tm = libvlc_media_get_duration(md)
 
   tm = libvlc_media_get_duration(md)
Riga 269: Riga 266:
 
    
 
    
 
   Print "\n- Codificatore -"
 
   Print "\n- Codificatore -"
  p1 = Alloc(SizeOf(gb.Pointer), 3)
+
   p2 = VarPtr(p1)
+
   Repeat
 
+
    Wait 0.01
  i = libvlc_media_tracks_get(md, VarPtr(p2))
+
    i = libvlc_media_tracks_get(md, VarPtr(p))
    
+
   Until i > 0
 +
 
   For b = 0 To i - 1
 
   For b = 0 To i - 1
     mt = Pointer@(p2 + (SizeOf(gb.Pointer) * b))
+
     mt = Pointer@(p + (SizeOf(gb.Pointer) * b))
 
     tp = mt.i_type
 
     tp = mt.i_type
 
      
 
      
Riga 299: Riga 297:
 
         vt = mt.union
 
         vt = mt.union
 
         With vt
 
         With vt
           Print "Risoluzione:     "; .i_width; "x"; .i_height
+
           Print "Dimensione:     "; .i_width; "x"; .i_height
 
           Print "Fotogrammi/sec.: "; .i_frame_rate_num
 
           Print "Fotogrammi/sec.: "; .i_frame_rate_num
 
           Print "Orientazione:    "; orient[.i_orientation]
 
           Print "Orientazione:    "; orient[.i_orientation]
Riga 311: Riga 309:
 
    
 
    
 
  <FONT Color=gray>' ''Libera la memoria:''</font>
 
  <FONT Color=gray>' ''Libera la memoria:''</font>
  Free(p1)
 
 
   libvlc_media_release(md)
 
   libvlc_media_release(md)
 
   libvlc_release(inst)
 
   libvlc_release(inst)
 
    
 
    
  '''End'''
+
  End
  
  

Versione attuale delle 16:10, 29 giu 2024

Con la libreria VLC è possibile anche estrarre da un file multimediale informazioni generali ed evenuali metadati.

E' necessario avere installata nel sistema e richiamare in Gambas la libreria condivisa: "libvlc.so.5.6.1 ".

Mostriamo un esempio:

Library "libvlc:5.6.1"

Public Struct video_track_t
  i_height As Integer
  i_width As Integer
  i_sar_num As Integer
  i_sar_den As Integer
  i_frame_rate_num As Integer
  i_frame_rate_den As Integer
  i_orientation As Integer
  i_projection As Integer
  f_yaw As Single
  f_pitch As Single
  f_roll As Single
  f_field_of_view As Single
  i_multiview As Byte
End Struct

Public Struct audio_track_t
  i_channels As Integer
  i_rate As Integer
End Struct

Private Enum libvlc_media_parse_local = 0,
             libvlc_media_parse_network,
             libvlc_media_fetch_local,
             libvlc_media_fetch_network = 4,
             libvlc_media_do_interact = 8

 'libvlc_instance_t * libvlc_new (int argc, const char *const *argv)
' Create And initialize a libvlc instance.
Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer

 'libvlc_media_t * libvlc_media_new_path (libvlc_instance_t *p_instance, const char *path)
' Create a media for a certain file path.
Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer

 'int libvlc_media_parse_with_options (libvlc_media_t *p_md, libvlc_media_parse_flag_t parse_flag, int timeout)
' Parse the media asynchronously with options.
Private Extern libvlc_media_parse_with_options(p_md As Pointer, parse_flag As Integer, timeout As Integer) As Integer

 'libvlc_time_t libvlc_media_get_duration(libvlc_media_t *p_md)
' Get duration (in ms) of media descriptor object item.
Private Extern libvlc_media_get_duration(p_md As Pointer) As Long

 'char* libvlc_media_get_meta (libvlc_media_t * p_md, libvlc_meta_t e_meta)
' Read the meta of the media.
Private Extern libvlc_media_get_meta(p_md As Pointer, e_meta As Integer) As String

 'unsigned libvlc_media_tracks_get (libvlc_media_t * p_md, libvlc_media_track_t *** tracks)
' Get media descriptor's elementary streams description.
Private Extern libvlc_media_tracks_get(p_md As Pointer, tracks As Pointer) As Integer

 'const char * libvlc_media_get_codec_description (libvlc_track_type_t i_type, uint32_t i_codec)
' Get codec description from media elementary stream.
Private Extern libvlc_media_get_codec_description(i_type As Integer, i_codec As Integer) As String

 'void libvlc_media_release (libvlc_media_t *p_md)
' Decrement the reference count of a media descriptor object.
Private Extern libvlc_media_release(p_md As Pointer)

 'libvlc_release (libvlc_instance_t * p_instance)
' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
Private Extern libvlc_release(p_instance As Pointer)


Public Sub Main()

 Dim inst, md, p As Pointer
 Dim tm As Long
 Dim b As Byte
 Dim s As String
 Dim tp, i As Integer
 Dim vt As Video_track_t
 Dim at As Audio_track_t
 Dim meta As String[] = ["Title:", "Artist:", "Genre", "Copyright:", "Album", "TrackNumber:",
                         "Description:", "Rating:", "Date:", "Setting:", "URL:",
                         "Language:", "NowPlaying:", "Publisher:", "EncodedBy:", "ArtworkURL:",
                         "TrackID:", "TrackTotal:", "Director:", "Season:", "Episode:",
                         "ShowName:", "Actors:", "AlbumArtist:", "DiscNumber:", "DiscTotal:"]
 Dim orient As String[] = ["Normal", "Flipped horizontally", "Flipped vertically", "Rotated 180 degrees",
                           "Transposed", "Rotated 90 degrees clockwise", "Rotated 90 degrees anti-clockwise", "Anti-transposed"]

 s = "/percorso/del/file/video"
 Print "Nome file:  "; s
 
 inst = libvlc_new(0, Null)
 If inst == 0 Then Error.Raise("Errore !")
 
 md = libvlc_media_new_path(inst, s)
 If md == 0 Then Error.Raise("Errore !")
 
 libvlc_media_parse_with_options(md, libvlc_media_parse_local, 0)
 
 tm = libvlc_media_get_duration(md)
 Print "Durata:     "; Time(0, 0, 0, tm)
 
 Print "\n- Metadati -"
 For b = 0 To meta.Max
   s = libvlc_media_get_meta(md, b)
   If Not IsNull(s) Then Print meta[b]; String(17 - Len(meta[b]), Chr(32)); s
 Next
 
 Print "\n- Codificatore -"

 Repeat 
   Wait 0.01
   i = libvlc_media_tracks_get(md, VarPtr(p))
 Until i > 0

 For b = 0 To i - 1
   tp = Int@(Pointer@(p + (SizeOf(gb.Pointer) * b)) + 12)
   Print "Codifica:        "; libvlc_media_get_codec_description(tp, Int@(Pointer@(p + (SizeOf(gb.Pointer) * b))))
   Print "Tipo media:      ";
   Select Case tp
     Case -1
       Print "Sconosciuto"
     Case 0
       Print "Audio"
       at = Pointer@(Pointer@(p + (SizeOf(gb.Pointer))) + (SizeOf(gb.Pointer) * 3))
       With at
         Print "Canali:          "; at.i_channels
         Print "Frequenza camp.: "; at.i_rate
       End With
     Case 1
       Print "Video"
       vt = Pointer@(Pointer@(p) + (SizeOf(gb.Pointer) * 3))
       With vt
         Print "Dimensione:      "; .i_width; "x"; .i_height
         Print "Fotogrammi/sec.: "; .i_frame_rate_num
         Print "Orientazione:    "; orient[.i_orientation]
       End With
     Case 2
       Print "Testo"
   End Select
   Print
 Next

' Libera la memoria:
 libvlc_media_release(md)
 libvlc_release(inst)
 
End

Il seguente codice è simile al precedente, ma un po' semplificato inserendo un'ulteriore Struttura della libreria VLC:

Library "libvlc:5.6.1"

Public Struct video_track_t
  i_height As Integer
  i_width As Integer
  i_sar_num As Integer
  i_sar_den As Integer
  i_frame_rate_num As Integer
  i_frame_rate_den As Integer
  i_orientation As Integer
  i_projection As Integer
  f_yaw As Single
  f_pitch As Single
  f_roll As Single
  f_field_of_view As Single
  i_multiview As Byte
End Struct

Public Struct audio_track_t
  i_channels As Integer
  i_rate As Integer
End Struct

Public Struct media_track_t
  i_codec As Integer
  i_original_fourcc As Integer
  i_id As Integer
  i_type As Integer
  i_profile As Integer
  i_level As Integer
  union As Pointer
  i_bitrate As Integer
  psz_language As Pointer
  psz_description As Pointer
End Struct

Private Enum libvlc_media_parse_local = 0,
             libvlc_media_parse_network,
             libvlc_media_fetch_local,
             libvlc_media_fetch_network = 4,
             libvlc_media_do_interact = 8

 'libvlc_instance_t * libvlc_new (int argc, const char *const *argv)
' Create And initialize a libvlc instance.
Private Extern libvlc_new(argc As Integer, argv As String[]) As Pointer

 'libvlc_media_t * libvlc_media_new_path (libvlc_instance_t *p_instance, const char *path)
' Create a media for a certain file path.
Private Extern libvlc_media_new_path(p_instance As Pointer, path As String) As Pointer

 'int libvlc_media_parse_with_options (libvlc_media_t *p_md, libvlc_media_parse_flag_t parse_flag, int timeout)
' Parse the media asynchronously with options.
Private Extern libvlc_media_parse_with_options(p_md As Pointer, parse_flag As Integer, timeout As Integer) As Integer

 'libvlc_time_t libvlc_media_get_duration(libvlc_media_t *p_md)
' Get duration (in ms) of media descriptor object item.
Private Extern libvlc_media_get_duration(p_md As Pointer) As Long

 'char* libvlc_media_get_meta (libvlc_media_t * p_md, libvlc_meta_t e_meta)
' Read the meta of the media.
Private Extern libvlc_media_get_meta(p_md As Pointer, e_meta As Integer) As String

 'unsigned libvlc_media_tracks_get (libvlc_media_t * p_md, libvlc_media_track_t *** tracks)
' Get media descriptor's elementary streams description.
Private Extern libvlc_media_tracks_get(p_md As Pointer, tracks As Pointer) As Integer

 'const char * libvlc_media_get_codec_description (libvlc_track_type_t i_type, uint32_t i_codec)
' Get codec description from media elementary stream.
Private Extern libvlc_media_get_codec_description(i_type As Integer, i_codec As Integer) As String

 'void libvlc_media_release (libvlc_media_t *p_md)
' Decrement the reference count of a media descriptor object.
Private Extern libvlc_media_release(p_md As Pointer)

 'libvlc_release (libvlc_instance_t * p_instance)
' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
Private Extern libvlc_release(p_instance As Pointer)


Public Sub Main()

 Dim inst, md, p As Pointer
 Dim tm As Long
 Dim b As Byte
 Dim s As String
 Dim tp, i, c As Integer
 Dim mt As Media_track_t
 Dim vt As Video_track_t
 Dim at As Audio_track_t
 Dim meta As String[] = ["Title:", "Artist:", "Genre", "Copyright:", "Album", "TrackNumber:",
                         "Description:", "Rating:", "Date:", "Setting:", "URL:",
                         "Language:", "NowPlaying:", "Publisher:", "EncodedBy:", "ArtworkURL:",
                         "TrackID:", "TrackTotal:", "Director:", "Season:", "Episode:",
                         "ShowName:", "Actors:", "AlbumArtist:", "DiscNumber:", "DiscTotal:"]
 Dim orient As String[] = ["Normal", "Flipped horizontally", "Flipped vertically", "Rotated 180 degrees",
                           "Transposed", "Rotated 90 degrees clockwise", "Rotated 90 degrees anti-clockwise", "Anti-transposed"]

 s = "/percorso/del/file/video"
 Print "Nome file:  "; s
 
 inst = libvlc_new(0, Null)
 If inst == 0 Then Error.Raise("Errore !")
 
 md = libvlc_media_new_path(inst, s)
 If md == 0 Then Error.Raise("Errore !")
 
 libvlc_media_parse_with_options(md, libvlc_media_parse_local, 0)
 
 tm = libvlc_media_get_duration(md)
 Print "Durata:     ";Time(0, 0, 0, tm)
 
 Print "\n- Metadati -"
 For b = 0 To meta.Max
   s = libvlc_media_get_meta(md, b)
   If Not IsNull(s) Then Print meta[b]; String(17 - Len(meta[b]), Chr(32)); s
 Next
 
 Print "\n- Codificatore -"

 Repeat 
   Wait 0.01
   i = libvlc_media_tracks_get(md, VarPtr(p))
 Until i > 0

 For b = 0 To i - 1
   mt = Pointer@(p + (SizeOf(gb.Pointer) * b))
   tp = mt.i_type
   
   c = mt.i_original_fourcc
   
   Print "Tipo media:      ";
   Select Case tp
     Case -1
       Print "Sconosciuto"
     Case 0
       Print "Audio"
       Print "Codifica:        "; libvlc_media_get_codec_description(tp, mt.i_codec)
       Print "Formato audio:   "; Left(String@(VarPtr(c)), 4)
       at = mt.union
       With at
         Print "Canali:          "; at.i_channels
         Print "Frequenza camp.: "; at.i_rate
       End With
     Case 1
       Print "Video"
       Print "Codifica:        "; libvlc_media_get_codec_description(tp, mt.i_codec)
       Print "CompressorID:    "; Left(String@(VarPtr(c)), 4)
       vt = mt.union
       With vt
         Print "Dimensione:      "; .i_width; "x"; .i_height
         Print "Fotogrammi/sec.: "; .i_frame_rate_num
         Print "Orientazione:    "; orient[.i_orientation]
       End With
     Case 2
       Print "Testo"
   End Select
   Print
 Next
 
 
' Libera la memoria:
 libvlc_media_release(md)
 libvlc_release(inst)
 
End


Riferimenti