What is it with Ubuntu / Linux, Youtube / HTML5 videos and the high CPU load?

14,095

Solution 1

Since your system has both Nvidia and Intel GPU, and the problem is found on every single browser you're using. It's definitely a problem with the drivers and not the browsers. Even though Chrome is not helping by not providing video hardware decoding. You should try using only the Intel GPU which has more stable drivers on Linux.

@Quasdunk reported that switching to the Intel GPU lowered significantly the load on the machine and now it's usable.

If you really want to use the Nvidia GPU, you should try upgrading your drivers using this ppa.

Solution 2

I had similar issue. My CPU used >100% in htop while watching YouTube videos in 1080p.

Specs:

CPU: 7700k
GPU: Nvidia GTX 1080
Drivers: 384.69

I had to install these plugins:

sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly

Then went to Google Chrome flags page chrome://flags/ and enabled option:

WebRTC H.264 software video encoder/decoder Mac, Windows, Linux, Chrome OS

Screen: enter image description here

After restarting browser my cpu usage dropped to around 30%.

As a last resort You can always disable Video Hardware Decode by using command line:

google-chrome --disable-accelerated-video-decode 

Here's a list of all possible command line options for Google Chrome: https://peter.sh/experiments/chromium-command-line-switches/

Alternative Solution:

There is another thing that, for me, made my CPU go high. It was a js script on the YouTube. I had to block it in uBlock addon:

enter image description here

Red rectangle shows many requests from a mss_4.js script - this caused the CPU spikes. Green rectangle shows that the script is blocked inside the uBlock addon, so no more request inside the mss_4.js are made.

Share:
14,095

Related videos on Youtube

Quasdunk
Author by

Quasdunk

Updated on September 18, 2022

Comments

  • Quasdunk
    Quasdunk almost 2 years

    I've been googling around for a few weeks now and trying all the different solutions, but I could neither find a working solution nor a satisfying answer to my question: Why does a Youtube HTML5 video on Ubuntu / Linux make the CPU go through the roof? Since I've found similar questions, I know it's not only me.

    I have an Nvidia GeForce 660M and Intel Graphics on a Core i7 (with 8 cores).

    Watching a 1080p video on Ubuntu 16.04 (with both Firefox and Chromium) the CPU load builds up to 100% over a few minutes, turning the video into a slide show and making the computer not usable at all. But streaming those videos with VLC or Totem is no problem whatsoever (that's why most solutions I've found so far suggest this workaround).

    Watching the same videos on Windows (on the same laptop) does not really look differently from editing a Word file in terms of CPU load.

    So this means the problem must be specifically related to the browser in combination with Linux / Ubuntu.

    Yes, HTML5 is supported:

    html5-support


    Yes, I have Nvidia drivers installed:

    enter image description here


    Here's what chrome://gpu gives me:

    enter image description here


    So it seems like hardware acceleration for video decoding is not available. How can I make it available? Is it even possible? If no: Why not and will it ever be? Is there another configuration option that I'm missing?

    It's 2017 and being able to watch funny cat videos in high quality on a decent computer should be a pretty basic thing!

    • Felipe
      Felipe about 7 years
      hardware acceleration hasn't been enabled since 2012 and it won't be anytime soon from what I read. Nonetheless, you shouldn't have a problem using software decoding for your videos, your CPU shouldn't jump that high. Do you experience the same when using Firefox? if so, it might be related to the fact that you have 2 graphics cards
    • Quasdunk
      Quasdunk about 7 years
      @Felipe That doesn't really sound very promising. Yes, I also stumbled upon an articel from 2014 stating something similar, but since it's really old I didn't take it too seriously. And yes, I also read about the 2 graphics card issue, that's why I installed nvidia-prime and explicitly told it to use the Nvidia GPU as suggested here. I really can't believe hardware acceleration is not possible on one of the most popular OS... And yes, it's the same in Firefox (and Vivaldi).
    • Felipe
      Felipe about 7 years
      so does the same happens when using Firefox? like I said, if it does it might be harder to solve, but if Firefox works fine, then it might just be a faulty Chrome installation. Also, try making nvidia-prime only use the Intel GPU. I would test every possibility to see what happens and narrow down the problem.
    • Quasdunk
      Quasdunk about 7 years
      @Felipe sorry, I've edited my comment later on regarding other browsers. So yes, it's the same in Firefox, Chromium and Vivaldi. I did now switch to the Intel GPU, even though I had tried that too, but that was a while ago and some things changed since then. It seems to run more stable (the load average did not go above 2.0 even after 5 minutes). If that's really the solution, the issue might be with the Nvidia drivers (even though I've tried all of them already). I'll have a look at how the Intel GPU handles it now in a longer term and report back :) Thank you!
    • Felipe
      Felipe about 7 years
      Have you tried using the Nvidia drivers from this ppa, give it a try they have the latest stable drivers: launchpad.net/~graphics-drivers/+archive/ubuntu/ppa
    • Quasdunk
      Quasdunk about 7 years
      @Felipe No, I actually didn't try those. But the PPA looks pretty neat, I guess I'll give it a shot, but not right now. Your idea to switch to the Intel GPU seems to work great so far. I have a 25-30% CPU average on 1080p videos and a 15-20% average on 720p videos, which is still ridiculous IMO but it's stable and by far less than 100% :-) I think I'll stick to that for a while before experimenting any further. Please feel free to post your thoughts as an answer so I can accept it. If I have any luck with the other drivers, I'll then add my observations to your answer if that's ok.
  • Quasdunk
    Quasdunk about 7 years
    Thank you very much! Even though it turned out to be more of a driver issue rather thank specifically browser/OS related, just one more time for the record: Hardware video acceleration does not work on Linux and won't be working any time soon! Switching to the Intel GPU makes it now bearable, but using 30% of an i7 CPU just to watch a video in the browser is still pretty insane.
  • Md. Abu Taher
    Md. Abu Taher over 5 years
    A shortcut for WebRTC flag chrome://flags/#enable-webrtc-h264-with-openh264-ffmpeg
  • Martin Thoma
    Martin Thoma over 4 years
    I have a T460p with an Nvidia GeForce 940MX on Ubuntu 18.04. I turned the setting to "battery saving" (using the CPU instead of the GPU). This made my computer SUPER hot some times when watching YouTube. Interestingly, only recently (a couple of days ago, I guess). I'm not sure if I changed anything. I have chrome 79.0.3945.79 at the moment and changing the Nvidia setting to performance (using gpu) seems to have fixed the issue.
  • Martin Thoma
    Martin Thoma over 4 years
    Never mind, it did NOT solve my problem. I had wg-gesucht.de/wg-zimmer-in-Muenchen-Berg-am-Laim.3570695.htm‌​l open for a while and it started using heating my CPU up again.