项目重命名: ReelForge => Pixelle-Video
This commit is contained in:
52
pixelle_video/models/progress.py
Normal file
52
pixelle_video/models/progress.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
Progress event models for video generation
|
||||
|
||||
Provides structured progress events for UI layer to consume and translate.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class ProgressEvent:
|
||||
"""
|
||||
Structured progress event for video generation
|
||||
|
||||
Attributes:
|
||||
event_type: Type of event (e.g., "generating_narrations", "frame_step", "concatenating")
|
||||
progress: Progress value from 0.0 to 1.0
|
||||
frame_current: Current frame number (1-based, optional)
|
||||
frame_total: Total number of frames (optional)
|
||||
step: Current step within frame (1-4, optional)
|
||||
action: Action being performed (e.g., "audio", "image", "compose", "video", optional)
|
||||
|
||||
Examples:
|
||||
# Simple progress event
|
||||
ProgressEvent(event_type="generating_narrations", progress=0.05)
|
||||
|
||||
# Frame step event
|
||||
ProgressEvent(
|
||||
event_type="frame_step",
|
||||
progress=0.23,
|
||||
frame_current=1,
|
||||
frame_total=5,
|
||||
step=1,
|
||||
action="audio"
|
||||
)
|
||||
"""
|
||||
event_type: str
|
||||
progress: float
|
||||
|
||||
# Optional frame-related fields
|
||||
frame_current: Optional[int] = None
|
||||
frame_total: Optional[int] = None
|
||||
step: Optional[int] = None # 1-4 for frame processing steps
|
||||
action: Optional[str] = None # "audio", "image", "compose", "video"
|
||||
extra_info: Optional[str] = None # Additional information (e.g., batch progress)
|
||||
|
||||
def __post_init__(self):
|
||||
"""Validate progress value"""
|
||||
if not 0.0 <= self.progress <= 1.0:
|
||||
raise ValueError(f"Progress must be between 0.0 and 1.0, got {self.progress}")
|
||||
|
||||
126
pixelle_video/models/storyboard.py
Normal file
126
pixelle_video/models/storyboard.py
Normal file
@@ -0,0 +1,126 @@
|
||||
"""
|
||||
Storyboard data models for video generation
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class StoryboardConfig:
|
||||
"""Storyboard configuration parameters"""
|
||||
|
||||
# Task isolation
|
||||
task_id: Optional[str] = None # Task ID for file isolation (auto-generated if None)
|
||||
|
||||
n_storyboard: int = 5 # Number of storyboard frames
|
||||
min_narration_words: int = 5 # Min narration word count
|
||||
max_narration_words: int = 20 # Max narration word count
|
||||
min_image_prompt_words: int = 30 # Min image prompt word count
|
||||
max_image_prompt_words: int = 60 # Max image prompt word count
|
||||
|
||||
# Video parameters
|
||||
video_width: int = 1080 # Video width
|
||||
video_height: int = 1920 # Video height (9:16 portrait)
|
||||
video_fps: int = 30 # Frame rate
|
||||
|
||||
# Audio parameters
|
||||
voice_id: str = "[Chinese] zh-CN Yunjian" # Default voice
|
||||
tts_workflow: Optional[str] = None # TTS workflow filename (None = use default)
|
||||
tts_speed: float = 1.2 # TTS speed multiplier (1.0 = normal, >1.0 = faster)
|
||||
|
||||
# Image parameters
|
||||
image_width: int = 1024
|
||||
image_height: int = 1024
|
||||
image_workflow: Optional[str] = None # Image workflow filename (None = use default)
|
||||
|
||||
# Frame template
|
||||
frame_template: str = "default.html" # HTML template name or path (e.g., "default.html", "modern.html")
|
||||
|
||||
|
||||
@dataclass
|
||||
class StoryboardFrame:
|
||||
"""Single storyboard frame"""
|
||||
index: int # Frame index (0-based)
|
||||
narration: str # Narration text
|
||||
image_prompt: str # Image generation prompt
|
||||
|
||||
# Generated resource paths
|
||||
audio_path: Optional[str] = None # Audio file path
|
||||
image_path: Optional[str] = None # Original image path
|
||||
composed_image_path: Optional[str] = None # Composed image path (with subtitles)
|
||||
video_segment_path: Optional[str] = None # Video segment path
|
||||
|
||||
# Metadata
|
||||
duration: float = 0.0 # Audio duration (seconds)
|
||||
created_at: Optional[datetime] = None
|
||||
|
||||
def __post_init__(self):
|
||||
if self.created_at is None:
|
||||
self.created_at = datetime.now()
|
||||
|
||||
|
||||
@dataclass
|
||||
class ContentMetadata:
|
||||
"""Content metadata for visual display and narration generation"""
|
||||
title: str # Content title
|
||||
author: Optional[str] = None # Author/creator
|
||||
subtitle: Optional[str] = None # Subtitle
|
||||
genre: Optional[str] = None # Genre/category
|
||||
summary: Optional[str] = None # Content summary
|
||||
publication_year: Optional[str] = None # Publication year
|
||||
cover_url: Optional[str] = None # Cover/thumbnail image URL
|
||||
|
||||
|
||||
@dataclass
|
||||
class Storyboard:
|
||||
"""Complete storyboard"""
|
||||
title: str # Video title
|
||||
config: StoryboardConfig # Configuration
|
||||
frames: List[StoryboardFrame] = field(default_factory=list)
|
||||
|
||||
# Content metadata (optional)
|
||||
content_metadata: Optional[ContentMetadata] = None
|
||||
|
||||
# Final output
|
||||
final_video_path: Optional[str] = None
|
||||
total_duration: float = 0.0
|
||||
|
||||
# Metadata
|
||||
created_at: Optional[datetime] = None
|
||||
completed_at: Optional[datetime] = None
|
||||
|
||||
def __post_init__(self):
|
||||
if self.created_at is None:
|
||||
self.created_at = datetime.now()
|
||||
|
||||
@property
|
||||
def is_completed(self) -> bool:
|
||||
"""Check if all frames are processed"""
|
||||
return all(
|
||||
frame.video_segment_path is not None
|
||||
for frame in self.frames
|
||||
)
|
||||
|
||||
@property
|
||||
def progress(self) -> float:
|
||||
"""Return processing progress (0.0-1.0)"""
|
||||
if not self.frames:
|
||||
return 0.0
|
||||
completed = sum(
|
||||
1 for frame in self.frames
|
||||
if frame.video_segment_path is not None
|
||||
)
|
||||
return completed / len(self.frames)
|
||||
|
||||
|
||||
@dataclass
|
||||
class VideoGenerationResult:
|
||||
"""Video generation result"""
|
||||
video_path: str # Final video path
|
||||
storyboard: Storyboard # Complete storyboard
|
||||
duration: float # Total duration
|
||||
file_size: int # File size (bytes)
|
||||
created_at: datetime = field(default_factory=datetime.now)
|
||||
|
||||
Reference in New Issue
Block a user