Spaces:
Sleeping
Sleeping
| # START OF video_generator.py | |
| import os | |
| import tempfile | |
| import shutil | |
| from typing import List, Dict | |
| class VideoGenerator: | |
| """A simplified and safe video generator.""" | |
| def __init__(self): | |
| self.temp_dir = tempfile.mkdtemp() | |
| def create_synchronized_video(self, audio_path: str, word_timestamps: List[Dict], | |
| text: str, style_config: Dict, output_filename: str) -> str: | |
| """ | |
| This is a fallback function. Instead of creating a video, | |
| it copies the audio file to a .m4a format to indicate a processed file. | |
| This avoids using ffmpeg and external fonts, which can cause errors. | |
| """ | |
| try: | |
| # The safest operation is to just provide the audio back in a different format | |
| output_path = os.path.join(self.temp_dir, output_filename.replace('.mp4', '.m4a')) | |
| shutil.copy2(audio_path, output_path) | |
| print(f"Fallback successful: Created audio file at {output_path}") | |
| return output_path | |
| except Exception as e: | |
| print(f"Critical error in fallback video generation: {e}") | |
| raise | |
| def __del__(self): | |
| if hasattr(self, 'temp_dir') and os.path.exists(self.temp_dir): | |
| shutil.rmtree(self.temp_dir, ignore_errors=True) | |
| # END OF video_generator.py |