CeLux: High-performance video processing for Python, powered by FFmpeg and PyTorch. Ultra-fast video decoding directly to tensors with CPU and CUDA support.
AGPL-3.0 License
CeLux is a high-performance Python library for video processing, leveraging the power of FFmpeg. It delivers some of the fastest decode times for full HD videos globally, enabling efficient and seamless video decoding directly into PyTorch tensors.
The name CeLux is derived from the Latin words celer
(speed) and lux
(light), reflecting its commitment to speed and efficiency.
uint8
, float32
, or float16
data types.CeLux offers two installation options tailored to your system's capabilities:
Install the CPU version of CeLux using pip
:
pip install celux
Note: The CPU version only supports CPU operations. Attempting to use GPU features with this version will result in an error.
Install the CUDA version of CeLux using pip
:
pip install celux-cuda
Note: The CUDA version requires a CUDA-capable GPU and the corresponding Torch-Cuda installation.
celux
Regardless of the installation choice, both packages are imported using the same module name:
import celux #as cx
This design ensures a seamless transition between CPU and CUDA versions without changing your import statements.
Here's a simple example demonstrating how to use CeLux to read video frames and process them:
import celux as cx
def process_frame(frame):
# Implement your frame processing logic here
pass
# Choose device based on your installation
device = "cuda" if torch.cuda.is_available() else "cpu"
with cx.VideoReader(
"path/to/input/video.mp4",
device=device, # "cpu" or "cuda"
dtype="uint8" # Options: "uint8", "float32", "float16"
) as reader:
for frame in reader:
# Frame is a PyTorch tensor in HWC format
process_frame(frame)
Parameters:
device
(str): Device to use. Can be "cpu"
or "cuda"
.dtype
(str): Data type of the output frames ("uint8"
, "float32"
, or "float16"
).Note: If you set dtype
to "float"
or "half"
, the frame values will be normalized between 0.0
and 1.0
.
CeLux allows you to efficiently decode and process video frames with ease. Below are some common operations:
reader = cx.VideoReader(
"path/to/video.mp4",
device="cuda", # Use "cpu" or "cuda"
dtype="float32", # Data type: "uint8", "float32", "float16"
frame_range=[10, 20] # Optional: Read frames 10 to 20
)
for frame in reader:
# Your processing logic
pass
properties = reader.get_properties()
print(properties)
While CeLux is easily installable via pip
, you might want to build it from source for customization or contributing purposes.
Clone the Repository:
git clone https://github.com/Trentonom0r3/celux.git
cd celux
Install Dependencies:
Ensure all prerequisites are installed. You can use vcpkg
for managing dependencies on Windows.
Configure the Project with CMake:
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
Windows Users: If using Vcpkg, include the toolchain file:
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=<path_to_vcpkg>/scripts/buildsystems/vcpkg.cmake
Build the Project:
cmake --build build --config Release
Install the Package:
cmake --install build
Set Up Environment Variables:
Ensure FFmpeg binaries and other dependencies are in your system's PATH
. On Unix systems, you might need to set LD_LIBRARY_PATH
or DYLD_LIBRARY_PATH
.
We welcome contributions! Follow these steps to contribute:
Fork the Repository:
Click the "Fork" button at the top right of the repository page.
Clone Your Fork:
git clone https://github.com/your-username/celux.git
cd celux
Create a New Branch:
git checkout -b feature/your-feature-name
Make Your Changes:
Implement your feature or bugfix.
Commit Your Changes:
git commit -am "Add your commit message here"
Push to Your Fork:
git push origin feature/your-feature-name
Submit a Pull Request:
Go to the original repository and click on "Pull Requests," then "New Pull Request."
ffmpy
to CeLux
.pypi
release.cpu
and cuda
backends.Numpy
support in favor of PyTorch
tensors with GPU/CPU support.NV12ToBGR
, BGRToNV12
, and NV12ToNV12
conversion modules.Fixed several minor issues.
Made VideoReader
and VideoWriter
callable.
Created BGR conversion modules.
Added frame range (in/out) arguments.
with VideoReader('input.mp4')([10, 20]) as reader:
for frame in reader:
print(f"Processing frame {frame}")
.pyi
stub files to .whl
.dtype
arguments to (uint8
, float32
, float16
).has_audio
property to VideoReader.get_properties()
.uint8
, float
, half
).This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). See the LICENSE file for details.
A: Yes, you can set device="cpu"
when initializing VideoReader
. However, decoding performance will be significantly slower compared to GPU-accelerated decoding.
A: CeLux aims to support all video formats and codecs supported by FFmpeg. However, hardware-accelerated decoding is currently available for specific codecs like H.264 and HEVC. These are the only codecs tested so far.
A: Please open an issue on the GitHub Issues page with detailed information about the bug or feature request.
Audio Processing:
Performance Enhancements:
Cross-Platform Support:
Support for Additional Codecs: