https://foro.gambas-es.org/viewtopic.php?f=17&t=7851&p=47367#p47367
-----------------------------------
tincho
Viernes, 03 Enero 2020, 23:54

Re: Alguna Libreria Para Leer Metadatos De Fotos.
-----------------------------------
Bueno Vuott, adapte esta clase que nos compartiste para extraer los metadatos.
Logro extraer casi todos los metadatos que necesito para mi programa (que sirve para ordenar fotos y vídeos tomados con cámaras de fotos digitales), solo me falta extraer la fecha de creación del vídeo.
Algunos fabricantes llaman "Media Create Date" otros "Date/Time Original" etc. estas etiquetas se encuentran en los metadatos EXIF.
He buscado un rato largo en
https://www.olivieraubert.net/vlc/python-ctypes/doc/
Pero no encontré ninguna referencia a dichas etiquetas EXIF
Al parecer esta librería esta destinada a películas y no a vídeos familiares creados con una cámara digital (que es el tipo de archivos que intento ordenar)

Gracias Vuott por todos los aportes de código, son muy interesantes porque de a poco me voy metiendo en el uso de librerías C.

Pongo aquí el código tal como quedo.
[code linenumbers=false syntax=gambas]
' Gambas class file

Export

Library "libvlc:5.6.0"

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
  pose1 As Single
  pose2 As Single
  pose3 As Single
  pose4 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 Function MediaData(f As String) As Collection

  Dim inst, md, p1, p2 As Pointer

  Dim tm As Long   ''Duración del flujo
  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"]

  Dim cn As New Collection
  Dim codec As String

  cn.Clear

  If Exist(f) Then

    inst = libvlc_new(0, Null)
    md = libvlc_media_new_path(inst, f)
    libvlc_media_parse_with_options(md, libvlc_media_parse_local, 0)

    Sleep 0.1

    tm = libvlc_media_get_duration(md)

    For b = 0 To meta.Max
      s = libvlc_media_get_meta(md, b)
      cn.Add(s, meta[b])
    Next

    p1 = Alloc(24)
    p2 = VarPtr(p1)

    i = libvlc_media_tracks_get(md, VarPtr(p2))

    For b = 0 To i - 1

      tp = Int@(Pointer@(p2 + (SizeOf(gb.Pointer) * b)) + 12)

      Select Case tp

        Case 0
          codec = libvlc_media_get_codec_description(tp, Int@(Pointer@(p2 + (SizeOf(gb.Pointer) * b))))
          cn.Add(codec, "AudioCodec")

          at = Pointer@(Pointer@(p2 + (SizeOf(gb.Pointer))) + 24)
          With at
            cn.Add(.i_channels, "Channels")
            cn.Add(.i_rate, "Rate")
          End With

        Case 1
          codec = libvlc_media_get_codec_description(tp, Int@(Pointer@(p2 + (SizeOf(gb.Pointer) * b))))
          cn.Add(codec, "VideoCodec")

          vt = Pointer@(Pointer@(p2) + 24)

          With vt
            cn.Add(.i_width & "x" & .i_height, "ImageSize")
            cn.Add(.i_frame_rate_num, "Frames/Sec")
            cn.Add(orient[.i_orientation], "Orientation")
          End With
        Case 2
          '
      End Select
    Next

    ' Libera la memoria:
    Free(p1)
    libvlc_media_release(md)
    libvlc_release(inst)

  Endif

  Return cn

End
[/code]

[u]Con la herramienta [b]exiftool[/b] recupero estos datos, entre otros[/u]
ImageWidth	1920
ImageHeight	1080
CompressorID	avc1
VideoFrameRate	29.932
MediaCreateDate	2019:01:01 01:01:01
MediaTimeScale	48000
MediaDuration	13.03 s
AudioFormat	mp4a
AudioChannels	2
AudioBitsPerSample	16
AudioSampleRate	48000
ImageSize	1920x1080
Rotation	0

[u]Mientras que con [b]libvlc[/b] recupero estos[/u]
Title:	test.mp4
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:	
VideoCodec	H264 - MPEG-4 AVC (part 10)
ImageSize	1920x1080
Frames/Sec	17630
Orientation	Normal
AudioCodec	MPEG AAC Audio
Channels	2
Rate	48000

Saludos.


