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

Uploaded CPython 3.14Windows x86-64

nelux-0.10.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.9 MB view details)

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

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

Uploaded CPython 3.14macOS 12.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

nelux-0.10.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.9 MB view details)

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

nelux-0.10.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.10.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: nelux-0.10.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.10.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 d6b3a380abd4b03537649c7dc6731bade0799e47fb3e55d2b70595495d11028b
MD5 9fd260359c0452364c12ae776edbe7dd
BLAKE2b-256 38f5411e081b3374c05ba0d0ebce47cdf05e3faad91d5af307df31e059582df1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.10.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9fd37d6acb33d4b88c34c8e6cd56997b763a2485ed3ae23580acede4a4635771
MD5 212bcef52736723fda4d02251c358ca2
BLAKE2b-256 85b67cca90a8c5ede4829ef94dd0871e6b3c16896daa3a33a6d47ab83c932b4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.10.0-cp314-cp314-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 bc09c08fa54eef6e4fb85c4f25ff4c33e871c6883a28fda588f46140c2452bcb
MD5 4abf1ce9b50dd9a9e611af0e9bc4e92a
BLAKE2b-256 b3870e4f09dd694c87708431eedd821b0690dfabd28ffc9db63983aa134ccff9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nelux-0.10.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.10.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d0dee73747e586a3143ed8938dfc20fdc85f4e462854489e8a7ae2f6e497d2cc
MD5 a040c5a5198d582c4448041a9c751635
BLAKE2b-256 5289ce482cc6886d1369bf7af4a680e7c86fbd9255d63b86aeaacfed6f9bc0d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.10.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 db5da78ed7c8c8578dca73310bff3c7073b22bab8b4e75ff75f6f9fa981d2370
MD5 61522686299c85893ef968f376188f2c
BLAKE2b-256 e24f45f065deeacc6224b9b3dfe130d6e544a685ea75fb7411b0068d778e1c2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nelux-0.10.0-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 b02255eebe40e36d6fbab794338b873aa71bc32b5b68d21dbd700464d349a1a2
MD5 c7ecad4964025614c405d465f8a8c138
BLAKE2b-256 458f1479044ecfaa9b2c2db322a04a9ec823b05d0269e627641ef3f7707a8af2

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