How to change the playing speed of videos in HTML5?
Asked Answered
L

15

250

How to change the video play speed in HTML5? I've checked video tag's attributes in w3school but couldn't approach that.

Livialivid answered 12/6, 2010 at 6:11 Comment(0)
H
383

According to this site, this is supported in the playbackRate and defaultPlaybackRate attributes, accessible via the DOM. Example:

/* play video twice as fast */
document.querySelector('video').defaultPlaybackRate = 2.0;
document.querySelector('video').play();

/* now play three times as fast just for the heck of it */
document.querySelector('video').playbackRate = 3.0;

The above works on Chrome 43+, Firefox 20+, IE 9+, Edge 12+.

Histidine answered 12/6, 2010 at 8:5 Comment(6)
Thanks for the helpful resource.Though Firefox doesn't support the attribute I've made a demo in Chrome which works fine.I guess my boss will like that.Thank you!Livialivid
playbackRate works in Firefox since version 20. It also works in Chrome.Reserpine
this works when run in the beginning but not if its run later in the process, such as at: window.onload=function(){document.getElementById("master_video").defaultPlaybackRate=0.1;document.getElementById("master_video").play();}Sterigma
its not working for Ionic android...I am using HTML% video player in ionic framwork for android but it not support playback rates.........Stratagem
Its not working for multiple video player in same page. Only the first one works fine and other plays in normal speed.Class
@Class .querySelector returns the first matching one. You can use .querySelectorAll, but you need to iterate through them instead of directly using the code in these answers.Ilyssa
B
114

Just type

document.querySelector('video').playbackRate = 1.25;

in JS console of your modern browser.

Bodily answered 30/9, 2016 at 15:56 Comment(3)
Some attributes of the video element will prevent this command from working. If this console command fails, check for attributes on the video element and parent elements in the inspector and remove those that block user interaction with the video. The try the command again.Transalpine
I copy/pasted this code in the F12 developer tools on the browser and it works.Volt
To effect all videos use document.querySelectorAll('video').forEach(function(el, i) { el.playbackRate = 1.25; }); Useful for eLearning where there are hidden video tags in the page so effect them all.Urial
M
23

(Tested in Chrome while playing videos on YouTube, but should work anywhere--especially useful for speeding up online training videos).

For anyone wanting to add these as "bookmarklets" (bookmarks containing JavaScript code instead of URLs) to your browser, use these browser bookmark names and URLs, and add each of the following bookmarks to the top of your browser. When copying the "URL" portion of each bookmark below, copy the entire multi-line code block, new-lines and all, into the "URL" field of your bookmark creation tool in your browser.

enter image description here

Name: 0.5x
URL:

javascript:

document.querySelector('video').playbackRate = 0.5;

Name: 1.0x
URL:

javascript:

document.querySelector('video').playbackRate = 1.0;

Name: 1.5x
URL:

javascript:

document.querySelector('video').playbackRate = 1.5;

Name: 2.0x
URL:

javascript:

document.querySelector('video').playbackRate = 2.0;

Here are all of my playback-speed bookmarklets:

I added all of the above playback speed bookmarklets, and more, into a folder named 1.00x on my bookmark bar, as shown here:

enter image description here

References:

  1. The main answer by Jeremy Visser
  2. Copied from my GitHub gist here: https://gist.github.com/ElectricRCAircraftGuy/0a788876da1386ca0daecbe78b4feb44#other-bookmarklets
    1. Get other bookmarklets here too, such as for aiding you on GitHub.
Millenarian answered 1/12, 2020 at 23:38 Comment(0)
B
7

solutions

  1. dom event onloadstart="this.playbackRate = 1.5;"
  <video
    onloadstart="this.playbackRate = 1.5;"
    controls
    src="https://cdn.xgqfrms.xyz/HTML5/video/controlslist.mp4">
  </video>
  1. js video.playbackRate = 1.5;
  <video
    id="custom-video"
    controls
    src="https://cdn.xgqfrms.xyz/HTML5/video/controlslist.mp4">
  </video>

const video = document.querySelector('#custom-video');

if(video) {
  video.playbackRate = 1.5;
}

demo

https://codepen.io/xgqfrms/pen/dydwzjp

Blackamoor answered 13/6, 2022 at 9:34 Comment(3)
This worked for me while the others didn't. I was trying to change playback speed on youtube video previews, such as on the homepage. It has one dynamically updated video tag for all the preview plays and for some reason setting it with javascript didnt work but updating the attributes with onloadstart does.Ansell
If the DOM content is created dynamically using js, it will overwrite any modifications you have made.Blackamoor
If you still have problems, please give a complete demo code URL of an online editor, such as codepen.io, codesandbox.ioBlackamoor
P
6

I prefer having a more fine tuned approach for video speed. I like being able to speed up and slow down the video on command. Thus I use this:

window.addEventListener("keypress", function(e) {
  if(e.key==="d") document.getElementsByTagName("video")[0].playbackRate += .1; else if(e.key==="s") document.getElementsByTagName("video")[0].playbackRate -= .1;
}, false);

Press d to speed up, s to slow down.

Polly answered 7/5, 2021 at 19:0 Comment(1)
Good idea to customize keys for faster speed changes! Thanks for sharing.Rutherfordium
L
3

You can use this code:

var vid = document.getElementById("video1");

function slowPlaySpeed() { 
    vid.playbackRate = 0.5;
} 

function normalPlaySpeed() { 
    vid.playbackRate = 1;
} 

function fastPlaySpeed() { 
    vid.playbackRate = 2;
}
Lithology answered 11/12, 2019 at 6:47 Comment(2)
Hi @Armel, may I know where to put this code if I am using Selenium with Python?Zigrang
Hi @balandongiv, I am sorry I don't know :(Grillparzer
D
2
javascript:document.getElementsByClassName("video-stream html5-main-video")[0].playbackRate = 0.1;

you can put any number here just don't go to far so you don't overun your computer.

Desegregate answered 25/3, 2019 at 15:17 Comment(0)
T
2

In chrome, create a new bookmark enter image description here

Enter an arbitarary name for example speed selector then Enter the following code in the URL

javascript:

var speed = prompt("Please enter speed", "1");
document.querySelector('video').playbackRate = speed,void(0);

then when you click on this bookmark, a popup window appears then you can enter the speed of video

enter image description here

Theca answered 10/4, 2021 at 9:8 Comment(0)
C
1

suppose that your video/audio id is myVideo, then you can simply use JavaScript for doing that you wanna do, By just typing the following simple JS code:-

var vid = document.getElementById("myVideo");
vid.playbackRate = 0.5;`
That will decrease the speed of your video/audio to it's half speed.

playbackspeed

Indicates the current playback speed of the audio/video.

Example values:

1.0 is normal speed

0.5 is half speed (slower)

2.0 is double speed (faster)

-1.0 is backwards, normal speed

-0.5 is backwards, half speed

source: w3schools.com

Cinchonize answered 21/3, 2021 at 7:41 Comment(1)
negative values are not working in Chrome. wish they were, that'd be a nice easy rewind or reverse play featureEpigeous
C
1

Just type the following command in the javascript console of your browser:

document.querySelector('video').playbackRate = 2.0;

enter image description here

You can get it by choosing the inspect option from the right-click menu as follows: enter image description here

Carlow answered 23/6, 2021 at 12:24 Comment(0)
S
1

Firefox has a speed control context menu when you right-click

Firefox speed control context menu.

Seato answered 26/4, 2022 at 16:42 Comment(0)
C
1

It works always you can try this

var vid = document.getElementById("myVideo");
vid.playbackRate = 0.5;
Castaway answered 29/6, 2022 at 6:29 Comment(0)
J
1

If there are multiple videos on the page, most of other answers will only change the first one.

javascript:document.querySelectorAll('video').forEach( (vid) => vid.playbackRate = 1.5 );

^^ this bookmarklet will speed up all videos on the open page.

Jeanett answered 7/2, 2023 at 17:15 Comment(0)
E
1

As posted above, the general solution to this is:

document.querySelector('video').playbackRate = 2.0;

However, if this returns an error like:

caught TypeError: Cannot set properties of null (setting 'playbackRate')

due to the first function returning null (meaning it couldn't find the element specified), then the simple solution is to use a typical selector (ID, Class, etc.). But what I've found is that when this error is thrown even though it should not throw an error as there's a video element and it's the only one on the page, the issue is related to the HTML property of tabindex being set to "-1". Simply using browser inspect to get to the video, then removing the "tabindex" property can fix an error as displayed above.

seen here is "tabindex=-1", removing this will allow the console to locate the element

Extrasensory answered 11/4, 2023 at 6:56 Comment(0)
X
0

using React:

onLoadStart={(e) => {
    e.target.playbackRate = 1.5;
}}
Xerophagy answered 20/4, 2024 at 17:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.