Charlène's

... it's worse than your datacenter.


Loading a mpv profile according to the CPU model on OpenBSD

Latest update: 2021-07-11

I recently found out that mpv was stuttering when i used it on my old Intel Pineview Atom box because the normalisation audio filter munched all the CPU time. I wondered if i could load a profile according to the CPU used, and finally managed to do it.

I thought that it would be integrated with the profile-desc=cond:some_lua_code helper, but it did not work at all.

So at first, in my ~/.config/mpv/mpv.conf, i defined options for the default profile, then the Atom specific profile, with youtube-dl options as a goodie:

# Better youtube quality on higher specced machines
ytdl-format=best[height<=?1080]
# Normalize the audio output
af=loudnorm=I=-15

[atom]
# Reduce youtube quality on that slow Atom box
ytdl-format=best[height<=?360]
# And clear the normalization audio filter (it uses a lot of cpu)
af=

mpv has lua scripting capabilities that will be required to make the profile autoloading work. As expected, if the CPU model is an Atom, it will apply the "atom" profile.

$ cd ~/.config/mpv
$ mkdir scripts
$ cat > scripts/autoprofile.lua
h = io.popen("sysctl hw.model")
v = h:read("*a")
h:close()
if string.find(v, "Atom", 1, true) ~= nil then
    mp.commandv("apply-profile", "atom")
end
^D

You can check out if everything is correct with mpv -v [...]. Enjoy :)