Skip to main content

Crate rave_nvcodec

Crate rave_nvcodec 

Source
Expand description

Crates.io docs.rs License: MIT

§rave-nvcodec

NVDEC/NVENC hardware codec wrappers for RAVE.

rave-nvcodec implements GPU decode and encode stages over NVIDIA Video Codec SDK APIs with CUDA-device-pointer based frame flow.

§Scope

  • NVDEC decode wrapper (NvDecoder) implementing FrameDecoder
  • NVENC encode wrapper (NvEncoder) implementing FrameEncoder
  • Encoder configuration (NvEncConfig)
  • Raw FFI bindings for CUDA Video Codec SDK (sys module)

§Public API Highlights

  • NvDecoder::new(ctx, source, codec)
  • NvEncoder::new(cuda_context, sink, config)
  • NvEncConfig for resolution/fps/bitrate/GOP/B-frame/pitch settings

§Typical Usage

use std::sync::Arc;

use rave_core::codec_traits::{BitstreamSink, BitstreamSource};
use rave_core::context::GpuContext;
use rave_core::error::Result;
use rave_core::ffi_types::cudaVideoCodec;
use rave_nvcodec::nvdec::NvDecoder;

fn make_decoder(ctx: Arc<GpuContext>, source: Box<dyn BitstreamSource>) -> Result<NvDecoder> {
    NvDecoder::new(ctx, source, cudaVideoCodec::HEVC)
}

§Runtime Requirements

  • NVIDIA driver libraries (libcuda, libnvcuvid, libnvidia-encode)
  • Compatible CUDA toolkit + Video Codec SDK runtime
  • Linux/WSL link search paths must include locations for NVIDIA driver libs

§Notes

  • Decode output and encode input are GPU-resident NV12 frames.
  • Encode path caches resource registration by device pointer to avoid per-frame registration overhead.
  • This crate performs FFI-heavy work; all unsafe boundaries are isolated in codec modules and sys.

§Stub mode

When the rave_nvcodec_stub cfg is active (set by build.rs when the NVIDIA Video Codec SDK headers or libraries are not found), the nvdec and nvenc modules are replaced with stubs that return EngineError::Decode / EngineError::Encode immediately. This allows the workspace to build and run tests on CI runners without a GPU or NVIDIA drivers installed.

Modules§

config
Shared encoder configuration types used by both the real and stub NVENC backends.
nvdec
CPU-only stub for builds without NVDEC/NVENC system dependencies.
nvenc
CPU-only stub for builds without NVDEC/NVENC system dependencies.
sys
Raw FFI bindings to NVIDIA Video Codec SDK (nvcuvid + nvEncodeAPI).