Professional video processing pipeline with computer vision analysis, 360ยฐ processing, adaptive streaming, and AI-powered transcription (msprites2)
Project description
๐ฌ Video Processor
A Modern Python Library for Professional Video Processing
Extracted from the demostar Django application, now a standalone powerhouse for video encoding, thumbnail generation, and sprite creation.
๐ LATEST: v0.4.0 - Complete Multimedia Platform!
๐ญ Computer Vision Analysis โข ๐ฅ AV1/HEVC/HDR โข ๐ก Adaptive Streaming โข ๐ 360ยฐ Video Processing โข โ Production Ready
๐ Full Documentation โข ๐ Features โข โก Quick Start โข ๐ป Examples โข ๐ Upgrade
๐ Documentation
Complete Documentation Suite Available in docs/
| Documentation | Description |
|---|---|
| ๐ User Guide | Complete getting started guides and feature overviews |
| ๐ Migration | Upgrade instructions and migration guides |
| ๐ ๏ธ Development | Technical implementation details and architecture |
| ๐ Reference | API references, roadmaps, and feature lists |
| ๐ป Examples | 11 comprehensive examples covering all features |
Quick Links
- ๐ NEW_FEATURES_v0.4.0.md - Complete v0.4.0 feature overview
- ๐ README_v0.4.0.md - Comprehensive getting started guide
- ๐ MIGRATION_GUIDE_v0.4.0.md - Upgrade instructions
- ๐ป Examples Documentation - Hands-on usage examples
โจ Features
๐ฅ Video Encoding
|
๐ผ๏ธ Thumbnails & Sprites
|
โก Background Processing
|
๐ ๏ธ Modern Development
|
๐ 360ยฐ Video Support (Optional)
|
|
๐ฆ Installation
Quick Install
# Basic installation (standard video processing)
uv add video-processor
# With 360ยฐ video support
uv add "video-processor[video-360]"
# With spatial audio processing
uv add "video-processor[spatial-audio]"
# Complete 360ยฐ feature set
uv add "video-processor[video-360-full]"
# Or using pip
pip install video-processor
pip install "video-processor[video-360-full]"
Optional Features
๐ 360ยฐ Video Processing
For immersive video processing capabilities:
video-360: Core 360ยฐ video processing (py360convert, opencv, numpy, scipy)spatial-audio: Spatial audio processing (librosa, soundfile)metadata-360: Enhanced 360ยฐ metadata extraction (exifread)video-360-full: Complete 360ยฐ package (includes all above)
๐ฆ Dependency Details
# Core 360ยฐ processing
uv add "video-processor[video-360]"
# Includes: py360convert, opencv-python, numpy, scipy
# Spatial audio support
uv add "video-processor[spatial-audio]"
# Includes: librosa, soundfile
# Complete 360ยฐ experience
uv add "video-processor[video-360-full]"
# Includes: All 360ยฐ dependencies + exifread
โก Procrastinate Migration (2.x โ 3.x)
This library supports both Procrastinate 2.x and 3.x for smooth migration:
๐ Automatic Version Detection
from video_processor.tasks.compat import get_version_info, IS_PROCRASTINATE_3_PLUS
version_info = get_version_info()
print(f"Using Procrastinate {version_info['procrastinate_version']}")
print(f"Features available: {list(version_info['features'].keys())}")
# Version-aware setup
if IS_PROCRASTINATE_3_PLUS:
# Use 3.x features like improved performance, graceful shutdown
pass
๐ Migration Steps
-
Install compatible version:
uv add "procrastinate>=3.5.2,<4.0.0" # Or keep 2.x support: ">=2.15.1,<4.0.0"
-
Apply database migrations:
# Procrastinate 3.x (two-step process) procrastinate schema --apply --mode=pre # Before deploying # Deploy new code procrastinate schema --apply --mode=post # After deploying # Procrastinate 2.x (single step) procrastinate schema --apply
-
Use migration helper:
from video_processor.tasks.migration import migrate_database # Automatic version-aware migration success = await migrate_database("postgresql://localhost/mydb")
-
Update worker configuration:
from video_processor.tasks import get_worker_kwargs # Automatically normalizes options for your version worker_options = get_worker_kwargs( concurrency=4, timeout=5, # Maps to fetch_job_polling_interval in 3.x remove_error=True, # Maps to remove_failed in 3.x )
๐ Procrastinate 3.x Benefits
- Better performance with improved job fetching
- Graceful shutdown with
shutdown_graceful_timeout - Enhanced error handling and job cancellation
- Schema compatibility improvements (3.5.2+)
Development Setup
git clone <repository>
cd video_processor
# Install with all development dependencies
uv sync --dev
# Install with dev + 360ยฐ features
uv sync --dev --extra video-360-full
# Verify installation
uv run pytest
๐ Quick Start
Basic Video Processing
from pathlib import Path
from video_processor import VideoProcessor, ProcessorConfig
# ๐ Configure your processor
config = ProcessorConfig(
base_path=Path("/tmp/video_output"),
output_formats=["mp4", "webm"],
quality_preset="high" # ๐ฏ Professional quality
)
# ๐ฌ Initialize and process
processor = VideoProcessor(config)
result = processor.process_video(
input_path="input_video.mp4",
output_dir="outputs"
)
# ๐ Results
print(f"๐ฅ Video ID: {result.video_id}")
print(f"๐ Formats: {list(result.encoded_files.keys())}")
print(f"๐ผ๏ธ Thumbnail: {result.thumbnail_file}")
print(f"๐๏ธ Sprites: {result.sprite_files}")
Async Background Processing
import asyncio
from video_processor.tasks import setup_procrastinate
async def process_in_background():
# ๐๏ธ Connect to PostgreSQL
app = setup_procrastinate("postgresql://user:pass@localhost/db")
# ๐ค Submit job
job = await app.tasks.process_video_async.defer_async(
input_path="/path/to/video.mp4",
output_dir="/path/to/output",
config_dict={"quality_preset": "ultra"}
)
print(f"โ
Job queued: {job.id}")
asyncio.run(process_in_background())
โ๏ธ Configuration
Quality Presets Comparison
| ๐ฏ Preset | ๐บ Video Bitrate | ๐ Audio Bitrate | ๐จ CRF | ๐ก Best For |
|---|---|---|---|---|
| Low | 1,000k | 128k | 28 | ๐ฑ Mobile, limited bandwidth |
| Medium | 2,500k | 192k | 23 | ๐ Standard web delivery |
| High | 5,000k | 256k | 18 | ๐ฌ High-quality streaming |
| Ultra | 10,000k | 320k | 15 | ๐๏ธ Archive, professional use |
Advanced Configuration
from video_processor import ProcessorConfig
from pathlib import Path
config = ProcessorConfig(
# ๐ Storage & Paths
base_path=Path("/media/videos"),
storage_backend="local", # ๐ฎ S3 coming soon!
# ๐ฅ Video Settings
output_formats=["mp4", "webm", "ogv"],
quality_preset="ultra",
# ๐ผ๏ธ Thumbnails & Sprites
thumbnail_timestamp=30, # ๐ 30 seconds in
sprite_interval=5.0, # ๐๏ธ Every 5 seconds
# ๐ ๏ธ System
ffmpeg_path="/usr/local/bin/ffmpeg" # ๐ง Custom FFmpeg
)
๐งช Testing
๐ฏ NEW in v0.3.0: Comprehensive Test Infrastructure
Video Processor now includes a world-class testing framework with 108+ video fixtures and perfect test compatibility!
โก Quick Testing
# Run all tests
make test
# Unit tests only (fast)
uv run pytest tests/unit/
# Integration tests with Docker
make test-docker
# Test specific categories
uv run pytest -m "smoke" # Quick smoke tests
uv run pytest -m "edge_cases" # Edge case scenarios
uv run pytest -m "codecs" # Codec compatibility
๐ฌ Test Video Fixtures
Our comprehensive test suite includes:
- Edge Cases: Single frame videos, unusual resolutions (16x16, 1920x2), extreme aspect ratios
- Multiple Codecs: H.264, H.265, VP8, VP9, Theora, MPEG4 with various profiles
- Audio Variations: Mono/stereo, different sample rates, no audio, audio-only files
- Visual Patterns: SMPTE bars, RGB test patterns, YUV test, checkerboard patterns
- Motion Tests: Rotation, camera shake, scene changes, complex motion
- Stress Tests: High complexity scenes, noise patterns, encoding challenges
๐ Test Results
โ
52 passing tests (0 failures!)
โ
108+ test video fixtures
โ
Complete Docker integration
โ
Perfect API compatibility
๐ณ Docker Integration Testing
# Complete integration testing environment
make test-docker
# Test specific services
make test-db-migration # Database migration testing
make test-worker # Procrastinate worker testing
make clean-docker # Clean up test environment
๐ง Advanced Testing
# Generate/update test video fixtures
uv run python tests/fixtures/test_suite_manager.py --setup
# Validate test suite integrity
uv run python tests/fixtures/test_suite_manager.py --validate
# Generate synthetic videos for edge cases
uv run python tests/fixtures/generate_synthetic_videos.py
# Download open source test videos
uv run python tests/fixtures/download_test_videos.py
๐จ Test Categories
| Category | Description | Video Count |
|---|---|---|
| smoke | Quick validation tests | 2 videos |
| basic | Standard functionality | 5 videos |
| codecs | Format compatibility | 9 videos |
| edge_cases | Boundary conditions | 12+ videos |
| stress | Performance testing | 2+ videos |
| full | Complete test suite | 108+ videos |
๐ก Examples
Explore our comprehensive examples in the examples/ directory:
๐ Available Examples
| Example | Description | Features |
|---|---|---|
basic_usage.py |
๐ฏ Simple synchronous processing | Configuration, encoding, thumbnails |
async_processing.py |
โก Background task processing | Procrastinate, job queuing, monitoring |
custom_config.py |
๐ ๏ธ Advanced configuration scenarios | Quality presets, validation, custom paths |
docker_demo.py |
๐ณ Complete containerized demo | Docker, PostgreSQL, async workers |
web_demo.py |
๐ Flask web interface | Browser-based processing, job submission |
๐ณ Docker Quick Start
Get up and running in seconds with our complete Docker environment:
# Start all services (PostgreSQL, Redis, app, workers)
docker-compose up -d
# View logs from the demo application
docker-compose logs -f app
# Access web demo at http://localhost:8080
docker-compose up demo
# Run tests in Docker
docker-compose run test
# Clean up
docker-compose down -v
Services included:
- ๐๏ธ PostgreSQL - Database with Procrastinate job queue
- ๐ฌ App - Main video processor demo
- โก Worker - Background job processor
- ๐งช Test - Automated testing environment
- ๐ Demo - Web interface for browser-based testing
๐ฌ Real-World Usage Patterns
๐ข Production Video Pipeline
# Multi-format encoding for video platform
config = ProcessorConfig(
base_path=Path("/var/media/uploads"),
output_formats=["mp4", "webm"], # Cross-browser support
quality_preset="high",
sprite_interval=10.0 # Balanced performance
)
processor = VideoProcessor(config)
result = processor.process_video(user_upload, output_dir)
# Generate multiple qualities
for quality in ["medium", "high"]:
config.quality_preset = quality
processor = VideoProcessor(config)
# Process to different quality folders...
๐ฑ Mobile-Optimized Processing
# Lightweight encoding for mobile delivery
mobile_config = ProcessorConfig(
base_path=Path("/tmp/mobile_videos"),
output_formats=["mp4"], # Mobile-friendly format
quality_preset="low", # Reduced bandwidth
sprite_interval=15.0 # Fewer sprites
)
๐ API Reference
๐ฌ VideoProcessor
The main orchestrator for all video processing operations.
๐ง Methods
# Process video to all configured formats
result = processor.process_video(
input_path: Path | str,
output_dir: Path | str | None = None,
video_id: str | None = None
) -> VideoProcessingResult
# Encode to specific format
output_path = processor.encode_video(
input_path: Path,
output_dir: Path,
format_name: str,
video_id: str
) -> Path
# Generate thumbnail at timestamp
thumbnail = processor.generate_thumbnail(
video_path: Path,
output_dir: Path,
timestamp: int,
video_id: str
) -> Path
# Create sprite sheet and WebVTT
sprites = processor.generate_sprites(
video_path: Path,
output_dir: Path,
video_id: str
) -> tuple[Path, Path]
โ๏ธ ProcessorConfig
Type-safe configuration with automatic validation.
๐ Essential Fields
class ProcessorConfig:
base_path: Path # ๐ Base directory
output_formats: list[str] # ๐ฅ Video formats
quality_preset: str # ๐ฏ Quality level
storage_backend: str # ๐พ Storage type
ffmpeg_path: str # ๐ ๏ธ FFmpeg binary
thumbnail_timestamp: int # ๐ผ๏ธ Thumbnail position
sprite_interval: float # ๐๏ธ Sprite frequency
๐ VideoProcessingResult
Comprehensive result object with all output information.
@dataclass
class VideoProcessingResult:
video_id: str # ๐ Unique identifier
encoded_files: dict[str, Path] # ๐ Format โ file mapping
thumbnail_file: Path | None # ๐ผ๏ธ Thumbnail image
sprite_files: tuple[Path, Path] | None # ๐๏ธ Sprite + WebVTT
metadata: VideoMetadata # ๐ Video properties
๐งช Development
๐ ๏ธ Development Commands
# ๐ฆ Install dependencies
uv sync
# ๐งช Run test suite
uv run pytest -v
# ๐ Test coverage
uv run pytest --cov=video_processor
# โจ Code formatting
uv run ruff format .
# ๐ Linting
uv run ruff check .
# ๐ฏ Type checking
uv run mypy src/
๐ Test Coverage
Our comprehensive test suite covers:
- โ Configuration validation and type checking
- โ Path utilities and file operations
- โ FFmpeg integration and error handling
- โ Video metadata extraction
- โ Background task processing
- โ Procrastinate compatibility (2.x/3.x versions)
- โ Database migrations with version detection
- โ Worker configuration and option mapping
- โ 360ยฐ video processing (when dependencies available)
========================== test session starts ==========================
tests/test_config.py โ
โ
โ
โ
โ
[15%]
tests/test_utils.py โ
โ
โ
โ
โ
โ
โ
โ
[30%]
tests/test_procrastinate_compat.py โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
[85%]
tests/test_procrastinate_migration.py โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
โ
[100%]
======================== 43 passed in 0.52s ========================
๐ฆ Dependencies
๐ฏ Core Dependencies
| Package | Purpose | Why We Use It |
|---|---|---|
ffmpeg-python |
FFmpeg integration | ๐ฌ Professional video processing |
msprites2 |
Sprite generation | ๐๏ธ Seekbar thumbnails (forked for fixes) |
procrastinate |
Background tasks | โก Scalable async processing |
pydantic |
Configuration | โ๏ธ Type-safe settings validation |
pillow |
Image processing | ๐ผ๏ธ Thumbnail manipulation |
๐ง Development Tools
| Tool | Purpose | Benefits |
|---|---|---|
uv |
Package management | ๐ Ultra-fast dependency resolution |
ruff |
Linting & formatting | โก Lightning-fast code quality |
pytest |
Testing framework | ๐งช Reliable test execution |
mypy |
Type checking | ๐ฏ Static type analysis |
coverage |
Test coverage | ๐ Quality assurance |
๐ Why Video Processor?
๐ Comparison with Alternatives
| Feature | Video Processor | FFmpeg CLI | moviepy | OpenCV |
|---|---|---|---|---|
| Two-pass encoding | โ | โ | โ | โ |
| Multiple formats | โ | โ | โ | โ |
| Background processing | โ | โ | โ | โ |
| Type safety | โ | โ | โ | โ |
| Sprite generation | โ | โ | โ | โ |
| Modern Python | โ | N/A | โ | โ |
๐ Requirements
๐ฅ๏ธ System Requirements
- Python 3.11+ - Modern Python features
- FFmpeg - Video processing engine
- PostgreSQL - Background job processing (optional)
๐ง Installation Commands
# Ubuntu/Debian
sudo apt install ffmpeg postgresql-client
# macOS
brew install ffmpeg postgresql
# Arch Linux
sudo pacman -S ffmpeg postgresql
๐ค Contributing
We welcome contributions! Here's how to get started:
๐ Quick Contribution Guide
- ๐ด Fork the repository
- ๐ฟ Create a feature branch (
git checkout -b feature/amazing-feature) - ๐ Make your changes with tests
- ๐งช Test everything (
uv run pytest) - โจ Format code (
uv run ruff format .) - ๐ค Submit a pull request
๐ฏ Areas We'd Love Help With
- ๐ S3 storage backend implementation
- ๐๏ธ Additional video formats (AV1, HEVC)
- ๐ Progress tracking and monitoring
- ๐ณ Docker integration examples
- ๐ Documentation improvements
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Changelog
๐ v0.2.0 - Procrastinate 3.x Migration & Docker Support
- ๐ Procrastinate 3.x compatibility with backward support for 2.x
- ๐ฏ Automatic version detection and feature flagging
- ๐ Database migration utilities with pre/post migration support
- ๐ณ Complete Docker environment with multi-service orchestration
- ๐ Web demo interface with Flask-based UI
- โก Worker compatibility layer with unified CLI
- ๐งช 30+ comprehensive tests covering all compatibility scenarios
- ๐ uv caching optimization following Docker best practices
๐ v0.1.0 - Initial Release
- โจ Multi-format encoding: MP4, WebM, OGV support
- ๐ผ๏ธ Thumbnail generation with customizable timestamps
- ๐๏ธ Sprite sheet creation with WebVTT files
- โก Background processing with Procrastinate integration
- โ๏ธ Type-safe configuration with Pydantic V2
- ๐ ๏ธ Modern tooling: uv, ruff, pytest integration
- ๐ Comprehensive documentation and examples
๐ Migration to v0.4.0
Upgrading from Previous Versions
Video Processor v0.4.0 maintains 100% backward compatibility while adding powerful new features:
# Your existing code continues to work unchanged
processor = VideoProcessor(config)
result = await processor.process_video("video.mp4", "./output/")
# But now you get additional features automatically:
if result.is_360_video:
print(f"360ยฐ projection: {result.video_360.projection_type}")
if result.quality_analysis:
print(f"Quality score: {result.quality_analysis.overall_quality:.1f}/10")
New Features Available
- ๐ญ Computer Vision Analysis: Automatic scene detection and quality assessment
- ๐ฅ Modern Codecs: AV1, HEVC, and HDR support
- ๐ก Streaming: HLS and DASH adaptive streaming
- ๐ 360ยฐ Processing: Complete immersive video pipeline
Migration Resources
- ๐ Complete Migration Guide - Step-by-step upgrade instructions
- ๐ New Features Overview - What's new in v0.4.0
- ๐ป Updated Examples - New capabilities in action
๐โโ๏ธ Questions? Issues? Ideas?
Found a bug? Open an issue
Have a feature request? Start a discussion
Want to contribute? Check out our contribution guide
Built with โค๏ธ for the video processing community
Making professional video encoding accessible to everyone
Project details
Release history Release notifications | RSS feed
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 advanced_video_processor-0.6.0.tar.gz.
File metadata
- Download URL: advanced_video_processor-0.6.0.tar.gz
- Upload date:
- Size: 278.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4e088985835f3ce4cdc658308ed6089d44385aab2ef99d3cbbb525a970ed5c4
|
|
| MD5 |
478545b1989b9ff1a086d29fd73ea37d
|
|
| BLAKE2b-256 |
62330e164608059a3dfe92188e4883971597fe564198d8164056c2b61c704185
|
File details
Details for the file advanced_video_processor-0.6.0-py3-none-any.whl.
File metadata
- Download URL: advanced_video_processor-0.6.0-py3-none-any.whl
- Upload date:
- Size: 173.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b1c6c9ecaaecae2e162a989b631a9800772236c2932b8f5ecb0b276c63a808c
|
|
| MD5 |
de553aa86bf8662a68776bee9703ba7c
|
|
| BLAKE2b-256 |
bf495780dec6421151937f773db618b7bff62093caa196d01c40f528b88bd65c
|