How to enable VP9 codec on Google Stadia in Chromium

Reasoning

I needed to run Stadia on a Libreboot laptop which runs entirely free software. This includes Chromium, which meeans, that I have to use VP9 codec in Stadia to even make it work. Otherwisee it would not work.

Introduction

First we have to understand what is going on. At the end of the day, Stadia is a video stream. This compressed video stream needs to be encoded by Google servers and decoded by your device to display the games you play. The most popular compression codec is H.264. Many devices are able to utilise this tech as it offers a decent image quality, low file sizes (in this case bandwith) and can be practically decoded by almost any device as it is not CPU intensive. I have recently found out through this post that Stadia on Chrome defaults to H.264.

Enter VP9 codec. This is a vastly superior codec to H.264, the quality and sharpness of the image looks much better than a H.264 video and is a streaming codec supported by Stadia. The big BUT is that VP9 decoding uses much more CPU, so older and weaker devices may have a hard time decoding and could start stuttering. There are low powered devices such as mobile phones and Chromecasts that can handle VP9 like butter, this is because of dedicated hardware decoding. If you go on Youtube, right click a video and click stats for nerds, you can see next to codec that most 1080p videos or lower are actually AVC or H.264 quality, there are some tricks to make YouTube encode the video to VP9 and it looks much much better, foliage and text is sharper.

Manual method

Run:

localStorage.setItem("video_codec_implementation_by_codec_key", '{"vp9":"ExternalDecoder"}')

in the browser console while on stadia.google.com it will force vp9 for the next game session, but after that it goes back to h264.

Do this before every session, go to stadia.google.com, right click and press inspect elements. There should be a tab next to elements called console. copy and paste the above code to the console and press enter. The video codec should now be VP9.

Tampermonkey script

// ==UserScript==
// u/name         Stadia
// u/namespace    Stadia
// u/version      0.1
// u/description  Will force fullscreen on any Stadia launch URL for the first click.
// u/author       EricLowry
// u/include      /^https:\/\/stadia\.google\.com\/(u\/[0-9]+\/)?player\/.+/
// u/grant        none
// ==/UserScript==


// Fullscreen
(function() {
        document.body.addEventListener('click', fsTrigger, true);
    function fsTrigger() {
        document.body.requestFullscreen();
        document.body.removeEventListener('click', fsTrigger, true);
    }
})();

// Force VP9
(function() {
    localStorage.setItem("video_codec_implementation_by_codec_key", '{"vp9":"ExternalDecoder"}')
})();

Notes: It also includes a “force fullscreen” function which will ensure Stadia always starts up as fullscreen, but you can delete that part if you want =D