Ottenere informazioni generali sull'audio e sul video con le funzioni esterne del API di Libquicktime

Da Gambas-it.org - Wikipedia.

La libreria Libquicktime legge e scrive file audio-video quicktime/avi/mp4.


Per utilizzare in Gambas le sue risorse, è necessario instalare e richiamare la libreria dinamica condivisa: "libquicktime.so.2.0.0"


Mostriamo di seguito un semplice esempio per ottenere informazioni generali sull'audio e sul video di un file video supportato dalla libreria.

Library "libquicktime:2.0.0"

' quicktime_t * quicktime_open (const char *filename, int rd, int wr)
' Open a file.
Private Extern quicktime_open(filename As String, rd As Integer, wr As Integer) As Pointer

' int quicktime_has_audio (quicktime_t * file)
' Check if a file has at least one audio track.
Private Extern quicktime_has_audio(quicktime As Pointer) As Integer

' int quicktime_audio_tracks (quicktime_t * file)
' Get the number of audio tracks.
Private Extern quicktime_audio_tracks(quicktime As Pointer) As Integer

' long quicktime_sample_rate (quicktime_t *file, int track)
' Get the samplerate of an audio track.
Private Extern quicktime_sample_rate(quicktime As Pointer, track As Integer) As Long

' int quicktime_audio_bits (quicktime_t *file, int track)
' Get the bits per sample of an audio track.
Private Extern quicktime_audio_bits(quicktime As Pointer, track As Integer) As Integer

' int quicktime_track_channels (quicktime_t *file, int track)
' Get the number of channels of an audio track.
Private Extern quicktime_track_channels(quicktime As Pointer, track As Integer) As Integer

' long quicktime_audio_length (quicktime_t *file, int track)
' Get the audio length.
Private Extern quicktime_audio_length(quicktime As Pointer, track As Integer) As Long

' int lqt_get_audio_language (quicktime_t *file, int track, char * language)
' Get the audio language.
Private Extern lqt_get_audio_language(quicktime As Pointer, track As Integer, language As Pointer) As Integer

' int quicktime_has_video (quicktime_t *file)
' Check if a file has at least one video track.
Private Extern quicktime_has_video(quicktime As Pointer) As Integer

' int quicktime_video_tracks (quicktime_t *file)
' Get the number of video tracks.
Private Extern quicktime_video_tracks(quicktime As Pointer) As Integer

' int quicktime_video_width (quicktime_t *file, int track)
' Get the width of a video track.
Private Extern quicktime_video_width(quicktime As Pointer, track As Integer) As Integer

' int quicktime_video_height (quicktime_t *file, int track)
' Get the height of a video track.
Private Extern quicktime_video_height(quicktime As Pointer, track As Integer) As Integer

' double quicktime_frame_rate (quicktime_t *file, int track)
' Get the framerate of a video track.
Private Extern quicktime_frame_rate(quicktime As Pointer, track As Integer) As Float

' long quicktime_video_length (quicktime_t *file, int track)
' Get the video length.
Private Extern quicktime_video_length(quicktime As Pointer, track As Integer) As Long

' char * quicktime_video_compressor (quicktime_t *file, int track)
' Get the four character code of a video track.
Private Extern quicktime_video_compressor(quicktime As Pointer, track As Integer) As String

' int quicktime_close (quicktime_t * file)
' Close a quicktime handle and free all associated memory.
Private Extern quicktime_close(quicktime As Pointer) As Integer


Public Sub Main()

 Dim qt, lingua As Pointer
 Dim i, tracce, bit, canali, wi, hi As Integer
 Dim frequenza, dimensione As Long
 Dim frame As Float
 Dim compr As String
 
  qt = quicktime_open("/percorso/del/file/video", 1, 0)
  If IsNull(qt) Then Error.Raise("Impossibile aprire il file !")
   
  Print "== ANALISI DELL'AUDIO =="

  If CBool(quicktime_has_audio(qt)) = False Then
    Print "Il file video non ha tracce audio !"
    Quit
  Endif
   
  tracce = quicktime_audio_tracks(qt)
  Print "Numero tracce audio: "; Null, tracce

  For i = 0 To tracce - 1

    frequenza = quicktime_sample_rate(qt, i)
    Print "Frequenza camp.to: "; Null, "Hz "; frequenza

    bit = quicktime_audio_bits(qt, i)
    If bit > 0 Then Print "Risoluzione audio: "; Null, bit; " bit"
   
    canali = quicktime_track_channels(qt, i)
    Print "Numero canali audio: "; Null, canali
   
    dimensione = quicktime_audio_length(qt, i)
    Print "Dimensione audio: "; Null, dimensione; " byte"
   
    lingua = Alloc(SizeOf(gb.String))
    lqt_get_audio_language(qt, i, lingua)
    Print "Lingua dell'audio: "; Null, String@(lingua)
   
  Next
   
   
  Print "\n== ANALISI DEL VIDEO =="
  
  If CBool(quicktime_has_video(qt)) = False Then Error.Raise("Il file non possiede video !")
  tracce = quicktime_video_tracks(qt)
  Print "Numero tracce video: "; Null, tracce
   
  For i = 0 To tracce - 1
    wi = quicktime_video_width(qt, i)
    Print "Larghezza video: "; Null, wi; " pixel"
    
    hi = quicktime_video_height(qt, i)
    Print "Altezza video: ", Null, hi; " pixel"
    
    frame = quicktime_frame_rate(qt, i)
    Print "Frequenza frame: "; Null, frame
    
    dimensione = quicktime_video_length(qt, i)
    Print "Dimensione video: "; Null, dimensione; " frame"
   
    compr = quicktime_video_compressor(qt, i)
    Print "Tipo compressione: "; Null, compr
  
  Next
   
' Va in chiusura:
  Free(lingua)
  quicktime_close(qt)

End



Riferimenti