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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 12.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

nelux-0.9.0-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.0-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.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: nelux-0.9.0-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.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 3c33ef77cb490e3de22a0f23e6d6b6c6efa6801103cc4eb3b4bcd91e71bc8aae
MD5 e5ad88a8145b67ea600f2aa352a3db9d
BLAKE2b-256 f032ff8bb9cc3ef6b83faa755e8f42db640f41a01b6ad66220534677e6e221bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.9.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d069c2d61b8567263e78ad87861c5fda63eeef3d25e0344556fcf3c0a3bb03a9
MD5 d346af43b1a7913352c6c00a4bda0af8
BLAKE2b-256 3720b59d038afb58cb900f80b191dde3176856fb00cebfa98c368b48a8b93bec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.9.0-cp314-cp314-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 bde3c1186fc3e6eaf3aa4f2ee31098f66556614b6b99fb265b08037839e20cec
MD5 1545f5a9111de531e34c25efc8487329
BLAKE2b-256 383dadbe32dd6cd06fa99ec5045aaa0026c31804c378de5572d76b3e5a510e1b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nelux-0.9.0-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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4efbfab4f6093902fe685c7e1d3a34e8b7bf53120bce845561f2eeb24483827e
MD5 76e5b2af00018985b7a30113cc97fc7d
BLAKE2b-256 5b58232efa9b51da9f8c8b8938b737713cdcef42a4ab8b3daa491facda08428e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.9.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ecf71a3ca8148a985855289f785adf13f821183be7efbcf4895db1f82dcb3532
MD5 a5d0da321d891bbc8011f71d878dbbc5
BLAKE2b-256 7f022539fb29029d2b7b6659f49b22f70a13452b2d3a5d2ca2c0109ce4ebcd47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.9.0-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 a8ee9242b8506353c894ea0e4d38cd5886dd561668404d3a86b7df4313b8de82
MD5 e1be30e623a69fc324ce0036cb0381d7
BLAKE2b-256 b94aa9b28efb8b459c3c622512744e038b0ab30d7012e445b0f1f32abc55c8b1

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