videospeed icon indicating copy to clipboard operation
videospeed copied to clipboard

Fix YouTube subtitles lagging behind

Open danielzgtg opened this issue 10 months ago • 8 comments

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

danielzgtg avatar May 02 '25 09:05 danielzgtg

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!

29988122 avatar May 26 '25 14:05 29988122

@danielzgtg could you rebase this against updated code structure?

igrigorik avatar Jul 19 '25 04:07 igrigorik

@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.

danielzgtg avatar Jul 21 '25 22:07 danielzgtg

I'm having a hard time testing this / verifying it has impact. Any tips?

igrigorik avatar Jul 23 '25 23:07 igrigorik

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.

VSC 0.9.1

After

All subtitles stay in sync.

Subt

danielzgtg avatar Jul 24 '25 20:07 danielzgtg

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?

igrigorik avatar Jul 27 '25 13:07 igrigorik

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.

danielzgtg avatar Jul 27 '25 16:07 danielzgtg

@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

canarslan12 avatar Aug 28 '25 14:08 canarslan12