I'm just trying to get to grips with the VLC Python module and while the documentation is really helpful and the samples over at https://wiki.videolan.org/Python_bindings/ have been great for the basic functions, I'm a little stuck with figuring out how to use the tracks_get() function within the Media class.
import vlc
def getCodec():
file = "/video/video.mp4"
VLCInstance = vlc.Instance()
Media = VLCInstance.media_new(file)
Media.parse()
tracks = Media.tracks_get()
for track in tracks:
mediatype = track.type
mediacodec = track.codec
codec_desc = vlc.libvlc_media_get_codec_description(mediatype,mediacodec)
print(str(codec_desc))
getCodec()
I have written the code above and this all works fine, but in the documentation here it mentions that the result must be freed with tracks_release. I can't see any function with that name though. I have found a function called libvlc_media_tracks_release, but I cannot seem to supply that with the parameters that it wants. I have tried adding vlc.libvlc_media_tracks_release(tracks, 2)
at the bottom of my code, but that comes up with the error "ctypes.ArgumentError: argument 1: <class 'TypeError'>: expected LP_LP_MediaTrack instance instead of generator"
.
So my questions are, how do I call the tracks_release() function and thereby use the tracks_get() function correctly and why do I need free the result anyway? Will Python's garbage collection not deal with the object once it goes out of scope?