Set any YouTube playback speed (script)

Post your working scripts, libraries and tools for AHK v1.1 and older
a0l0e0x000
Posts: 14
Joined: 26 Dec 2020, 08:27

Set any YouTube playback speed (script)

Post by a0l0e0x000 » 14 Jan 2021, 16:54

Youtube only allows you to set speeds from 0.25x to 2x and in 0.25x steps.
However this script will let you set YouTube playback speed to anything from 0.1x to 16x easily (remap "^F12" to any hotkey you desire)

1. Script will open your browser console (Works at least in Chrome) and type in a command
2. You then need to type your desired speed (eg. "3.2" if you want to set the playback to 3.2x) and press ENTER.
3. The script will automaticlly close the console after you press ENTER.
(4.) The script also has an added function to write a "." when you press your NumPadDot button, because your language settings in windows may replace the "." with a "," and the comma doesn't work in a console as a decimal separator. - You can delete the "hotkey..." parts of the code to remove this added function if you want.

Code: Select all

^F12::
hotkey, numpaddot, ReplaceComma, on
send, ^+j
sleep, 1000
sendinput, document.getElementsByTagName("video")[0].playbackRate = 
keywait, enter, D
sleep, 100
send, ^+j
hotkey, numpaddot, ReplaceComma, off
return

ReplaceComma(){
send, `.
}

User avatar
submeg
Posts: 335
Joined: 14 Apr 2017, 20:39
Contact:

Re: Set any YouTube playback speed (script)

Post by submeg » 25 Jan 2021, 05:58

Have you noticed that the audio and video become desynced when you change the speed up and then to a slower speed?
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

a0l0e0x000
Posts: 14
Joined: 26 Dec 2020, 08:27

Re: Set any YouTube playback speed (script)

Post by a0l0e0x000 » 26 Jan 2021, 16:45

submeg wrote:
25 Jan 2021, 05:58
Have you noticed that the audio and video become desynced when you change the speed up and then to a slower speed?
Interesting, no, I have never had that happen and I use the script a lot.

BTW here is an updated version which fixes a problem with autocomplete ruining the code, however it has it's own new problem of timing out after 5 seconds because I couldn't get KeyWait to work (meaning you need to wait till it times out to use it again; and if it times out before you click enter you have to manually close the console, but the code is generally more robust than the 1st version)

Code: Select all

^F13::
hotkey, numpaddot, ReplaceComma, on
hotkey, numpadenter, ReplaceNumpadEnter, on
hotkey, enter, ReplaceEnter, on
send, ^+j
sleep, 1000
sendinput, document.getElementsByTagName("video")[0].playbackRate = 
sleep, 5000
hotkey, numpaddot, ReplaceComma, off
hotkey, numpadenter, ReplaceNumpadEnter, off
hotkey, enter, ReplaceEnter, off
return

ReplaceComma(){
send, `.
}

ReplaceEnter(){
Sleep, 500
send, {left}
sleep, 50
send, {enter}
sleep, 50
send, ^+j
}

ReplaceNumpadEnter(){
sleep, 500
send, {left}
sleep, 50
send, {enter}
sleep, 50
send, ^+j
}

a0l0e0x000
Posts: 14
Joined: 26 Dec 2020, 08:27

Re: Set any YouTube playback speed (script)

Post by a0l0e0x000 » 26 Jan 2021, 17:03

submeg wrote:
25 Jan 2021, 05:58
Have you noticed that the audio and video become desynced when you change the speed up and then to a slower speed?
Oh and whatever causes the desyncing is a browser or YouTube issue, as all the script does is to use the browser's built it Dev console to send a command. And all that command does is alter the playback speed, but that is all on the browser side.
I am using an up-to-date Google Chrome in Windows 10 btw and have never noticed the problem you mentioned.

User avatar
submeg
Posts: 335
Joined: 14 Apr 2017, 20:39
Contact:

Re: Set any YouTube playback speed (script)

Post by submeg » 28 Jan 2021, 04:01

Interesting, would make sense that it's a youtube issue. I'll give the other code a try, thanks!
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

a0l0e0x000
Posts: 14
Joined: 26 Dec 2020, 08:27

Re: Set any YouTube playback speed (script)

Post by a0l0e0x000 » 14 Feb 2021, 09:58

submeg wrote:
28 Jan 2021, 04:01
Interesting, would make sense that it's a youtube issue. I'll give the other code a try, thanks!
On second thought it may also be your GPU. YouTube is not optimized for this so if you set the speed at 10x your GPU is going to be drawing 10-times the frames, so if you don't have a capable one it will start to lag. I have a Quadro p1000 and it starts dropping some frames if I try to play 4K 30fps at more than 5x speed (that's still 150 fps tho so the video is fine), but the card is pinned at 100% usage, so if you have a less capable computer that might cause weird issues.
Possibly IDK ;D

Post Reply

Return to “Scripts and Functions (v1)”