ghostlexly / gpu-video-wallpaper

Use your GPU for rendering low CPU usage video animated wallpaper.
MIT License
165 stars 12 forks source link

Tips for Battery Optimization #11

Closed gjgress closed 1 year ago

gjgress commented 2 years ago

I often need to work from my laptop without access to my charger, and so running mpv in the background with default settings all the time is a serious battery drain.

Fortunately, mpv can be easily configured to reduce power-- especially in this case, when one does not need to worry about things like video/audio desync, cutting out some of the superfluous mpv features goes a long way.

I'm just opening this issue to share my mpv config optimized for this script in particular, in case other users have the same needs. In your local mpv config location (either ~/.config/mpv/mpv.config or /etc/mpv/mpv.config), add to your config the following profile:

[lowpower]
profile-desc = "Profile designed to run mpv and minimize battery usage, perfect for using mpv for backgrounds and whatnot. Set for files with no audio"
deband=no
gpu-dumb-mode=yes
hwdec=auto-safe
hwdec-codecs=all
interpolation=no
osc=no
terminal=no
video-sync = display-desync
vo=gpu
vd-lavc-fast
vd-lavc-skiploopfilter=all
ytdl=no

Of course, you have to enable the profile for this to work. In the video-wallpaper.sh script, adding the --profile=lowpower flag to the xwinwrap call will do exactly this.

Obvious caveat: I can't guarantee this profile will work on all computers. If mpv does not work with this profile, try removing the hwdec-codecs=all line or the vo=gpu line. In terms of performance, this reduced my power usage to 3% of the original power usage (even lower than my compositor!), and I didn't notice a significant drop in quality.

I don't think I could in good faith suggest adding any of these flags to the default behavior in the repo. That being said, these options can be toggled directly by just adding the flag to mpv. The safest options are:

I think vd-lavc-skiploopfilter is also safe too.

I hope this helps!

ZediAlreadyTaken commented 2 years ago

Will this also pause the playback when the desktop is out of focus? If not, then is there something we could change to achieve such behavior?

gjgress commented 2 years ago

Hmm, that's a tougher question. To get such behavior, you would have to either:

I use a compsoitor with semi transparent windows, so for me I wouldn't want such behavior. And while it would save battery power I'm sure, it wouldn't make a massive difference (no more than turning off your compositor)

That being said, since this profile relies on mpv to utilize the gpu, its possible (I don't know) that it could affect games. But I think a much simpler solution would be to map a key to video-wallpaper.sh --start' andvideo-wallpaper --stop`, personally.

SwallowYourDreams commented 2 years ago

I don't think I could in good faith suggest adding any of these flags to the default behavior in the repo. That being said, these options can be toggled directly by just adding the flag to mpv. The safest options are:

Thank you for your suggestion. I'll try it out and will consider adding it to the script. Could you elaborate on the "risks" associated with using this config or the corresponding flags?

gjgress commented 2 years ago

Hi SwallowYourDreams,

I'll do my best (I'm not a mpv power user).

This mode is extremely restricted, and will disable most extended features. That includes high quality scalers and custom shaders!

It is intended for hardware that does not support FBOs (including GLES, which supports it insufficiently), or to get some more performance out of bad or old hardware.

This mode is forced automatically if needed, and this option is mostly useful for debugging. The default of auto will enable it automatically if nothing uses features which require FBOs.

This option might be silently removed in the future.

It's probably not a good idea to enable this by default because it disables pretty much all new features. It's just an easy way to disable a lot of heavy resources like shaders that consume power pretty heavily. As a result, I don't think its a good idea to enable in general (but it could be worth using on your own config if you are still starved for battery)

Specify the hardware video decoding API that should be used if possible. Whether hardware decoding is actually done depends on the video codec. If hardware decoding is not possible, mpv will fall back on software decoding.

Hardware decoding is not enabled by default, because it is typically an additional source of errors. It is worth using only if your CPU is too slow to decode a specific video.

Most modern computers use hardware which is compatible with hardware decoding. This is also another huge power saver. Auto-safe means that it will only use codecs which are white-listed (I think the white-listing is determined by the hardware, but I don't know for sure). My understanding is that if your hardware does not support decoding, this will simply disable hwdec anyway.

To be honest, playing around with MPV flags is dangerous business because it is so difficult to standardize across different machines. That's why I decided to open an issue with this information instead of a pull request; that way if other uses are concerned about the battery usage, they can experiment for themselves and find a configuration that works for them.

Upon further reflection, I don't know if I would suggest any of these flags to be enabled by default. It's just a headache waiting to happen.