Files
One-KVM/libs/hwcodec
mofeng-git 2f60e61dd5 perf(video): 消除中间帧复制并优化 MJPEG 有界预取
通过 Bytes 所有权和只读 AVBufferRef 引用池化 NV12 输入,消除中间 AVFrame 的整帧复制,并保留 V4L2 编码包脱离硬件缓冲的处理。

允许输出健康时有界预取 MJPEG,在输出背压时优先解码前丢帧;增加等帧、输出等待、丢帧原因及编码分段耗时统计,提供预取和所有权输入的对照开关。

补充缓冲寿命、只读保护、软件编码回退和队列策略测试及接口说明,保留现有 PTS、解码 worker、音频和加密行为。
2026-10-01 22:39:04 +08:00
..
2026-07-14 21:01:47 +08:00

A real-time hardware codec library for RustDesk based on FFmpeg

Codec

Windows

GPU FFmpeg ram FFmpeg vram sdk vram
intel encode qsv qsv Y
intel decode d3d11 d3d11 Y
nvidia encode nvenc(nv12->d3d11) nvenc(d3d11) Y
nvidia decode d3d11 d3d11 N
amd encode amf amf Y
amd decode d3d11 d3d11 Y

Notes

  • The reason for discarding the codecs using Cucontext is discussed in the following forum thread: https://forums.developer.nvidia.com/t/cuctxdestroy-causing-system-freeze-and-black-screen/290542/1. Based on the information above, there are several optimizations and changes made to the codec:

    • FFmpeg encoding AV_PIX_FMT_NV12 directly: The codec is modified to transfer AV_PIX_FMT_NV12 to AV_PIX_FMT_D3D11. This is done because FFmpeg doesn't use Cucontext if the device type is AV_HWDEVICE_TYPE_D3D11VA.
    • FFmpeg decoding with AV_HWDEVICE_TYPE_CUDA acceleration: This functionality is disabled and replaced with AV_HWDEVICE_TYPE_D3D11VA. The decoding process now utilizes D3D11VA acceleration instead of CUDA.
    • SDK decoding with CUDA acceleration: The CUDA acceleration support is disabled.
  • amd sdk remove h265 support, https://github.com/GPUOpen-LibrariesAndSDKs/AMF/issues/432

Linux

GPU FFmpeg ram
intel encode vaapi
intel decode vaapi
nvidia encode vaapi, nvnec
nvidia decode vaapi, nvdec
amd encode vaapi, amf
amd decode vaapi

Issue

Owned NV12 input

The bytes feature provides Encoder::encode_owned_bytes for packed NV12 input to FFmpeg V4L2 M2M encoders. It holds a Bytes owner in a read-only AVBufferRef until FFmpeg releases its last reference, instead of copying the input into an intermediate AVFrame. Other encoders retain the existing copy path. Converted or stride-compacted One-KVM input also retains that path.

ONE_KVM_V4L2_OWNED_INPUT=0 disables this optimization when the encoder is created, allowing comparisons with the same binary. ONE_KVM_VIDEO_STATS=1 enables preparation, send-frame, receive-packet, callback and output-copy timings. One-KVM reports them in [VideoInputPerf] at five-second intervals; copied_bytes counts only the intermediate raw-input copy, not FFmpeg's remaining copy into V4L2 MMAP buffers. Encoded packet detachment remains in place to avoid retaining scarce V4L2 capture buffers in downstream caches.

System requirements