Fix background blur mask not synchronized with video
The input track is played in a video element which, in turn, is drawn on
the canvas used to calculate the segmentation mask and on the output
canvas. However, the segmentation mask canvas is drawn first, then the
segmentation mask is calculated, and then once the calculation is
finished the mask it used to draw the video on the output canvas. The
mask calculation is done in a worker and thus asynchronously, so when
the resulting mask is received the input video might be in a different
frame than the one used to calculate the mask.
To solve this now a snapshot of the input video is taken when the
segmentation mask is calculated, and that snapshot, instead of the real
video, is then used to draw on the output canvas.
Due to this now the video with the blurred background might lag some
frames behind the actual video, although now the blur should "exactly"
match only the background.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Loading
Please register or sign in to comment