How to change the video play speed in HTML5? I've checked video tag's attributes in w3school but couldn't approach that.
17 Answers
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+.
-
1Thanks 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!– YoungCommented Jun 12, 2010 at 9:31
-
5playbackRate works in Firefox since version 20. It also works in Chrome. Commented Jul 11, 2013 at 16:04
-
2this 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();} Commented Dec 19, 2013 at 11:48
-
its not working for Ionic android...I am using HTML% video player in ionic framwork for android but it not support playback rates......... Commented Nov 26, 2015 at 7:43
-
2@Sushan
.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.– leewzCommented Jul 6, 2017 at 5:01
Just type
document.querySelector('video').playbackRate = 1.25;
in JS console of your modern browser.
-
3Some 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. Commented Nov 9, 2018 at 16:45
-
I copy/pasted this code in the F12 developer tools on the browser and it works. Commented Jun 23, 2022 at 20:53
-
2To 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. Commented Jul 3, 2023 at 6:45
(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.
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:
References:
- The main answer by Jeremy Visser
- Copied from my GitHub gist here: https://gist.github.com/ElectricRCAircraftGuy/0a788876da1386ca0daecbe78b4feb44#other-bookmarklets
- Get other bookmarklets here too, such as for aiding you on GitHub.
solutions
- dom event
onloadstart="this.playbackRate = 1.5;"
<video
onloadstart="this.playbackRate = 1.5;"
controls
src="https://cdn.xgqfrms.xyz/HTML5/video/controlslist.mp4">
</video>
- 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
-
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. Commented Jun 14, 2023 at 15:04
-
If the DOM content is created dynamically using js, it will overwrite any modifications you have made.– xgqfrmsCommented Jun 15, 2023 at 0:22
-
If you still have problems, please give a complete demo code URL of an online editor, such as codepen.io, codesandbox.io– xgqfrmsCommented Jun 15, 2023 at 0:27
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.
-
Good idea to customize keys for faster speed changes! Thanks for sharing.– devdankeCommented Jan 27, 2022 at 2:02
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;
}
-
Hi @Armel, may I know where to put this code if I am using Selenium with Python?– rpbCommented Apr 19, 2020 at 11:31
-
In chrome, create a new bookmark
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
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.
It works always you can try this
var vid = document.getElementById("myVideo");
vid.playbackRate = 0.5;
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.
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
-
negative values are not working in Chrome. wish they were, that'd be a nice easy rewind or reverse play feature– OG SeanCommented Jan 25, 2023 at 6:05
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.
<video src={USERBG} autoPlay loop muted controls onLoadStart={(e) => (e.target.playbackRate = 0.5)} className="object-cover object-center w-full h-full fixed top-0 left-0 z-10" >
-
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.– Community BotCommented May 12 at 15:02