Implementation:869413421 Ai moive studio VisualIdentityService batch generate keyframes
| Knowledge Sources | |
|---|---|
| Domains | Vision, Generative_AI |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Service that batch-generates keyframe images for shots using relay-based visual continuity, with scene-level grouping, independent database sessions per scene, and previous-keyframe reference chaining.
Description
VisualIdentityService.batch_generate_keyframes implements the relay-based visual continuity pattern. Shots are grouped by scene; scenes are processed concurrently (up to 3), but shots within each scene are processed sequentially so the previous keyframe can serve as a reference for the next shot.
Each scene uses an independent database session (get_async_db()) to avoid connection conflicts. The KeyframePromptBuilder.build_prompt constructs the prompt with previous shot context, and retry_with_backoff wraps the GatewayProvider.generate_image call. Results are committed after each shot for partial progress recovery.
Usage
Import when generating keyframe images with visual continuity. Called by the movie generation pipeline after scene image generation.
Code Reference
Source Location
- Repository: ai-moive-studio
- File: backend/src/services/visual_identity_service.py:L237-385
Signature
class VisualIdentityService(BaseService):
async def batch_generate_keyframes(
self,
script_id: str,
api_key_id: str,
model: Optional[str] = None
) -> dict:
"""
Args:
script_id: script UUID
api_key_id: API key UUID
model: image model name
Returns:
Dict with total, success, failed, message
"""
Import
from src.services.visual_identity_service import VisualIdentityService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| script_id | str | Yes | Script UUID |
| api_key_id | str | Yes | API key UUID |
| model | str | No | Image model name |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | dict | {total, success, failed, message} |
| DB side effects | — | Updates MovieShot.keyframe_url |
Usage Examples
Batch Keyframe Generation
from src.services.visual_identity_service import VisualIdentityService
service = VisualIdentityService(db_session)
result = await service.batch_generate_keyframes(
script_id="script-uuid",
api_key_id="key-uuid",
model="gemini-3-pro-image-preview",
)
print(f"Keyframes: {result['success']}/{result['total']}")
Related Pages
Implements Principle
- Principle:869413421_Ai_moive_studio_Visual_Identity_Continuity
- Principle:869413421_Ai_moive_studio_AI_Image_Generation