A reusable Django app for integrating video processing capabilities to your video models
Project description
Contentor Video Processor
A Django app for programmatically creating different video resolutions, compressing videos, and reducing storage and bandwidth costs without sacrificing quality. Reduce video sizes dramatically (e.g., from 1GB to 100MB) while maintaining visual quality.
Features
- Chunk upload support for large video files (10GB+ files can be uploaded with proper settings)
- Automatic video compression and resolution conversion
- Support for multiple video resolutions (original, 720p, 480p, 360p)
- S3-compatible storage integration
- Chunked file uploads for large video files
- Webhook notifications for processing status updates
- Easy integration with your existing Django models
Installation
pip install django-contentor-video-processor
Quick Start
1. Add to INSTALLED_APPS
Add contentor_video_processor to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
# ...
'contentor_video_processor',
# ...
]
2. Configure Settings
Add the following to your settings.py:
# STORAGE SETTINGS
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_BUCKET_NAME")
AWS_S3_ENDPOINT_URL = os.getenv("AWS_ENDPOINT")
AWS_LOCATION = "customers/your-org/media"
# Remove hardcoded `MEDIA_URL` if you want signed URLs
AWS_DEFAULT_ACL = None
AWS_QUERYSTRING_AUTH = True # Enable signed URLs
AWS_S3_FILE_OVERWRITE = True
AWS_S3_OBJECT_PARAMETERS = {
"CacheControl": "max-age=3600", # Cache for 1 hour
}
ADMIN_RESUMABLE_CHUNK_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
ADMIN_RESUMABLE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
ADMIN_RESUMABLE_CHUNKSIZE = 52428800 # 50MB matching chunk size
# Contentor API credentials (get your free API key at https://contentor.app)
CONTENTOR_VIDEO_PROCESSING_ACCESS_KEY = os.getenv("CONTENTOR_VIDEO_PROCESSING_ACCESS_KEY", "")
CONTENTOR_VIDEO_PROCESSING_ACCESS_TOKEN = os.getenv("CONTENTOR_VIDEO_PROCESSING_ACCESS_TOKEN", "")
# Your application's base URL (needed for webhook notifications)
BASE_URL = "https://your-app-url.com"
# The app and model that will contain your videos
CONTENTOR_VIDEO_MODEL = "your_app.Video"
CONTENTOR_VIDEO_PROCESSING_REQUESTS_APP = "your_app"
CONTENTOR_PROCESSING_REQUEST_MODEL_VERBOSE_NAME = "Video Processing Request"
CONTENTOR_PROCESSING_REQUEST_MODEL_VERBOSE_NAME_PLURAL = "Video Processing Requests"
CONTENTOR_VIDEO_RESOLUTIONS = ["original", "720p", "480p", "360p"]
CONTENTOR_ORIGINAL_RESOLUTION = "1080p"
# Additional configuration options
CONTENTOR_VIDEO_PROCESSING_CONFIG = {
# contentor settings
"api_url": "https://process.contentor.app/api/process-video/",
"download_provider": "minio",
"upload_provider": "minio",
"original_resolution": "1080p",
"resolutions": ["original", "720p", "480p", "360p"],
# video quality settings
"crf": "30", # Compression quality (lower = better quality, higher file size)
"preset": "ultrafast", # Encoding speed preset
"optimise_for_web": True,
"output_file_format": "mp4" # Output format
}
3. Update URLs
Add the Contentor Video Processor URLs to your main urls.py:
from django.urls import include, path
urlpatterns = [
# ...
path("contentor-video/", include("contentor_video_processor.urls")),
# ...
]
4. Integrate with Your Models
Inherit from ContentorVideoModel and add a ContentorVideoField to your model:
from django.db import models
from contentor_video_processor.models import ContentorVideoModel
from contentor_video_processor.models import ContentorVideoField
class Video(ContentorVideoModel):
title = models.CharField(max_length=255)
description = models.TextField(blank=True)
# This field will store your video and handle processing
video = ContentorVideoField(
null=True,
blank=True,
upload_to="videos/original/",
)
# Add any other fields you need
5. Run Migrations
python manage.py makemigrations
python manage.py migrate
6. Collect Static Files
Ensure that STATICFILES_FINDERS includes AppDirectoriesFinder:
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
Then run:
python manage.py collectstatic
7. Use the Video Template
In your templates, use the provided video element to display your videos with all available resolutions:
{% include "contentor_video_processor/video_element.html" with video=your_video_object %}
Server Configuration
Nginx Configuration for Large File Uploads
When handling large video files, you may need to adjust your server timeout settings to avoid upload timeouts. Here's an example Nginx configuration:
location /contentor-video/upload {
proxy_pass http://app:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
}
Advanced Usage
Customizing Video Processing Options
You can customize the video processing options by modifying the CONTENTOR_VIDEO_PROCESSING_CONFIG in your settings:
CONTENTOR_VIDEO_PROCESSING_CONFIG = {
# ...
"crf": "23", # Better quality but larger file size
"preset": "medium", # Balance between encoding speed and compression
# ...
}
Webhook Notifications
The app can send notifications when video processing is complete. To enable this, make sure you have set either:
- The
BASE_URLsetting, which will construct a webhook URL automatically - A hardcoded webhook URL in your configuration
Troubleshooting
Upload Issues
- If you're experiencing timeouts during large file uploads, increase the timeout settings in your web server configuration.
- Ensure your S3-compatible storage is properly configured with the correct credentials.
Processing Issues
- Verify that your Contentor API credentials are correct.
- Check the Contentor dashboard for processing status and error messages.
- Ensure your webhook URL is accessible from the internet if you're expecting status updates.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
[License information] This project is licensed under the MIT License. See the LICENSE file for details.
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 django_contentor_video_processor-0.8.3.tar.gz.
File metadata
- Download URL: django_contentor_video_processor-0.8.3.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98d573600c7844df0aa8c3c9cd951d426638a90504600e37fdd2373dd1e70f71
|
|
| MD5 |
9fa20a8875aec354122434a4cbc90e4f
|
|
| BLAKE2b-256 |
10763eb9432ca87be93de8657c30f4a45c3c9e7de7186d7583ca9426bd3930d1
|
File details
Details for the file django_contentor_video_processor-0.8.3-py3-none-any.whl.
File metadata
- Download URL: django_contentor_video_processor-0.8.3-py3-none-any.whl
- Upload date:
- Size: 35.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2789d04f58be41fa3e730fd3aa9ec187a7fcd2fc05436bf880481d8e77597179
|
|
| MD5 |
64f0de334255598be8d7c8d89ba4b589
|
|
| BLAKE2b-256 |
bc745c4c81af58346aff29d05436d32d0e005ffa30d16ac586ae39150d96f50b
|