Playing 4K videos in Windows 10 with NVIDIA hardware decoding and low CPU utilisation
If the playback of 4K videos is causing your processor fans to spin themselves to bits or the quality of the playback is an annoyingly inconsistent frame skipping mess, this may help you.
The default Windows movie player app and alternatives like VLC and smplayer can play videos with hardware decoding but I frequently have playback issues. In search of something that works and is simple, say hello to mpv.io a free, open source, and cross-platform media player.
Using MPV to playback 4K videos has provided me with the smoothest viewing experience compared to anything I have ever used but there is one small catch. Out of the box it defaults to software decoding (using your CPU), so you need to configure it to take advantage of hardware decoding, i.e, nvidia NVENC. Go to the options and tick a few boxes? Unfortunately not, you have to configure it by way of a text file named mpv.conf. Realistically all this means is using notepad to type a few characters... or since you are here reading this blog all you have to do is copy and paste what I have written for you, and save the file. Easy!
7-zip will be required to extract MPV from the download. Available here https://www.7-zip.org/download.html
Head over to mpv.io and download MPV, by clicking on the 'installation' link at the top of the page.
Click on the link to the Windows builds, https://sourceforge.net/projects/mpv-player-windows/files
This will take you to another site. Scroll down and click on the 64bit folder link
Scroll down and click on the latest MPV player version, for example at the time of writing this is the link titled mpv-x86_64-20220306-git-1c49d57.7z dated 2022-03-06.
Seconds later your download should have started and will be saved to where ever you saved it to or typically in your Downloads folder under Windows.
You will need 7-zip install for this next bit. Go to your downloads folder, in my case the 'Downloads' folder under Windows. Right click on the mpv-x86_64-20220306-git-1c49d57.7z file, in the context menu hover over '7-Zip' then left click the option that says "extract to mpv-x86_64-20220306-git-1c49d57\"
This will cause the 7-zip file archive to be extracted to a folder with the name mpv-x86_64-20220306-git-1c49d57 in the same location.
As you can see in the screenshot. This folder contains the MPV application and all its program files. Please continue by double clicking on the mpv-x86_64-20220306-git-1c49d57 folder.
If everything went well, you should see folder with contents resembling the screenshot above. Open the folder called installer. Right click on the file called mpv-install and in the context menu click on 'Run as administrator'. This will install MPV on your PC.
MPV will now configure your Windows to associate certain file type to MPV. Once this is complete you will see the following;
If you do not wish for MPV to be the default video player skip the above, if you do, then click on the 'Associate a file type or protocol with a program' and choose MPV as the default video player, see below screenshot.
This next bit is where we are going to configure MPV with some options to make your Nvidia GPU do all the decoding. Go back to the mpv-x86_64-20220306-git-1c49d57 folder.
Create a folder called portable_config
The screenshot above shows the folder portable_config that has been created. Double click and open the portable_config folder.
Once inside the portable_config folder, right click anywhere in the empty folder space, in the context menu, hover over the option called 'New' and then left click on 'Text Document'.
This will create a text file in the portable_config folder.
Rename it to mpv.
Open the text file by double clicking on it, this will open up Notepad. This file is used to configure MPV. We will now configure MPV to use nvidia hardware decoding by default. Copy and paste the below options into this file.
#MPV for Windows and NVIDIA NVENC decoding
#Default video output set to GPU. Best CPU utilisation in Windows
vo=gpu
#To enable NVDEC use opengl api
gpu-api=opengl
#Hardware decoder set to NVDEC wont work if above not set to opengl
hwdec=nvdec
#Prevent MPV closing after playback
keep-open
The screenshot below shows the above pasted into the text file.
Once you have pasted the above in this text file, click on 'File' then 'Save As...' It is important you choose 'Save As...'
In the window that popped up, change the 'Save as type' to 'All files' then change the file name to mpv.conf and click on 'Save'.
After following the steps above you can now close the text file. If all is well you should now see the following,
The CONF file is what MPV will read to obtain the settings we copied. The empty text document can be deleted. MPV has now been configured to use your nvidia GPU to perform hardware decoding. If you did not set MPV as the default video player, to view a video file with MPV simply right click the file and choose open with, then select MPV.
How can you tell if nvidia hardware decoding is working?
This is a screenshot showing CPU and GPU utilisation when using MPV out of the box with no configuration settings to play a video.
As you can see, CPU load is at 20% and the video decode graph is showing my GTX 1080 at 0%. After adding the options above into the mpv.conf file,
CPU load is at 2% and the video decode graph is now showing 18%. We have more or less offloaded all the work to the GPU.
I tried to capture the second screenshot at 19.200 but I wasn't quick enough :D
MPV is a very tweakable application, for a full list of additional options you can use in the mpv.conf file refer to the online manual available at https://mpv.io/manual/master/
The options I have used in this article (which are the only options I use) are the absolute minimum to achieve hardware decoding with the lowest CPU load possible. In terms of other options I have no recommendations. During the playback of a video in MPV, pressing Ctrl-H will allow you to toggle between hardware decoding and CPU. Enjoy MPV!
Comments
Post a Comment
If you enjoyed this article please let me know!