I was just looking a web stream on Youtube today and was wondering why my CPU was so busy. So I fired up top and saw my web browser (Firefox) took up around 70% of a CPU to play the stream.

I thought, "this must be some high resolution crazy stream! how modern! such wow!" Then I thought, wait, this is the web, there must be something insane going on.

So I did a little experiment: I started chromium --temp-profile on the stream, alongside vlc (which can also play Youtube streams!). Then I took a snapshot of the top(1) command after 5 minutes. Here are the results:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
16332 anarcat   20   0 1805160 269684 102660 S  60,2   1,7   3:34.96 chromium
16288 anarcat   20   0  974872 119752  87532 S  33,2   0,7   1:47.51 chromium
16410 anarcat   20   0 2321152 176668  80808 S  22,0   1,1   1:15.83 vlc
 6641 anarcat   20   0   21,1g 520060 137580 S  13,8   3,2  55:36.70 x-www-browser
16292 anarcat   20   0  940340  83980  67080 S  13,2   0,5   0:41.28 chromium
 1656 anarcat   20   0 1970912  18736  14576 S  10,9   0,1   4:47.08 pulseaudio
 2256 anarcat   20   0  435696  93468  78120 S   7,6   0,6  16:03.57 Xorg
16262 anarcat   20   0 3240272 165664 127328 S   6,2   1,0   0:31.06 chromium
  920 message+  20   0   11052   5104   2948 S   1,3   0,0   2:43.37 dbus-daemon
17915 anarcat   20   0   16664   4164   3276 R   1,3   0,0   0:02.07 top

To deconstruct this, you can see my Firefox process (masquerading as x-www-browser) which has been started for a long time. It's taken 55 hours of CPU time, but let's ignore that for now as it's not in the benchmark. What I find fascinating is there are at least 4 chromium processes running here, and they collectively take up over 7 minutes of CPU time.

Compare this a little over one (1!!!11!!!) minute of CPU time for VLC, and you realize why people are so ranty about everything being packaged as web apps these days. It's basically using up an order of magnitudes more processing power (and therefore electric power and slave labor) to watch those silly movies in your web browsers than in a proper video player.

Keep that in mind next time you let Youtube go on a "autoplay Donald Drumpf" playlist...

video acceleration
Isn't this because VLC can take advantage of VA-API for hardware accelerated decoding? Where as Firefox has no support and Chromium requires an out-of-tree patch.
Comment by deccelerator
Higher quality YouTube is DASH-only

Unless something changed recently, VLC is limited to 720p. That won't truly affect any conclusions, but for a completely fair comparison you'd have to take down YT to 720p, specifically in mp4 so any potential hardware acceleration can do its job on the browser too. On Chromia you might have to flip a flag to enable that at all.

Alternatively and for a better video viewing experience, you can download or pipe better quality video/audio with youtube-dl.

$ youtube-dl -F "https://www.youtube.com/watch?v=tyOHcXKlyU8"  
[youtube] tyOHcXKlyU8: Downloading webpage
[youtube] tyOHcXKlyU8: Downloading video info webpage
WARNING: Unable to extract video title
[info] Available formats for tyOHcXKlyU8:
format code  extension  resolution note
249          webm       audio only DASH audio   60k , opus @ 50k, 6.30MiB
250          webm       audio only DASH audio   86k , opus @ 70k, 8.18MiB
140          m4a        audio only DASH audio  131k , m4a_dash container, mp4a.40.2@128k, 15.53MiB
251          webm       audio only DASH audio  164k , opus @160k, 15.87MiB
160          mp4        256x144    144p  109k , avc1.4d400c, 24fps, video only, 6.70MiB
278          webm       256x144    144p  118k , webm container, vp9, 24fps, video only, 11.36MiB
242          webm       426x240    240p  229k , vp9, 24fps, video only, 13.57MiB
133          mp4        426x240    240p  294k , avc1.4d4015, 24fps, video only, 12.39MiB
243          webm       640x360    360p  401k , vp9, 24fps, video only, 22.38MiB
134          mp4        640x360    360p  579k , avc1.4d401e, 24fps, video only, 22.12MiB
244          webm       854x480    480p  703k , vp9, 24fps, video only, 32.00MiB
135          mp4        854x480    480p  809k , avc1.4d401e, 24fps, video only, 31.22MiB
136          mp4        1280x720   720p 1125k , avc1.4d401f, 24fps, video only, 46.40MiB
247          webm       1280x720   720p 1242k , vp9, 24fps, video only, 53.06MiB
248          webm       1920x1080  1080p 2642k , vp9, 24fps, video only, 152.24MiB
137          mp4        1920x1080  1080p 3770k , avc1.640028, 24fps, video only, 161.78MiB
43           webm       640x360    medium , vp8.0, vorbis@128k, 83.67MiB
18           mp4        640x360    medium  460k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 55.23MiB
22           mp4        1280x720   hd720 1428k , avc1.64001F, mp4a.40.2@192k (44100Hz) (best)

If I right click on a YouTube video and click "stats for nerds," I find that it typically prefers to send VP9 with Opus. The Opus stream (251) provides the best audio.

In my case, to match what YouTube sends to my browser I have to use something like this:

$ youtube-dl -f 248+251 "https://www.youtube.com/watch?v=tyOHcXKlyU8"

Play that back in VLC or mpv and you'll find it uses a lot more CPU. By contrast, force YouTube to use 720p with H.264 for hardware acceleration and it'll use less. The difference should still be pronounced, mind you, but not quite by an order of magnitude.

Comment by Frans
Comments on this page are closed.
Created . Edited .