Playing several videos in sync (with python)

This forum is about all development around libVLC.
sampsa
Blank Cone
Blank Cone
Posts: 42
Joined: 16 Dec 2014 13:54

Playing several videos in sync (with python)

Postby sampsa » 18 Jun 2015 16:18

Dear libvlc people,

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
1) Would there be any difference/advantage for my case in creating only a single vlc instance and from that instance, all the necessary players? Is there some maximum number of players per one instance?

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)
Function "callback" could modify a variable, but then I'm stuck again in busy-waiting .. this time waiting for the change in the variable.

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!

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Playing several videos in sync (with python)

Postby Jean-Baptiste Kempf » 09 Jul 2015 22:13

1) less memory and no.
2) don't think so.
3) start the player as paused ?
4) no.

Are you playing the same file?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

west88
New Cone
New Cone
Posts: 2
Joined: 13 Jul 2015 16:25

Re: Playing several videos in sync (with python)

Postby west88 » 13 Jul 2015 16:39

Hi, did you succeed to play videos in sync?

And as Jean-Baptiste Kempf asked, do you play the same video file across every player in the grid or a different video on every single one (all video with the same time)?

sampsa
Blank Cone
Blank Cone
Posts: 42
Joined: 16 Dec 2014 13:54

Re: Playing several videos in sync (with python)

Postby sampsa » 24 Jul 2015 10:13

Different video in each vlc player .. Here the trick is to have homogeneous video files, with exactly the same number of frames, but that is a bit of a long story .. (I achieve that with some custom software).


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 24 guests