You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 58253b0
Browse filesBrowse the repository at this point in the historyBrowse files
perf: cut the processor time of hardware decoding on Windows (#326)
* perf: reuse the buffers of hardware-decoded frames in the media player
For every picture the hardware path dropped the system-memory frame the
picture was read back into, and allocated a new I420 frame for the
conversion. At 4K that is two fresh allocations of 12 MB per picture, and a
fresh allocation costs more to fault in than the copy into it.
The read-back frame now stays between pictures, with a new buffer only when
the size or the pixel format changes (the transfer copies no more than the
smaller of the two frames), and the I420 frames come from a buffer pool, so a
picture lands in memory that is already mapped. The conversion of other
formats in software uses the pool as well.
CPU cycles on the decoding thread per picture, on an NVIDIA GeForce RTX 3080
through Direct3D 11: the read-back went from 11.0 to 5.3 million at 4K and
from 3.3 to 1.8 million at 1080p, the conversion from 10.4 to 5.7 and from 2.2
to 1.3.
* perf: decode through Direct3D 12 first in the media player on Windows
FFmpeg 8.1 has Direct3D 12 hwaccels for H.264 and VP9. The Windows build now
enables them (h264_d3d12va, vp9_d3d12va), and the player tries a Direct3D 12
device before the Direct3D 11 one it used. A machine without Windows 10 2004
or a driver that decodes through Direct3D 12 has no such device, and goes on
with Direct3D 11 as before. The pictures are the same: every test of the
hardware path compares them with software decoding.
Reading a picture back is what costs processor time on this path, and
Direct3D 12 does it for about half of what Direct3D 11 does. Process CPU per
frame in the player on an NVIDIA GeForce RTX 3080, median of four runs of
steady playback, one machine and synthetic media:
software Direct3D 11 Direct3D 12
1080p H.264 3.6 ms 4.2 ms 2.1 ms
4K H.264 6.6 ms 12.4 ms 5.4 ms
Direct3D 11 used more processor time than software at 4K, Direct3D 12 less.
The component list changed, so the next build rebuilds FFmpeg on Windows.
The pictures are the same ones software decoding gives; in the tests, every frame of H.264 and VP9 media is compared with its software counterpart. Hardware decoding is off unless asked for.
224
224
225
-
-**Platforms:** macOS through VideoToolbox, Windows through Direct3D 11, and Linux through NVDEC on NVIDIA GPUs (x86-64 and ARM64; the driver provides `libcuda.so.1` and `libnvcuvid.so.1`, which are loaded when a player asks for hardware). The flag is accepted everywhere; where the platform has no hardware decoder, or the FFmpeg build has none for it (32-bit ARM, VA-API on Intel and AMD GPUs), the video is decoded in software, and `isHardwareDecoding()` says so.
225
+
-**Platforms:** macOS through VideoToolbox, Windows through Direct3D 12 (Windows 10 version 2004 or later, with a driver that decodes video through it) and otherwise Direct3D 11, and Linux through NVDEC on NVIDIA GPUs (x86-64 and ARM64; the driver provides `libcuda.so.1` and `libnvcuvid.so.1`, which are loaded when a player asks for hardware). The flag is accepted everywhere; where the platform has no hardware decoder, or the FFmpeg build has none for it (32-bit ARM, VA-API on Intel and AMD GPUs), the video is decoded in software, and `isHardwareDecoding()` says so.
226
226
-**Codecs:** H.264 and VP9. VP8, MPEG-4, MJPEG and H.265/HEVC are decoded in software.
227
227
-**Fallback:** a stream the hardware does not take, such as a profile it cannot decode, is decoded in software without the player noticing more than `isHardwareDecoding()` turning `false`. If the hardware fails after it has produced a picture, decoding goes on in software from the next key frame.
228
-
-**What it saves** is processor time, not the copy: a decoded picture is read back from the media engine into system memory, and converted to I420 as WebRTC wants it. On an Apple M2, a 1080p H.264 stream took 11.6 ms of processor time per frame in software and 1.4 ms in hardware, and a 4K stream 35.7 ms against 4.2 ms, about seven to eight times less. Per frame, software on all cores is faster on the clock, which does not matter at playback speed. These are figures for one machine and for synthetic media, not a promise.
228
+
-**What it saves** is processor time, not the copy: a decoded picture is read back from the media engine into system memory, and converted to I420 as WebRTC wants it. On an Apple M2, a 1080p H.264 stream took 11.6 ms of processor time per frame in software and 1.4 ms in hardware, and a 4K stream 35.7 ms against 4.2 ms, about seven to eight times less. Per frame, software on all cores is faster on the clock, which does not matter at playback speed. Windows gains less: on an NVIDIA GeForce RTX 3080 through Direct3D 12, a 1080p H.264 stream took about 2.1 ms of processor time per frame against 3.6 ms in software, and a 4K stream 5.4 ms against 6.6 ms. Direct3D 11 reads the picture back more slowly and took more than software at 4K (12.4 ms), which is why Direct3D 12 comes first. These are figures for one machine each and for synthetic media, not a promise; try it on your own streams before relying on it.
0 commit comments