HlsKit provides strong HLS video conversion features backed by ffmpeg. Prepare your mp4 files for streaming
Project description
HlsKit-Py
HlsKit-Py is the Python version of hlskit-rs, an asyncio-based video processing library for converting video bytes into HLS (HTTP Live Streaming) output. Built on top of pydantic and asyncio, it provides a fast, type-safe, and scalable interface for video transcoding tasks.
๐ฆ Installation
pip install hlskit-py
๐งฌ Dependencies
HlsKit-Py uses the following core dependencies:
pydanticโ for data validation and settings modeling.ruffโ for code linting and formatting.
๐คช Example
import asyncio
from hlskit_py import HlsVideoProcessingSettings, HlsVideoProcessor
async def process_videos():
input_path = "example/sample.mp4"
with open(input_path, "rb") as video_binary:
input_bytes = video_binary.read()
results = await HlsVideoProcessor.process_video(
input_bytes=input_bytes,
output_profiles=[
HlsVideoProcessingSettings(resolution=(1920, 1080), constant_rate_factor=28),
HlsVideoProcessingSettings(resolution=(1280, 720), constant_rate_factor=28),
HlsVideoProcessingSettings(resolution=(854, 480), constant_rate_factor=28),
],
)
# Do something with `results.output_profiles`
print(results)
if __name__ == "__main__":
asyncio.run(process_videos())
๐ Web API + S3 Integration
import boto3
import uuid
from fastapi import FastAPI, UploadFile, File
from hlskit_py import HlsVideoProcessor, HlsVideoProcessingSettings
app = FastAPI()
s3 = boto3.client("s3")
BUCKET_NAME = "your-s3-bucket"
@app.post("/upload")
async def upload_and_process_video(file: UploadFile = File(...)):
input_bytes = await file.read()
results = await HlsVideoProcessor.process_video(
input_bytes=input_bytes,
output_profiles=[
HlsVideoProcessingSettings(resolution=(1920, 1080), constant_rate_factor=28),
HlsVideoProcessingSettings(resolution=(1280, 720), constant_rate_factor=28),
HlsVideoProcessingSettings(resolution=(854, 480), constant_rate_factor=28),
],
)
uploaded_files = []
for profile in results.output_profiles:
for relative_path, content in profile.output_files.items():
key = f"{uuid.uuid4()}/{relative_path}"
s3.upload_fileobj(content, BUCKET_NAME, key)
uploaded_files.append(f"s3://{BUCKET_NAME}/{key}")
return {"message": "Upload successful", "files": uploaded_files}
๐ง Processing Flow (Mermaid Diagram)
flowchart TD
A[Input MP4 Bytes] --> B{For Each Resolution}
B -->|1080p| C1[Spawn ffmpeg Task]
B -->|720p| C2[Spawn ffmpeg Task]
B -->|480p| C3[Spawn ffmpeg Task]
C1 & C2 & C3 --> D[Generate .ts Segments & .m3u8 Playlists]
D --> E[Generate Master Playlist - master.m3u8 file]
E --> F[Return HlsVideo Struct]
๐ Project Structure
hlskit-py/
โโโ src/hlskit_py/
โ โโโ models/
โ โ โโโ hls_video_processing_settings.py
โ โ โโโ hls_video.py
โ โโโ services/
โ โ โโโ hls_video_processor.py
โ โโโ tools/
โ โโโ ffmpeg_command_builder.py
โ โโโ m3u8_tools.py
โโโ example/
โ โโโ example.py
โโโ README.md
โโโ CONTRIBUTING.md
โโโ LICENSE
โโโ pyproject.toml
๐ Future Goals
- Implement GStreamer backend.
- Add GPU encoding (NVIDIA/AMD) support.
๐ค Contributing
See CONTRIBUTING.md for contribution workflow, testing practices, coding style, and PR conventions.
๐ชช License
HlsKit is licensed under LGPLv3. By modifying or distributing it (e.g., via forks or extensions), you agree to the HlsKit Contributor License Agreement (CLA), which ensures our ecosystem thrives.
The 'HlsKit' name and logo are trademarks of Engels Tercero. Use in forks or derivatives requires written permission.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hlskit_py-0.1.3.tar.gz.
File metadata
- Download URL: hlskit_py-0.1.3.tar.gz
- Upload date:
- Size: 61.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af8b56249b4880503ace6f831205750b86f1d9a9ca185c46ced33a729f962b75
|
|
| MD5 |
07ef8364c4d720406615f96655f4999d
|
|
| BLAKE2b-256 |
97918b4511547cd28770e04dca29d9e65cfd660af1ee4e8eae5f207c0ffc65ad
|
File details
Details for the file hlskit_py-0.1.3-py3-none-any.whl.
File metadata
- Download URL: hlskit_py-0.1.3-py3-none-any.whl
- Upload date:
- Size: 34.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b51b5970253912449d7e616170bf36bed61137fb1ae1aff502bc45be5b7e0b64
|
|
| MD5 |
c8f6ceccf8033038ea495d3bd047bc8e
|
|
| BLAKE2b-256 |
a08870206edb94135d8e5eafe26e3670b78ce1f31a6b9c4f5f2fb626aa1409b1
|