File size: 2,528 Bytes
8b4f8f9
 
 
f7bd5c7
ca7cbe1
f7bd5c7
ca7cbe1
 
f7bd5c7
 
 
8b4f8f9
21b1e7f
 
0410763
 
 
 
f7bd5c7
 
 
 
 
 
 
 
 
ca7cbe1
 
 
 
 
 
 
 
f7bd5c7
ca7cbe1
8b4f8f9
ca7cbe1
8b4f8f9
 
 
 
 
 
 
 
 
 
 
 
ca7cbe1
8b4f8f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca7cbe1
8b4f8f9
 
 
 
 
ca7cbe1
8b4f8f9
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
from typing import List, Dict

import os
from redis import from_url, RedisError
from dotenv import load_dotenv
import time
import logging

load_dotenv()

class EncodingConfig:
    DEBUG = os.getenv("DEBUG", "True") == "True"
    TEMP_DIR = "/tmp"
    LOG_LEVEL = logging.DEBUG if DEBUG else logging.INFO

logging.basicConfig(level=EncodingConfig.LOG_LEVEL)
logger = logging.getLogger(__name__)

class RedisConfig:
    URL = os.getenv("REDIS_URL")
    CONN_POOL = None  # Will be initialized on first use
    QUEUE_NAME = "video_encoding_queue"

    @classmethod
    def get_connection(cls):
        if not cls.CONN_POOL:
            while True:
                try:
                    cls.CONN_POOL = from_url(cls.URL, max_connections=20, ssl_cert_reqs=None)
                    logger.info("Successfully connected to Redis")
                    break
                except RedisError as e:
                    logger.error(f"Could not connect to Redis instance: {e}. Retrying in 2 seconds...")
                    time.sleep(2)
        return cls.CONN_POOL

    HMAC_SECRET = os.getenv("VIDEO_HMAC_SECRET", "default-secret-change-me")

    RESOLUTIONS: List[Dict] = [
        {
            "name": "1080p",
            "width": 1920,
            "height": 1080,
            "video_bitrate": "5000k",
            "audio_bitrate": "128k",
            "codec": "libx264",
            "profile": "high",
            "preset": "slow"
        },
        {
            "name": "720p",
            "width": 1280,
            "height": 720,
            "video_bitrate": "2500k",
            "audio_bitrate": "128k",
            "codec": "libx264",
            "profile": "main",
            "preset": "medium"
        },
        {
            "name": "480p",
            "width": 854,
            "height": 480,
            "video_bitrate": "1000k",
            "audio_bitrate": "96k",
            "codec": "libx264",
            "profile": "baseline",
            "preset": "fast"
        },
        {
            "name": "240p",
            "width": 426,
            "height": 240,
            "video_bitrate": "400k",
            "audio_bitrate": "64k",
            "codec": "libx264",
            "profile": "baseline",
            "preset": "veryfast"
        }
    ]

    @classmethod
    def validate_resolutions(cls):
        for res in cls.RESOLUTIONS:
            if not all(key in res for key in ['name', 'width', 'height', 'video_bitrate']):
                raise ValueError(f"Invalid resolution config: {res}")