xbmc.Player().play() syncrhonized video playback. Inconsistent latency?

  • Good evening,

    I have a setup, where two screens (4k and HD) have to play videos synchronized.

    I have two minix neo u9-h with libreelec 8.2.5 from wrxstasy.

    Both players are conneced to a router via ethernet.

    On both boxes I have a small python script (/storage/.kodi/userdata/autoexec.py) that connects to a tcp port,

    which is created on an esp8266, connected via wifi to the router.

    Both players have the exactly same settings.

    The esp8266 sends a trigger message to the tcp port which in the python script starts a video via:

    xbmc.Player().play(path_to_video)

    Now my problem is, that both videos start with a different latency, which is around 1500ms. for one player and 200ms for the other.

    I already tried to synchronize the videos by addings a fixed delay,

    but this is hard to measure and not very beautiful.

    I'm not even sure if it's constant.

    Changing the video content seems to change the delay.

    Moving the wifi device around (increasing the distance to the router) seems to change the delay slightly.

    However I doubt that writing a simple message to a tcp port can result in such long latency.

    What is causing the different latency?

    1) xbmc.Plyer().play() --> it seems the most direct way to controll kodi. Could it cause latency i.e. because of internal polling?

    2) different video content (HD, 4K)? Can switchwing from the GUI's HD resolution to the 4k video resolution cause latency?

    3) low wifi on the esp8266? --> I measured the time between and the esp8266 needs 1.5 ms (!) to send the messages to the tcp ports. So I guess it should be OK.

    What else could be the reason? Any experiences with similiar setups?

    Many Greetings, Himi

  • As you didn't share what your python script does it's difficult to comment.

    I think your issue is that you are trying to do it in real time, rather that using time to you advantage. (If you can have a *small* delay)

    So something like.

    Synchronize time on both machines

    start video at time + 2 seconds

  • Hello again, thanks for replying and sorry for not providing enough information.

    Here is what I do with my autoexec.py

    I now tested it again with a different setup and router and it seems to work without a noticeable delay.

    I use two earphones connected to the player and they both start playing immediately.

    If I connect them through wifi they get a small delay, but that's explainable.

    Also if I use different video files (different content, different size, but same audio track) they get a larger delay, depending on the size I think,

    but it's still okay and barely audible.

    Before it was up to 2000 ms for some players.

    Maybe a router problem?

    Maybe the display or libreelec changing resolution/refreshrate?

    I also went through all the settings again and added the <video> tag to avoid detecting the fps automatically which I though could cause some delay before starting playback.

    I also set the display latency to 0.


    All settings are copied to advancedsettings.xml for a headless player setup.

    Sadly not every setting is explained (Proper settings documentation would be nice for the new libreelec).