Fix YouTube subtitles lagging behind
With this, subtitles on YouTube should keep up with up to 8x speed. They should no longer lag behind nor alternate between suddenly slowing down and speeding up.
This works by making YouTube's timers fire earlier / more frequently. This makes YouTube pick up the earlier-than-usual video positions caused by Video Speed Controller, and both refresh earlier and schedule the next timer to refresh earlier. A constant 4x boost is used for simplicity (the new script runs elsewhere in the unisolated MAIN world, so getting settings is hard), and 4x should be enough for most people.
YouTube's own speed should not be set to 0.25, or we get the same behavior as before this PR. The constant 4x should be low enough not to cause lag even with timers firing at 8x the normal 1x speed when YouTube's speed is set to 2x.
A funny side effect of this is that ads are cut a few seconds short.
Fixes #537
No idea that this will ever be implemented by someone 6 years later.
Thanks for the opensource contribution danielzgtg, and hope that it'll pass the test and be merged soon!
@danielzgtg could you rebase this against updated code structure?
@igrigorik Rebased
I ran into #1227 along the way, but it randomly went away and I retested this to work. Since it happens even without my commit, it should be unrelated.
I'm having a hard time testing this / verifying it has impact. Any tips?
Here are some screen recordings of Cosmos Laundromat, Blender Foundation, CC BY-SA 3.0. VSC is set to 4x and YouTube is set to 1x.
These should be watched with sound or simultaneously.
Before
Some subtitles overstay and others are skipped.
After
All subtitles stay in sync.
Interesting, I think I see it now, but only at 4x+ -- does that sound about right? Do you scan videos at that (or higher) speed?
On that video, the effect is noticeable even at VSC 3x applied to YouTube 2x: After the long sentence "I'm a sheep minding its own business", the words "And I suggest" are spoken before they appear on screen.
Yes, I watch many videos at 4x, but most videos at 3x. The purpose of me installing this extension is to exceed 2x on YouTube. This is true especially for familiar and slow speakers like Sal Khan. When cramming Khan Academy before exams, I watched new-style videos (example) at 6x and old-style videos (example) at 8x. Subtitles staying in sync lets me not need to rewind if I miss a word.
@igrigorik hello Ilya, tested it work as expected but currently it change all setTimeout and it might cause another problems.
I figured that only subtitles are not rounded so (delay%10 != 0) control will be enought for not breaking anything.
@danielzgtg can you add that before https://github.com/igrigorik/videospeed/pull/1185/commits/959f833368ffbec9a659d14d22cfb79e6ae7191c#diff-a2950df80365a2998d5503d97c7dd0dd731c78579c3c3716758e1a88a9eb29f6R6