Implementation:869413421 Ai moive studio VideoSynthesisService synthesize video
| Knowledge Sources | |
|---|---|
| Domains | Video, Multimedia |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Service that orchestrates the full video synthesis pipeline: material validation, per-sentence video composition with caching, crossfade concatenation, speed adjustment, BGM mixing, and MinIO upload.
Description
VideoSynthesisService.synthesize_video is the main orchestrator for the Picture Narrative Pipeline's final stage. It manages the entire video task lifecycle through a state machine: VALIDATING → DOWNLOADING_MATERIALS → SYNTHESIZING_VIDEOS → CONCATENATING → UPLOADING → completed.
Key features:
- Caching: Sentences with valid cached video segments (has_valid_cache()) are reused; only uncached sentences are freshly composed
- Concurrent composition: Uncached sentences are composed concurrently (semaphore limit 3) with optional LLM subtitle correction
- Crossfade concatenation: Per-sentence videos are concatenated with crossfade transitions (0.5s fade)
- Speed adjustment: Optional video speed multiplier applied after concatenation
- BGM mixing: Optional background music mixed at configurable volume with loop
- Upload and completion tracking: Final video uploaded to MinIO, task marked completed with video key and duration
Usage
Import when synthesizing the final video from a chapter's sentences. Called by the content generation Celery task.
Code Reference
Source Location
- Repository: ai-moive-studio
- File: backend/src/services/video_synthesis.py:L329-647
Signature
class VideoSynthesisService(BaseService):
async def synthesize_video(self, video_task_id: str) -> dict:
"""
Args:
video_task_id: video task UUID
Returns:
Dict with total, success, failed, video_key, duration
"""
Import
from src.services.video_synthesis import VideoSynthesisService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| video_task_id | str | Yes | Video task UUID |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | dict | {total, success, failed, video_key, duration} |
| DB side effects | — | Updates VideoTask status, progress, video_key, duration; uploads final MP4 to MinIO |
Usage Examples
Synthesizing a Chapter Video
from src.services.video_synthesis import VideoSynthesisService
service = VideoSynthesisService(db_session)
result = await service.synthesize_video(video_task_id="task-uuid")
print(f"Video: {result['video_key']}, Duration: {result['duration']}s")