How to perfectly sync two or more html5 video tags?

后端 未结 3 1066
轮回少年
轮回少年 2021-02-19 11:04

Is there any way to have two or more (preferably three) html5 < video > tags playing simultaneously and to be in perfect sync.

If I have let\'s say three til

3条回答
  •  梦谈多话
    2021-02-19 11:53

    Disclaimer: I'm not a video guy, but here are some thoughts anyway.

    If they need to be absolutely perfect...you are fighting several problems at once:

    1. A device might not be powerful enough to acquire, synchronize and render 3 streams at once.

    2. Even if #1 is solved, a device is never totally dedicated to your task. For example, it might pause for garbage collection between processing stream#1 and stream#2--resulting in dropped/unsynchronized frames.

    So to give yourself the best chance at perfection, you should first merge your 3 videos into 1 vertical video in the studio (or using studio software).

    Then you can use the extended clipping properties of canvas context.drawImage to break each single frame into 2-3 separate frames.

    Additionally, buffer a few frames you acquire on the stream (this goes without saying!).

    Use requestAnimationFrame (RAF) to control the drawing. RAF does a fairly good job of drawing frames when system resources are available and delaying frames when system resources are lacking.

    Your result won't be perfect, but they will be synchronized. You will always have to make the decision whether to drop or delay frames when system resources are unavailable, but at least the frames you do present will be synchronized.

提交回复
热议问题