Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:869413421 Ai moive studio VideoCompositionService synthesize sentence video

From Leeroopedia
Knowledge Sources
Domains Video, Multimedia
Last Updated 2026-10-23 12:00 GMT

Overview

Service that composes a single sentence video by downloading image and audio from MinIO, generating subtitle timelines, and executing an FFmpeg command.

Description

VideoCompositionService.synthesize_sentence_video creates a per-sentence video segment. It: (1) creates a sentence-specific working directory, (2) downloads the sentence's image and audio from MinIO, (3) generates a subtitle timeline from the audio duration and sentence content, (4) optionally corrects subtitle timing with an LLM, (5) builds an FFmpeg command combining the image (looped), audio, and subtitle filter, and (6) executes the FFmpeg command.

The result is an MP4 file at temp_dir/sentence_NNN/video.mp4.

Usage

Import when building per-sentence video segments for narrative video generation. Called by VideoSynthesisService.synthesize_video for each sentence.

Code Reference

Source Location

  • Repository: ai-moive-studio
  • File: backend/src/services/video_composition_service.py:L28-103

Signature

class VideoCompositionService:
    async def synthesize_sentence_video(
        self,
        sentence: Sentence,
        temp_dir: Path,
        index: int,
        gen_setting: dict,
        api_key: Optional[APIKey] = None,
        model: Optional[str] = None
    ) -> Path:
        """
        Args:
            sentence: Sentence object with image_url, audio_url, content
            temp_dir: temporary working directory
            index: sentence index for file naming
            gen_setting: video generation settings (subtitle style, etc.)
            api_key: optional API key for LLM subtitle correction
            model: optional LLM model for correction

        Returns:
            Path to generated MP4 video file
        """

Import

from src.services.video_composition_service import video_composition_service

I/O Contract

Inputs

Name Type Required Description
sentence Sentence Yes Sentence with image_url and audio_url
temp_dir Path Yes Temporary working directory
index int Yes Sentence index for file naming
gen_setting dict Yes Video generation settings (subtitle style)
api_key APIKey No For LLM subtitle correction
model str No LLM model for correction

Outputs

Name Type Description
return value Path Path to generated MP4 file

Usage Examples

Composing a Sentence Video

from src.services.video_composition_service import video_composition_service
from pathlib import Path

temp_dir = Path("/tmp/video_synthesis")
video_path = await video_composition_service.synthesize_sentence_video(
    sentence=sentence_obj,
    temp_dir=temp_dir,
    index=0,
    gen_setting={"subtitle_font_size": 24},
    api_key=api_key,  # optional LLM correction
    model="gpt-4o",
)
print(f"Video saved to: {video_path}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment