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.2-cp314-cp314-win_amd64.whl (43.4 MB view details)

Uploaded CPython 3.14Windows x86-64

nelux-0.9.2-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.2-cp314-cp314-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.14macOS 12.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

nelux-0.9.2-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.2-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.2-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: nelux-0.9.2-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.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ca26f47afac1b255bb891b40d7087ea06b8e54cc55782531b8fe3daf82a393b2
MD5 69278a530a45f925921d07bb5c34fd4f
BLAKE2b-256 d0c41e6c30695a0ea3d11fe92660cc42e3bac3bcf121b37ff2cd54800ed0ae75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.9.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 493536df6c59ccbf3002e89ce53d69b5245483cd6a79a03d954b3db9da7805dd
MD5 3d9fe4abe40d7b72d5413b0ac5b9a416
BLAKE2b-256 f30f8cb5608e2309680da18b7c7aa685454e04efb4dc772902972f2ed65c4962

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.9.2-cp314-cp314-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 fd54c17873f296665dc898d28dc1dca1fcdb81d59c8d1890c2440edaa505e666
MD5 b113e5def260fc8924ffd2eab8448ab0
BLAKE2b-256 70d13d8d263fef1b6c641c60c5febf15aa8c48437a9a3fd58c0a073d840f7e2c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nelux-0.9.2-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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 bd624940ac53a8ed922d000ef6e8db2885d4978bd9519f4b5e92ff281347e304
MD5 dabb83df043b2087f35a62d90995a262
BLAKE2b-256 cd11c4effd7ce016d6e377dabb77449d39379cabe15763d010587ccb93cddb32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.9.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 142eb318ad33c7c78114ce8deac9bfa9718d95e000e5e1d167c8a64995bd3762
MD5 4b1e265794962abab25bf7e80a5b9e17
BLAKE2b-256 8dd3037ab1851cefb9b693be21c865a0592611d884c08245e2601c472abdb2a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.9.2-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 4bc0e06f312e87f4b80a2db9fdbc6198a1fdbe3e574d823b4bbe09ac03580c61
MD5 d0052fc1a75f069313f505b3550ed456
BLAKE2b-256 e1c6a89ec43f86c245816440a2405a7537131a19d07d31fab0afd9cc78d86121

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