yichengchen / ATV-Bilibili-demo

BiliBili Client Demo for Apple TV (tvOS)
GNU General Public License v2.0
2.32k stars 436 forks source link

fix danmu mask out of sync with video #46

Closed qsz13 closed 1 year ago

qsz13 commented 1 year ago

This PR is to fix https://github.com/yichengchen/ATV-Bilibili-demo/issues/45

There are two issues:

  1. The mask FPS returned from API is not accurate. The number seems to be rounded down. When we assume the FPS is 29 while it's actually 30, the delay for the mask is exaggerated when the video plays on.
  2. mask frames returned from the API don't match perfectly with the video frames, so if we just calculate the frame index, there's still a noticeable 1-2 seconds mismatch.

The fix is to store the mask frames ordered by timestamp, and when we need to show the mask, we use binary search to find the latest mask frame. Also, a minor improvement is to start using the mask before the processing is finished, which decreases the loading time when we play the video from the beginning. Simulator Screen Shot - Apple TV - 2023-01-16 at 16 10 46

yichengchen commented 1 year ago

awesome