I have several videos in a window grid and I need to play the videos in sync. I am using python to achieve this.
Works like a charm. However, the vlc instances / players are asynchronous beasts and this creates some problems.
I have enumerated these problems below with more detailed explanations/questions. Any advices/thoughts would be greatly appreciated.
I am using the latest python interface ("should be compatible with any >= 2.0 VLC") from:
https://www.olivieraubert.net/vlc/python-ctypes/
Let's start by illustrating the situation with some python pseudocode:
Code: Select all
import vlc
screen1=vlc.Instance(st) # st has input parameters for vlc
player1=screen1.media_player_new()
screen2=vlc.Instance(st)
player2=screen2.media_player_new()
# etc .. for each video in the grid, I create a separate vlc instance from which I create a player
media1=screen1.media_new(filename)
player1.set_media(media1)
# etc .. for each video
So, I start playing a video with ..
player1.play()
And then I can poll its state with
player1.get_state()
which may results in
vlc.State.NothingSpecial, vlc.State.Opening, vlc.State.Playing, etc.
If I want to issue "player1.pause()", "player1.audio_set_mute(True)", etc. they have no effect, unless the player is in the state "vlc.State.Playing".
2) Is there any way to queue the commands to the player instance, so that they would take effect automagically once the player can execute them?
After issuing "player1.play()", I can periodically poll the player state with "player1.get_state()" and only after it returns "vlc.State.Playing", issue it more commands. However, I am not sure if such "busy waiting" is the optimal way to handle the situation (sure, I can wait between the polling, but its ugly).
Other possibility is to create callbacks, i.e.
Code: Select all
em=player1.event_manager()
em.event_attach(vlc.EventType.MediaPlayerPaused, callback)
em.event_attach(vlc.EventType.MediaPlayerPlaying, callback)
3) Is there any way to avoid the constant polling / busy-waiting for the players to be ready..? Something in the spirit of "select.select" function ?
I have had some problems with mysterious segfaults that occur when I am performing consecutive operations on the player objects too fast, say, polling them with "get_state" immediately after issuing a play (happends typically with large files).
4) .. any thoughts on those segfaults and why they might occur ?
Regards,
Sampsa
P. S. Happy Juhannus!