Forum › Forums › General › Tips and Tricks › mpv –hwdec=auto
- This topic has 30 replies, 9 voices, and was last updated Mar 31-1:05 pm by subluminal.
-
AuthorPosts
-
February 24, 2022 at 5:51 pm #78055Member
blur13
Hi!
Background: on my old netbook from 2011 I have noticed that videos tend to run a lot smoother using VLC rather than MPV. Using the same video as a benchmark, the CPU runs at 20% using VLC and around 80% using mpv. Thats a shame, because I like the “minimalist” look of mpv. It turns out there is a solution to this. Running
mpv --hwdec=autoenables hardware acceleration which solves the problem. According to the mpv manual, its disabled by default because CPU decoding is better image-wise and the performance improvement is only noticable on old hardware. Well, since antiX is an operating system for old hardware, I thought I’d share this trick here. At least on my netbook, it makes mpv a viable alternative again.
February 24, 2022 at 6:09 pm #78057Moderator
christophe
February 24, 2022 at 6:53 pm #78063Member
marcelocripe
::Hello blur13.
As soon as possible, I will test the solution you found. If all goes well, this solution will be the answer to the doubts that were raised in the topics:
https://www.antixforum.com/forums/topic/antix-21-beta2-iso-files-available/page/3/#post-66956
https://www.antixforum.com/forums/topic/antix-21-beta2-iso-files-available/page/4/
Thanks.
marcelocripe
– – – – –
OlĂĄ blur13.
Assim que for possĂvel, eu irei testar a solução que vocĂȘ encontrou. Se tudo correr bem, esta solução serĂĄ a resposta das dĂșvidas que foram levantadas nos tĂłpicos:
(Os endereços de URLs estĂŁo no texto da tradução automĂĄtica para o idioma InglĂȘs.)
Obrigado.
marcelocripe
February 24, 2022 at 8:58 pm #78074Memberolsztyn
::I have noticed that videos tend to run a lot smoother using VLC rather than MPV. Using the same video as a benchmark, the CPU runs at 20% using VLC and around 80% using mpv. Thats a shame, because I like the âminimalistâ look of mpv. It turns out there is a solution to this. Running
mpv –hwdec=auto
enables hardware acceleration which solves the problem.
Thanks for the tip… However I did not experience high CPU usage with MPV. When I run HD video (from SMB share) my CPU stays about 20%. Lower resolution: 12-15%. Playing silky smooth…
The above setting did not change CPU usage. How can I tell if hardware acceleration is enabled on MPV? Perhaps it is already enabled?
My testing is on Thinkpad T410 – i5 CPU and 4G memory – Laptop also from 2010-2011… Running antiX 21 Runit Live…
Thanks and Regards…- This reply was modified 1 year, 2 months ago by olsztyn.
Live antiX Boot Options (Previously posted by Xecure):
https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_ParametersFebruary 24, 2022 at 9:33 pm #78081Member
blur13
::https://mpv.io/manual/stable/#options-hwdec
my netbook has a AMD C-60 processor so I think i5 CPU is order of magnitude more powerful đ
February 24, 2022 at 9:55 pm #78085Membercalciumsodium
::Hi,
I tried this tip on my hp 650 g2 with an i5-processor.
This is what I found:
mpv https://vid.puffyan.us/watch?v=WizPqD0A83g
uses 3% cpu
mpv –hwdec=auto https://vid.puffyan.us/watch?v=WizPqD0A83g
uses 3% cpu
So, I did not find any difference on my system.
February 25, 2022 at 11:42 am #78096MemberRobin
::I have tried this very MPV command switch while writing aCSTV script for antiX, but found also it didn’t make any difference in CPU usage, at least on my 32 bit systems. Only some additional lines show up in console output, possibly it simply fails, maybe it is activated already:
... Running DIL (3.22.0) Version DtsDeviceOpen: Opening HW in mode 0 DtsDeviceOpen: Create File Failed ...Since the CPU usage is that low (max 20% with some peaks above) when using MPV also without this command switch, I didn’t care for this command.
Maybe it makes a difference whether using the Nouveau driver instead of the proprietary Nvidia driver. The latter allows playing video with MPV producing very low CPU usage already, while the Nouveau driver outpowers the CPU to 100% when trying to play the very same videos on the very same hardware. And it doesn’t make any difference then, which video player program I used for testing, all of them behave the same.So I came to the presumption, when running on proprietary Nvidia drivers MPV makes use of hardware acceleration already.
But there is another interesting switch I used in aCSTV to allow automatic selection of the appropriate video stream MPV uses. The main reason for video display distortion is: The streams sent by default have to high a bitrate to run on older hardware nowadays.
So you could try the MPV switch
--ytdl-format='best[tbr<=2999]/bestvideo[tbr<=2999]+bestaudio'Adapt the value 2999 in both positions according to your needs (e.g. a value of 1600 will give you the maximum available lower quality stream below this bitrate, while e.g. 3600 will limit it to that bitrate and chose the best stream available with a bitrate below this one.) This is the way my aCSTV script selects the stream in a bitrate not higher than the hardware can process it, once user has defined it in its settings page. The default value 2999 is what I found to be running without distortion on a 20 years old 32bit single core 1,7 GHz CPU with dedicated graphics card and proprietary nvidia drivers on antiX 19 (presuming any newer equipment would be fine with that value also). You may have to set a lower value when running on onboard-graphics or graphics using shared memory with CPU. Or set a higher value when your hardware or internet connection can handle it.
Probably this is what makes the main difference between VLC and MPV in this concern: MPV by default choses highest quality stream always, regardless whether hardware can play it, while VLC by default probably choses what is known to run whithout distortion on a specific hardware. And this MPV behaviour which was fine some time ago still, when there were no ultra-hq streams available, is problematic nowadays when providers like youtube or tv stations have upgraded to streams of e.g. 7200 and above, which can’t run distortion free on older devices anymore. So the selection of the correct stream (in terms of bitrate) is eminent nowadays, while it was not some time ago.
Windows is like a submarine. Open a window and serious problems will start.
February 25, 2022 at 9:42 pm #78114Member
blur13
::mpv test.mp4 (+) Video --vid=1 (*) (h264 1920x1080 25.000fps) (+) Audio --aid=1 --alang=eng (*) (aac 2ch 44100Hz) AO: [alsa] 48000Hz stereo 2ch float VO: [gpu] 1920x1080 yuv420p AV: 00:01:00 / 00:20:48 (4%) A-V: -0.000mpv --hwdec=auto test.mp4 (+) Video --vid=1 (*) (h264 1920x1080 25.000fps) (+) Audio --aid=1 --alang=eng (*) (aac 2ch 44100Hz) Using hardware decoding (vdpau-copy). AO: [alsa] 48000Hz stereo 2ch float VO: [gpu] 1920x1080 nv12 AV: 00:01:04 / 00:20:48 (5%) A-V: 0.000Tested on my desktop with CPU: Quad Core Intel Core i7 860 (-MT MCP-) speed: 2800 MHz
It makes a slight difference. CPU goes from 6-7% to 4-5% with hwdec=auto.
Obviously it seems to be hardware dependent if hardware decoding makes a difference. But on my underpowered netbook it made a huge difference.
March 4, 2022 at 1:02 pm #78531Memberclementishutin
::And this MPV behavior, which was acceptable a few years ago when there were no ultra-high-definition streams accessible, has become troublesome now that providers such as YouTube and television stations have updated to streaming.
March 13, 2022 at 1:43 pm #78997Membercalciumsodium
::I resurrected on of my old computers that I had built from various parts. This computer has 500 Mb of ram installed.
I tested watching a youtube video with and without –hwdec=auto. The CPU usage would fluctuate initially, but after about 1 minute, the CPU usage would stabilize. And that is when I record the following data.
With –hwdec=auto (see screenshot-2),
CPU: 39%
RAM: 153 MbWithout –hwdec=auto (see screenshot-3),
CPU: 38%
RAM: 154 MbI repeated the experiment several times.
So I did not see a difference on this system. Perhaps it is hardware dependent.
Attachments:
March 28, 2022 at 1:09 pm #80038Membersubluminal
::There are several factors to consider.
Your hardware i.e. GPU. RAM and CPU don’t matter as much with mpv.
Video Codec of the video you’re trying to decode. Older GPUs may not have avc/vp9/av1 decode capabilities. If the GPU is even older, i.e. ancient, GPU may not even support –vo=gpu option which is the default setting for mpv (as well as –hwdec=no, default). hwdec=auto is no good if your GPU doesn’t have the capability to decode that particular video codec. mpv in that case falls back to software decoding which eats a lot of cpu.
Before doing anything on old hardware using mpv, check if vo=gpu is available. Run ‘mpv –vo=help’. If vo=gpu isn’t available, vo=xv is a decent bet although the performance is terrible. Again, all depends on your hardware.
Most hardware made in the last 10 years would be able to decode h264/avc and most hwardware made in past 7-ish years can decode h264 and vp9. Only RDNA2, Iris Xe and Ampere(Nvidia) can do hardware level decoding for av1 although mpv uses dav1d by default which does (very efficient) software decoding (for mpv v 0.33) older versions of mpv use libaom which is far worse than dav1d.
So, to summarize, if your GPU can decode the video codec of the video you’re playing, keep hwdec=no in config file, or simply don’t use it since it is the default setting, then in runtime, press ‘Ctrl+h’ to enable hardware decoding.
On a side note: This is my mpv config. I use mpv to play video, view images and listen to music from youtube. Beware, some of these settings require good GPU to run. Even a decent intel iGPU would suffice. Mostly. Read the remarks and README.
https://github.com/subluminal-byte/mpv-config-video-image-viewer
Cheers.
- This reply was modified 1 year, 1 month ago by subluminal.
March 28, 2022 at 9:33 pm #80060MemberModdIt
::Hi subluminal,
thanks for detailed info and tips for MPV. Will see how your config options run on my present desktop
hardware, i5-2500K CPU presently clocked @ 3.30GHz + GeForce GTX 550 Ti 8GB Ram.All fits to my experiments with latest ytfzf vers 2.2, so many options to explore, brilliant lightweight
tool for searching/scraping video sites.March 29, 2022 at 9:39 am #80078Membersubluminal
::I would be very interested to know how it works in your hardware as well since I only tested it in my own and my friend’s.
Your hardware should be able to handle scale=ewa_lanczossharp with FSRCNN-8 perhaps even FSRCNN-16 version although the quality improvement of 16 over 8 is minimal. Again, depends on the video resolution and display/monitor/TV resolution. 480p/360p content on 1080p/2K monitor would be interesting.
I also added FSR.glsl. Although FSR is by AMD, it works on intel iGPU as well. There is also the NVScaler.glsl for Nvidia GPUs.
https://gist.github.com/agyild
In my testing, if you only use mpv’s built-in scalers, then in terms of image/video quality (for Luma plane only):
bilinear(default for mpv) < bicubic(default for a lot of other media players including vlc) < spline36(set as default in mpv’s built-in gpu-hq profile) = lanczos(sharper but more ringing artifacts than spline36) < spline64 < ewa_robidouxsharp < ewa_lanczossharp(very high quality)
Of course, in terms of speed the order is reverse, for obvious reasons. Better scalers require more GPU resource.
Highest possible image/video quality combination is ewa_lanczossharp+FSRCNN-8 for Luma upscale, KrigBilateral+cscale=ewa_lanczossoft/sharp for chroma plane upscale, deband=yes, SSimDownscaler+mitchell for dscale. Used with vo=gpu, gpu-api=opengl and hwdec=no.
That scaler combo is for Real-life content. For anime, Anime4K is supposedly better. I haven’t tested it yet. I haven’t watched very many anime lately.
- This reply was modified 1 year, 1 month ago by subluminal.
- This reply was modified 1 year, 1 month ago by subluminal.
March 29, 2022 at 10:42 am #80083Member
blur13
::subluminal
Thank you, your posts have been very informative. Seems there is a lot more to mpv than simply pressing “play”. Using hwdec=auto made mpv usable on my underpowered netbook, but judging from other posts in this thread that seems to be an outlier.
“So, to summarize, if your GPU can decode the video codec of the video youâre playing, keep hwdec=no in config file, or simply donât use it since it is the default setting, then in runtime, press âCtrl+hâ to enable hardware decoding.”
This confused me. Why keep hwdec=no to subsequently enable it using ctrl+h? If hardware decoding makes a difference then why not enable it in the config?
March 29, 2022 at 12:48 pm #80090Membersubluminal
::hwdec=auto/yes has trouble with video filtering. Color conversion may be required which adds an extra step, which eats more resource. Even with a good GPU (and proper driver) color conversion may produce slightly inferior or downright incorrect colors( Driver bug – no driver, doesn’t matter if it’s Intel, AMD or Nvidia, is without one). And even if colors are properly converted before filtering, some filters like vapoursynth scripts of SVP for motion, true motion, interpolation simply doesn’t work with hwdec=yes/auto. hwdec=auto-copy does work but it produces terrible performance on iGPU compared to using hwdec=no because it copies data to and from VRAM introducing latency.
In short, IF you do a lot of video filtering while playing video using mpv, hwdec=no produces best and most consistent bug-free results, although it does also use more resource. mpv devs themselves suggest either hwdec=no (default) or if your hardware is limited and you don’t use exotic video filters, hwdec=auto-safe.
- This reply was modified 1 year, 1 month ago by subluminal.
-
AuthorPosts
- You must be logged in to reply to this topic.

