I'm looking for playing a video with vlc player via python3.8. I'm able to play a movie (mp4) but I would like to add additional audio tracks. I read that the 'add slave' method is the (new) way but I'm not able to use it properly: I'm not able to add subtitles nor audio track.
To summerize: what I want to achieve with Python is roughly the following: https://wiki.videolan.org/VLC_HowTo/Play_an_external_audio_track_for_a_video
my current (non working) snippet:
import vlc
base_path = r"Z:/test/libvlc/"
video_file = base_path + "original.mp4"
audio_file = base_path + "2xlcDLHY7k0-instru+vocal_stereo.wav"
sub_file = base_path + "word.ass"
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new(video_file)
AdditionalTrack = player.add_slave(player, audio_file, True, i_type="audio")
Sub = player.add_slave(player,sub_file, True)
player.set_media(Media)
while True:
player.play()
I found doc for 'add_slave' func here: https://www.olivieraubert.net/vlc/python-ctypes/doc/ but I'm not able to use it properly
libvlc_media_slaves_add(p_md, i_type, i_priority, psz_uri) Add a slave to the current media. A slave is an external input source that may contains an additional subtitle track (like a.srt) or an additional audio track (like a.ac3). Parameters: p_md - media descriptor object. i_type - subtitle or audio. i_priority - from 0 (low priority) to 4 (high priority). psz_uri - Uri of the slave (should contain a valid scheme).
If anyone know how to add subtitles or additional audio track, I would be grateful to him if he can advise me how to,
thanks a lot !
use this code instead.
AdditionalTrack = player.add_slave(player, audio_file, True, i_type=vlc.MediaSlaveType(1))
i-type parameter is not a string type.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.