What algorithm/approach to use to synchronize multiple video players

蹲街弑〆低调 提交于 2019-12-04 04:06:39

Sorry I am not directly answering your questions, but instead this is how would I do it:

I would use MCI (I am Windows friendly but i think all other players had to be something similar)

  1. time must be synchronized on all clients which can be really tricky
    • on fast LAN with small latency you can send time by server to all clients and that is it
    • on unknown latency (like Internet) you cannot instead you can start sending time from server to each client many times. On client side compute the average time offset between server and client time and after that just add it to client time and that is it.
    • if clients connection latency is too unstable you are out of luck
  2. open stream but not start to play
  3. wait some time to be sure video is ready to play ...
  4. start play on each client on precise server time

    do not expect exact synchronism (without precise time synchronization). Also the play command can be executed in different speeds on different machines but not as much difference as the open stream command (therefore the delay on bullet #3)

Problem with this approach is that it assumes that playback is synchronized with time

This is often not true especially on network streaming. Most players drop frames to compensate but sometimes if the stream is not decoded for a longer time it can cause cumulative offset. In that case you can implement playback progress (your tics)

Tics can be:

  • played frames
  • playback progress time
  • playback progress percentage

Tics synchronization:

In all cases you must implement time synchronization from bullet #1 or any other. There are three basic approaches:

  1. the best is frame synchronization

    but need to implement own player or player capable of frame navigation which is very hard to implement correctly.

  2. playback progress time

    is the next best thing. If you notice bigger offset than some treshold then either pause or rewind back/forward.

    Problem with rewind is that it is unpredictable how much time it will take so you can measure the time it takes and iterate rewind in few steps with applying this time to match the synchronized playback time (its a bit tricky).

  3. playback progress percentage

    Almost the same as playback progress time but the resolution is far worse. It is applicable only on very big time offsets. Not suitable for the synchronization itself but for problem detection only. If problem detected then stop all clients and start on new exact server time and or rewind + delay before start playback again. This sucks I know but not all players support playback frame/time announcements.

Hope it helps a little.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!