How to change the playing speed of videos in HTML5?

253,482

Solution 1

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

Solution 2

Just type

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

in JS console of your modern browser.

Solution 3

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

Solution 4

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.

Solution 5

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

Share:
253,482

Related videos on Youtube

Young
Author by

Young

Updated on April 27, 2022

Comments

  • Young
    Young about 2 years

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

  • Young
    Young about 14 years
    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!
  • Janus Troelsen
    Janus Troelsen almost 11 years
    playbackRate works in Firefox since version 20. It also works in Chrome.
  • john-jones
    john-jones over 10 years
    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_vid‌​eo").defaultPlayback‌​Rate=0.1;document.ge‌​tElementById("master‌​_video").play();}
  • Dinesh R Rajput
    Dinesh R Rajput over 8 years
    its not working for Ionic android...I am using HTML% video player in ionic framwork for android but it not support playback rates.........
  • Sushan
    Sushan about 7 years
    Its not working for multiple video player in same page. Only the first one works fine and other plays in normal speed.
  • leewz
    leewz almost 7 years
    @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.
  • Christopher Harwood
    Christopher Harwood over 5 years
    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.
  • rpb
    rpb about 4 years
    Hi @Armel, may I know where to put this code if I am using Selenium with Python?
  • Armel
    Armel about 4 years
    Hi @balandongiv, I am sorry I don't know :(
  • devdanke
    devdanke over 2 years
    Good idea to customize keys for faster speed changes! Thanks for sharing.
  • Marco Aurelio Fernandez Reyes
    Marco Aurelio Fernandez Reyes about 2 years
    I copy/pasted this code in the F12 developer tools on the browser and it works.