Spaces:
Sleeping
Sleeping
Chandima Prabhath
Update Dockerfile to install FFmpeg and implement output directory cleanup in video encoding task
0388d92 | import os | |
| import logging | |
| import shutil | |
| from redis import from_url | |
| from ..config import RedisConfig | |
| from rq import Queue | |
| from pathlib import Path | |
| from typing import Optional | |
| from .ffmpeg import FFmpegEncoder | |
| from ..config import EncodingConfig | |
| logger = logging.getLogger(__name__) | |
| q = Queue(connection=RedisConfig.get_connection(), default_timeout=3600) | |
| def update_job_progress(job_id: str, progress: float): | |
| logger.info(f"Updating progress for job {job_id} to {progress}") | |
| RedisConfig.get_connection().hset(f"job:{job_id}", "progress", progress) | |
| def encode_video_task(job_id: str, input_path: str) -> Optional[str]: | |
| try: | |
| logger.info(f"Starting encoding for job {job_id}") | |
| output_dir = os.path.join(EncodingConfig.TEMP_DIR, job_id) | |
| encoder = FFmpegEncoder(input_path, output_dir) | |
| update_job_progress(job_id, 0.1) | |
| master_playlist = encoder.encode() | |
| update_job_progress(job_id, 1.0) | |
| logger.info(f"Encoding completed for job {job_id}") | |
| return master_playlist | |
| except Exception as e: | |
| logger.error(f"Encoding failed for job {job_id}: {str(e)}") | |
| update_job_progress(job_id, -1.0) | |
| raise | |
| finally: | |
| # Cleanup temporary files after 1 hour | |
| shutil.rmtree(output_dir, ignore_errors=True) | |