Differenze tra le versioni di "Ottenere informazioni generali da un flusso web audio-video con le risorse del API di VLC"

Da Gambas-it.org - Wikipedia.
 
(Una versione intermedia di uno stesso utente non è mostrata)
Riga 53: Riga 53:
 
   
 
   
 
  <FONT Color=gray>' ''void libvlc_media_player_release (libvlc_media_player_t * p_mi)''
 
  <FONT Color=gray>' ''void libvlc_media_player_release (libvlc_media_player_t * p_mi)''
  ' ''Release a media_player after use Decrement the reference count of a media player object.le risorse del API di
+
  ' ''Release a media_player after use Decrement the reference count of a media player object.''</font>
 
  Private Extern libvlc_media_player_release(p_mi As Pointer)
 
  Private Extern libvlc_media_player_release(p_mi As Pointer)
 
   
 
   
Riga 59: Riga 59:
 
  ' ''Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.''</font>
 
  ' ''Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.''</font>
 
  Private Extern libvlc_release(p_instance As Pointer)
 
  Private Extern libvlc_release(p_instance As Pointer)
 +
 +
 +
Public Sub Main()
 +
 +
  Dim inst, m, mp, p As Pointer
 +
  Dim b As Byte
 +
  Dim s As String
 +
  Dim tp, i As Integer
 +
  Dim vt As Video_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 = "https&#058;//d15umi5iaezxgx.cloudfront.net/LA7/CLN/HLS-B/Live.m3u8"
 +
  Print "Nome file:  "; s
 +
 +
  inst = libvlc_new(0, Null)
 +
  If inst == 0 Then Error.Raise("Errore !")
 +
 +
  m = libvlc_media_new_location(inst, s)
 +
  If m == 0 Then Error.Raise("Errore !")
 +
 +
  mp = libvlc_media_player_new_from_media(m)
 +
 +
  libvlc_media_release(m)
 +
 +
  libvlc_media_player_play(mp)
 +
 +
  Print "\n- Metadati -"
 +
  For b = 0 To meta.Max
 +
    s = libvlc_media_get_meta(m, 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(m, 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"
 +
      Case 1
 +
        Print "Video"
 +
        vt = Pointer@(Pointer@(p) + (SizeOf(gb.Pointer) * 3))
 +
        With vt
 +
          Print "Dimensione:      "; .i_width; "x"; .i_height
 +
          Print "Orientazione:    "; orient[.i_orientation]
 +
        End With
 +
      Case 2
 +
        Print "Testo"
 +
    End Select
 +
    Print
 +
  Next
 +
 +
<FONT Color=gray>' ''Libera la memoria:''</font>
 +
  libvlc_media_player_release(mp)
 +
  libvlc_release(inst)
 +
 +
End

Versione attuale delle 05:45, 11 ago 2024

Con le risorse del API di VLC è possibile ottenere alcune informazioni generali di un video trasmesso da una web-TV.

Mostriamo un esempio pratico:

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

' 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_location (libvlc_instance_t *p_instance, const char *psz_mrl)
' Create a media with a certain given media resource location.
Private Extern libvlc_media_new_location(p_instance As Pointer, psz_mrl As String) As Pointer

' libvlc_media_player_t * libvlc_media_player_new_from_media (libvlc_media_t *p_md)
' Create a Media Player object from a Media.
Private Extern libvlc_media_player_new_from_media(p_md As Pointer) As Pointer

' 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

' int libvlc_media_player_play (libvlc_media_player_t * p_mi)
' Play the video file.
Private Extern libvlc_media_player_play(p_mi As Pointer) As Integer

' 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)

' void libvlc_media_player_release (libvlc_media_player_t * p_mi)
' Release a media_player after use Decrement the reference count of a media player object.
Private Extern libvlc_media_player_release(p_mi 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, m, mp, p As Pointer
 Dim b As Byte
 Dim s As String
 Dim tp, i As Integer
 Dim vt As Video_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 = "https://d15umi5iaezxgx.cloudfront.net/LA7/CLN/HLS-B/Live.m3u8"
 Print "Nome file:  "; s

 inst = libvlc_new(0, Null)
 If inst == 0 Then Error.Raise("Errore !")

 m = libvlc_media_new_location(inst, s)
 If m == 0 Then Error.Raise("Errore !")

 mp = libvlc_media_player_new_from_media(m)

 libvlc_media_release(m)

 libvlc_media_player_play(mp)

 Print "\n- Metadati -"
 For b = 0 To meta.Max
   s = libvlc_media_get_meta(m, 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(m, 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"
     Case 1
       Print "Video"
       vt = Pointer@(Pointer@(p) + (SizeOf(gb.Pointer) * 3))
       With vt
         Print "Dimensione:      "; .i_width; "x"; .i_height
         Print "Orientazione:    "; orient[.i_orientation]
       End With
     Case 2
       Print "Testo"
   End Select
   Print
 Next

' Libera la memoria:
 libvlc_media_player_release(mp)
 libvlc_release(inst)

End