Skip to main content

Lightspeed video decoding directly into tensors!

Project description

Release and Benchmark Tests License PyPI Version PyPI - Downloads Python Versions Discord

NeLux

NeLux is a high-performance Python library for video processing, leveraging the power of FFmpeg with hardware acceleration (NVDEC/NVENC). It delivers some of the fastest decode times globally, enabling efficient video decoding directly into ML-ready PyTorch tensors.

Originall created by Trentonom0r3


Installation

pip install nelux

Supported platforms:

Platform Backends Notes
Windows x64 CPU + CUDA (NVDEC/NVENC) Requires FFmpeg DLLs on PATH (or pass to os.add_dll_directory).
Linux x86_64 (manylinux_2_28+) CPU + CUDA (NVDEC/NVENC) Install FFmpeg via apt install ffmpeg libavcodec62 libavformat62 libavutil60 libswscale9 libavfilter11 libavdevice62.
macOS arm64 (Apple Silicon, ≥ 12.0) CPU / MPS (via PyTorch) Install FFmpeg via brew install ffmpeg. No CUDA on macOS.

PyTorch must be importable before nelux — the package uses torch's C++ runtime. For CUDA builds, install the matching CUDA torch wheel:

# Linux CUDA
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu130

# macOS / Linux CPU
pip install torch torchvision

Quick Start

Basic Usage

from nelux import VideoReader

# Open video with hardware acceleration
reader = VideoReader("input.mp4", decode_accelerator="nvdec")

# Read frames - automatically BCHW format!
for frame in reader:
    print(frame.shape)   # [1, 3, 1080, 1920] - BCHW
    print(frame.dtype)   # torch.float16 for 8-bit videos
    
    # Ready for ML inference immediately
    output = model(frame)

Batch Frame Reading

from nelux import VideoReader

vr = VideoReader("video.mp4")

# Get specific frames
batch = vr.get_batch([0, 10, 20])           # [3, 3, H, W]
batch = vr.get_batch(range(0, 100, 10))     # [10, 3, H, W]

# Pythonic slice notation
batch = vr[0:100:10]                        # [10, 3, H, W]
single = vr[42]                             # Single frame

# Negative indexing
batch = vr[[-3, -2, -1]]                    # Last 3 frames

# Properties
print(len(vr))                              # Total frame count
print(vr.shape)                             # (frames, 3, H, W)

Video Encoding

from nelux import VideoReader

reader = VideoReader("input.mp4")

with reader.create_encoder("output.mp4") as enc:
    for frame in reader:
        enc.encode_frame(frame)

print("Done!")

Features

Core Features

  • Hardware Acceleration: NVDEC (decode) and NVENC (encode) support
  • ML-Ready Output: BCHW format with automatic dtype selection
    • FP16 for 8-bit videos (optimal for ML)
    • FP32 for 10/12/16-bit videos (higher precision)
  • Zero-Copy: Direct GPU tensor output, no CPU round-trip
  • Batch Decoding: Efficient multi-frame decoding with smart optimization

Performance Optimizations

  • Fused Operations: Color conversion + format change + normalization in single CUDA kernel
  • Smart Seeking: Minimizes seeks in batch operations (only seeks on backward jumps or large gaps)
  • Deduplication: Duplicate frame requests decoded once and shared
  • Asynchronous Decode: Non-blocking GPU operations with event-based synchronization

Supported Codecs & Formats

Feature Support
Video Codecs H.264, H.265/HEVC, VP9, AV1 (with NVDEC)
Pixel Formats NV12, P010, P016, YUV444 (8/10/12/16-bit)
Containers MP4, MKV, AVI, MOV, WebM

API Reference

VideoReader

VideoReader(
    file_path: str,
    num_threads: int = 4,
    force_8bit: bool = False,
    decode_accelerator: str = "cpu",  # "cpu" or "nvdec"
    cuda_device_index: int = 0
)

Properties:

  • shape: Tuple of (frames, 3, height, width)
  • frame_count: Total number of frames
  • fps: Frame rate
  • duration: Video duration in seconds
  • has_audio: Whether the source has an audio track

Methods:

  • get_batch(indices): Decode multiple frames efficiently
  • get_batch_range(start, end, step): Decode frame range
  • create_encoder(output_path): Create video encoder
  • __getitem__(index): Frame access via reader[42] or reader[0:100:10]

Documentation


Requirements

  • Python: 3.8+
  • PyTorch: 2.0+ (with CUDA support for GPU acceleration)
  • CUDA: 11.8+ (for NVDEC/NVENC)
  • OS: Windows 10/11, Linux (Ubuntu 20.04+)

Building from Source

git clone https://github.com/NevermindNilas/NeLux.git
cd NeLux

# Install dependencies
pip install -r requirements.txt

# Build (requires CMake, CUDA toolkit, FFmpeg)
python setup.py build_ext --inplace

See BUILD.md for detailed build instructions.


License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). See the LICENSE file for details.


Acknowledgments

  • FFmpeg: The backbone of video processing in NeLux
  • PyTorch: For tensor operations and CUDA integration
  • libyuv: For fast CPU color conversion
  • Contributors: Thanks to everyone who has contributed to NeLux!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nelux-0.9.1-cp314-cp314-win_amd64.whl (43.4 MB view details)

Uploaded CPython 3.14Windows x86-64

nelux-0.9.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

nelux-0.9.1-cp314-cp314-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.14macOS 12.0+ ARM64

nelux-0.9.1-cp313-cp313-win_amd64.whl (42.3 MB view details)

Uploaded CPython 3.13Windows x86-64

nelux-0.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

nelux-0.9.1-cp313-cp313-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 12.0+ ARM64

File details

Details for the file nelux-0.9.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: nelux-0.9.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 43.4 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nelux-0.9.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 54c52c93a21a8694600a400f03223f4735ac570f14b7c2da21c2e9664bdde65c
MD5 66ae4aa6c271becb354a00c4c7785bdc
BLAKE2b-256 6e35df5b3fe04743bbf7957f2193addf2cf4f5cf163cfed867f1be79027a7bc2

See more details on using hashes here.

File details

Details for the file nelux-0.9.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nelux-0.9.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 24dabe86e3a5d5ce0bc3fc5bc030173331b9db34d178d4f0a772a5f166be5245
MD5 7865b0a268a3f3b69430dc0c4d5156bf
BLAKE2b-256 b8c436db6e54047f911c03cb38f7b89f9a3ed4c5374c46820c32fbe799622a18

See more details on using hashes here.

File details

Details for the file nelux-0.9.1-cp314-cp314-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for nelux-0.9.1-cp314-cp314-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 d34d721162fc35b8570495ee201ce87d026906ba5179f93201f5f9865c0960a9
MD5 3d45423bf865abdb1a426594d87074d4
BLAKE2b-256 7d107dd472dce490707c49e76d9f18a75908cec596eb18531c1425e1f2e3074d

See more details on using hashes here.

File details

Details for the file nelux-0.9.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: nelux-0.9.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 42.3 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nelux-0.9.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3b478ba585725a95a62c7395982e6d7dc10842272378053234f52453ae1429f0
MD5 6a7c2f11e82c4b59d52ecd8c8e558c37
BLAKE2b-256 72092be5c5a85f74c39b7cbc6067a884d57cae25bb51322a2d29c8fb5368cd1b

See more details on using hashes here.

File details

Details for the file nelux-0.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nelux-0.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cb6ee6beb6bc13c46103517835df1aa2a066481994523ed3655d9a8555465634
MD5 80aad6744254d399f470e7b4309a1d68
BLAKE2b-256 9980d0cf27c1a95a0c60632906c950c568dd48d0eb0b6fe92a7fbcad6abeb9da

See more details on using hashes here.

File details

Details for the file nelux-0.9.1-cp313-cp313-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for nelux-0.9.1-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 17c101acafc672cb0301de87e67318fd109396241663772b2995d0f27b00d088
MD5 43ba93925ce3e54241fd22681c6f9306
BLAKE2b-256 a7d90adf686d19ce892ce92ec1aeb6355d487be806dfc5de1801f359e1d76298

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page