比特率:
# This allocates a double pointer and a MediaTrack object in RAM, then points to
# it, but no value is assigned to this double pointer or the MediaTrack object.
mediaTrack_pp = ctypes.POINTER(vlc.MediaTrack)()
# Assigns the MediaTrack in the double pointer to the values stored in `media`,
# returning the amount of media tracks as `n`
n = vlc.libvlc_media_tracks_get(media, ctypes.byref(mediaTrack_pp))
# Converts the double pointer to `POINTER` class that Python understands. We can
# then get the value the pointer is pointing at.
info = ctypes.cast(mediaTrack_pp, ctypes.POINTER(ctypes.POINTER(vlc.MediaTrack) * n))
# This gets the actual value of the double pointer i.e. value of MediaTrack
media_tracks = info.contents[0].contents
采样率(附加上面的代码):
# According to the API doc, MediaTrack class has an `u` field which has an
# `audio` field, containing the audio track.
audio = ctypes.cast(media_tracks.u.audio, ctypes.POINTER(vlc.AudioTrack))
# The AudioTrack class has a `rate` field, which is the sample rate.
sample = audio.contents.rate
我无法获得比特率的主要原因是因为我不了解如何获取数据类型LP_LP_MediaTrack
。这是MediaTrack实例的双指针。
当vlc.libvlc_media_tracks_get(media, ctypes.byref(mediaTrack_pp))
运行时,我想干脆在图书馆设置复制MediaTrack实例中media
的实际存储位置是mediaTrack_pp
点
然后,我们可以使用ctypes.cast()
方法获得Python中的实际对象。该算法应适用于所有使用LP_xxx
数据类型的Python代码,甚至适用于其他库。
解决了该问题后,剩下的就是处理API文档。
VLC MediaTrack类文档
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句