CoolFace
Apppublic

Hans-R-D/encoder-pipeline

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
config.py88 linesDownload Raw Back to video_encoder
1import os2from typing import List, Dict3 4import os5from redis import from_url, RedisError6from dotenv import load_dotenv7import time8import logging9 10load_dotenv()11 12class EncodingConfig:13    DEBUG = os.getenv("DEBUG", "True") == "True"14    TEMP_DIR = "/tmp"15    LOG_LEVEL = logging.DEBUG if DEBUG else logging.INFO16 17logging.basicConfig(level=EncodingConfig.LOG_LEVEL)18logger = logging.getLogger(__name__)19 20class RedisConfig:21    URL = os.getenv("REDIS_URL")22    CONN_POOL = None  # Will be initialized on first use23    QUEUE_NAME = "video_encoding_queue"24 25    @classmethod26    def get_connection(cls):27        if not cls.CONN_POOL:28            while True:29                try:30                    cls.CONN_POOL = from_url(cls.URL, max_connections=20, ssl_cert_reqs=None)31                    logger.info("Successfully connected to Redis")32                    break33                except RedisError as e:34                    logger.error(f"Could not connect to Redis instance: {e}. Retrying in 2 seconds...")35                    time.sleep(2)36        return cls.CONN_POOL37 38    HMAC_SECRET = os.getenv("VIDEO_HMAC_SECRET", "default-secret-change-me")39 40    RESOLUTIONS: List[Dict] = [41        {42            "name": "1080p",43            "width": 1920,44            "height": 1080,45            "video_bitrate": "5000k",46            "audio_bitrate": "128k",47            "codec": "libx264",48            "profile": "high",49            "preset": "slow"50        },51        {52            "name": "720p",53            "width": 1280,54            "height": 720,55            "video_bitrate": "2500k",56            "audio_bitrate": "128k",57            "codec": "libx264",58            "profile": "main",59            "preset": "medium"60        },61        {62            "name": "480p",63            "width": 854,64            "height": 480,65            "video_bitrate": "1000k",66            "audio_bitrate": "96k",67            "codec": "libx264",68            "profile": "baseline",69            "preset": "fast"70        },71        {72            "name": "240p",73            "width": 426,74            "height": 240,75            "video_bitrate": "400k",76            "audio_bitrate": "64k",77            "codec": "libx264",78            "profile": "baseline",79            "preset": "veryfast"80        }81    ]82 83    @classmethod84    def validate_resolutions(cls):85        for res in cls.RESOLUTIONS:86            if not all(key in res for key in ['name', 'width', 'height', 'video_bitrate']):87                raise ValueError(f"Invalid resolution config: {res}")88