Syncing VLC instances / players in Python and in general

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

Syncing VLC instances / players in Python and in general

Postby sampsa » 16 Dec 2014 15:15

Dear VLC'ers,

I am using the VLC python plugin and I'm having hard time in trying to display several recorded video streams in sync.

In python, I am creating several vlc instances, each one of them having their own media player, i.e:

******
vlci=vlc.Instance(st) # here st has the options given to the vlc instance (++)
player=vlci.media_player_new()
media=vlci.media_new(unicode(filename))
player.set_media(media)
******

The input media I am playing is an RTSP stream and I am performing the recording, by giving the following output option (++) to the "vlc" instance:

******
--sout=#duplicate{dst=std{access=file,mux=ts,dst='FILENAME'}} --sout-file-overwrite
******

.. where FILENAME is the name of the recorded stream (here either "stream1.avi", "stream2.avi" or "stream3.avi").

The three separate "vlci" instances each record a stream. The first two instances record the same camera, while the third one records a camera that has a higher bitrate. Finally I get three files:

******
> du -h *
2,3M stream1.avi
2,3M stream2.avi
60M stream3.avi
******

Next, I do a playback for these three streams simultaneously. During each second, I poll the position from the "player" instances of each vlc instance, i.e.:

player.get_position()

I get the following positions:

stream1, stream2, stream3

0.43595999479293823, 0.43168333172798157, 0.40312349796295166
0.4588924050331116, 0.4605380892753601, 0.4215429127216339
0.4695454239845276, 0.46996667981147766, 0.43995019793510437

Positions of streams 1 & 2 are practically the same (deviation less than one percent), as expected, while position of stream 3 lags behind.

As player.get_position() gives the fraction of the total time, then, for a video having the length of 1 minute, there will be a lag of ~ 1 second, while video of 30 minutes produces a lag of ~ 36 seconds ..!

How can I get the streams in sync?

When playing, I passed the vlc instance the following argument (++):

******
"--clock-synchro 1 --clock-jitter 5000"
******

.. but that did not work at all. Outside python, I tried to play around with:

******
cvlc stream1.avi --network-synchronisation --netsync-master -vvv
cvlc stream1.avi --network-synchronisation --netsync-master-ip 192.168.1.33 -vvv
******

.. and launching them simultaneously from different terminals (I start the "slave" first), but that did not work either. Both tell me:

[0x852168] netsync interface error: InputEvent DEAD

What is the best way to get the streams in sync in python?


Kind Regards,

Sampsa

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: Syncing VLC instances / players in Python and in general

Postby Jean-Baptiste Kempf » 02 Jan 2015 17:02

syncplay.pl?
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.

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

Re: Syncing VLC instances / players in Python and in general

Postby sampsa » 19 Jan 2015 10:00

Dear Jean-Baptiste,

Thank you for you reply.

I found a solution to my problem with the aid of Google and the earlier posts in this forum.

First of all, I had to record all videos with a custom program that dumps raw H264 packets into files and which does not drop corrupt frames (as vlc recording does).

Second, the raw video streams had to be muxed into .mkv (matroska) files (I do this with avconv). Reading this forum, it is clear that with, say, MP2 muxing, there is no way to seek video files in an exact manner. Matroska creates indexing in the metadata that helps seeking the videos. Now, when seeking several video files simultaneously, they always go into the same time instant.

Thanks for pointing out syncplay. I will certainly check it out for other uses.

Regards,

Sampsa


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 15 guests