I am playing a very heavy video (bitrate almost 300,000 kb/s) H.264 codec. The video mostly plays well in MPV player except at few frames. However, the GPU usage never goes above 40 % and CPU usage is more than 60%. Can something be done to use GPU more intensively rather than CPU. Below are screenshots of System monitor and Nvidia settings manager
According to the man page, hardware decoding is disabled by default. Did you try pressing Ctrl-h?
From the man page:
Use the
Ctrl+h
shortcut to toggle hardware decoding at runtime. It toggles this option betweenauto
andno
.
Hi Gregory, I used Ctrl+h
to toggle. Hardwared Decoding is on and still CPU usage is 60% as compared to GPU usage which is around 35%.
I made a file in /.config/mpv/mpv.conf
with the following in it
--hwdec = nvdec
--gpu-api=vulkan
and the GPU usage goes up to 60%. However, for some videos the GPU is still utilized only 30%. These are the same videos for which there was lag previously. Maybe it is an issue with the video itself.
Just going by what I see in other online examples (e.g. here), it doesn’t look like you are supposed to include the leading --
when you put the setting in the conf file (it’s possible that the software will know to ignore those, but normally, the --
is only used on the command line). Also, be careful about including spaces around the =
. Sometimes programs know to remove the spaces, sometimes they don’t. It’s best to avoid the spaces unless you know that the “parser” can handle those.
As for why some videos would be accelerated but others would not, that would depend on the abilities of the video driver and the codecs that are installed on the system. I think the vainfo
command should give you a readout of what encodings your system’s driver+codec configuration is capable of “accelerating”.
Thanks Gregory. I made those changes in the config file.
Maybe try something like this (works with nvidia or amg gpu).
vo=gpu-next
gpu-api=vulkan
hwdec=vulkan
gpu-context=auto
Which part of the GPU is being used? Is it using the rendering engine or the decoding engine? Only the latter means that it’s actually hardware decoding the video.
Did you install the RPMFusion packages?
This doesn’t seem to work on my AMD system:
MPV:
[vd] Could not create device.
[vd] Using software decoding.
These parameters do work for me:
# mpv.conf
gpu-hwdec-interop=vaapi
hwdec=vaapi
[vd] Looking at hwdec h264-vaapi...
[vd] Trying hardware decoding via h264-vaapi.
You need the freeworld vulkan package.
sudo dnf swap mesa-vulkan-drivers.x86_64 mesa-vulkan-drivers-freeworld.x86_64
AMD GPU require theses packages for h264 and h265.
$ rpm -qa mesa-*-drivers-freeworld
mesa-va-drivers-freeworld-25.0.1-1.fc42.x86_64
mesa-vdpau-drivers-freeworld-25.0.1-1.fc42.x86_64
mesa-vulkan-drivers-freeworld-25.0.1-1.fc42.x86_64
Nice, that works:
[vd] Looking at hwdec h264-vulkan...
[vo/gpu-next] Loading hwdec drivers for format: 'vulkan'
[vo/gpu-next] Loading hwdec driver 'vulkan'
[vd] Trying hardware decoding via h264-vulkan.
Hopefully this will be added to the RPMFusion wiki as well:
I tried those changes in the config file. And there is seemingly no change. The GPU usage is similar as before
I did install the rpmFusion packages. Also, the decoding is indeed working but it is not getting maxed out even in videos that lag
This might actually be caused by this particular video, its bitrate, and limitations of your hardware decoder. There might not be much you can do except re-encode your video.
Hardware accelerated video typically uses some dedicated circuitry in your GPU or SoC (in case of a smartphone/tablet). These units usually have limitations with regards to what resolutions and bitrates they can decode. Ultimately, this is related to throughput and buffer sizes of that particular piece of logic. When a video exceeds these limitations, the hardware cannot keep up and you will see stutters. According to the NVDEC API documentation, NVDEC supports H.264
- at a resolution up to 4096x4096,
- in the Baseline, Main, High profile, and
- up to Level 4.1.
You haven’t really given any details about your video stream except for its bitrate. Is the stream compliant with these NVDEC limitations? Level 4.1 in particular imposes some constraints that might be lower than what your stream has.
Following is the part of the output of ffmpeg that enlists the video information
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C4639.MP4':
Metadata:
major_brand : XAVC
minor_version : 17506303
compatible_brands: XAVCmp42iso6
creation_time : 2024-12-06T05:14:38.000000Z
Duration: 00:00:57.12, start: 0.000000, bitrate: 310194 kb/s
Stream #0:0[0x1](und): Video: h264 (High 4:2:2) (avc1 / 0x31637661), yuv422p10le(tv, bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 279947 kb/s, 100 fps, 100 tbr, 100k tbn (default)
Metadata:
creation_time : 2024-12-06T05:14:38.000000Z
handler_name : Video Media Handler
vendor_id : [0][0][0][0]
encoder : AVC Coding
Stream #0:1[0x2](und): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, stereo, s16, 1536 kb/s (default)
Metadata:
creation_time : 2024-12-06T05:14:38.000000Z
handler_name : Sound Media Handler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](und): Data: none (rtmd / 0x646D7472), 23756 kb/s (default)
Metadata:
creation_time : 2024-12-06T05:14:38.000000Z
handler_name : Timed Metadata Media Handler
timecode : 09:17:10:36
The output shows the stream is AVC encoded for which the GTX1650 doesn’t support hardware acceleration.
That doesn’t really show the level of the bitstream, you can get that with ffprobe -show_streams C4639.MP4
However, looking at your output, I can see a couple of potential issues:
- the resolution is 3840x2160, which is less than the supported 4096x4096 pixels
- it uses the “High 4:2:2” profile, which is distinct from “High” (which uses 4:2:0 chroma subsampling) supported by NVDEC
- the stream far exceeds level 4.1 constraints:
- level 4.1 supports only 8192 macroblocks/frame, your 4K frames have (3840/16)*(2160/16) = 32,400 macroblocks
- … and only 245,760 macroblocks/s. Even ignoring the macroblock/frame limit, this would mean your framerate could not be higher than a little more than 7.5 frames/s (actually 245,760/32,400), while your stream is 100 fps
- … and it is limited to 50 Mbit/s or 50,000 kbit/s, which your stream also exceeds.
Are you sure about that? According to the NVDEC documentation from Nvidia, Turing (and in fact everything all the way back to Fermi) does indeed support H.264/AVC decoding.
I misread the NVDEC documentation. A Turing generation card should support up to level 5.1. However, the stream also exceeds that:
- level 5.1 supports 36,864 macroblocks/frame, your 4K frames have (3840/16)*(2160/16) = 32,400 macroblocks
- … and 983,040 macroblocks/s. With 32,400 macroblocks/frame, this means no more than a little over 30 fps, while your stream is 100fps.
- … bitrate is limited to 240,000 kbit/s, which your stream also exceeds.