更改视频尺寸的定义方式
This commit is contained in:
@@ -18,6 +18,8 @@ from pathlib import Path
|
||||
from html2image import Html2Image
|
||||
from loguru import logger
|
||||
|
||||
from pixelle_video.utils.template_util import parse_template_size
|
||||
|
||||
|
||||
class HTMLFrameGenerator:
|
||||
"""
|
||||
@@ -41,13 +43,17 @@ class HTMLFrameGenerator:
|
||||
Initialize HTML frame generator
|
||||
|
||||
Args:
|
||||
template_path: Path to HTML template file
|
||||
template_path: Path to HTML template file (e.g., "templates/1080x1920/default.html")
|
||||
"""
|
||||
self.template_path = template_path
|
||||
self.template = self._load_template(template_path)
|
||||
|
||||
# Parse video size from template path
|
||||
self.width, self.height = parse_template_size(template_path)
|
||||
|
||||
self.hti = None # Lazy init to avoid overhead
|
||||
self._check_linux_dependencies()
|
||||
logger.debug(f"Loaded HTML template: {template_path}")
|
||||
logger.debug(f"Loaded HTML template: {template_path} (size: {self.width}x{self.height})")
|
||||
|
||||
def _check_linux_dependencies(self):
|
||||
"""Check Linux system dependencies and warn if missing"""
|
||||
@@ -197,20 +203,18 @@ class HTMLFrameGenerator:
|
||||
text: str,
|
||||
image: str,
|
||||
ext: Optional[Dict[str, Any]] = None,
|
||||
width: int = 1080,
|
||||
height: int = 1920,
|
||||
output_path: Optional[str] = None
|
||||
) -> str:
|
||||
"""
|
||||
Generate frame from HTML template
|
||||
|
||||
Video size is automatically determined from template path during initialization.
|
||||
|
||||
Args:
|
||||
title: Video title
|
||||
text: Narration text for this frame
|
||||
image: Path to AI-generated image (supports relative path, absolute path, or HTTP URL)
|
||||
ext: Additional data (content_title, content_author, etc.)
|
||||
width: Frame width in pixels
|
||||
height: Frame height in pixels
|
||||
output_path: Custom output path (auto-generated if None)
|
||||
|
||||
Returns:
|
||||
@@ -266,11 +270,11 @@ class HTMLFrameGenerator:
|
||||
output_filename = os.path.basename(output_path)
|
||||
output_dir = os.path.dirname(output_path)
|
||||
|
||||
# Ensure Html2Image is initialized
|
||||
self._ensure_hti(width, height)
|
||||
# Ensure Html2Image is initialized with template's size
|
||||
self._ensure_hti(self.width, self.height)
|
||||
|
||||
# Render HTML to image
|
||||
logger.debug(f"Rendering HTML template to {output_path}")
|
||||
logger.debug(f"Rendering HTML template to {output_path} (size: {self.width}x{self.height})")
|
||||
try:
|
||||
self.hti.screenshot(
|
||||
html_str=html,
|
||||
|
||||
@@ -197,21 +197,10 @@ class FrameProcessor:
|
||||
) -> str:
|
||||
"""Compose frame using HTML template"""
|
||||
from pixelle_video.services.frame_html import HTMLFrameGenerator
|
||||
from pathlib import Path
|
||||
from pixelle_video.utils.template_util import resolve_template_path
|
||||
|
||||
# Resolve template path
|
||||
template_filename = config.frame_template
|
||||
|
||||
# Try templates/ directory first
|
||||
template_path = Path(f"templates/{template_filename}")
|
||||
if not template_path.exists():
|
||||
# Try as absolute/relative path
|
||||
template_path = Path(template_filename)
|
||||
if not template_path.exists():
|
||||
raise FileNotFoundError(
|
||||
f"Template not found: {template_filename}. "
|
||||
f"Built-in templates: default.html, modern.html, neon.html"
|
||||
)
|
||||
# Resolve template path (handles various input formats)
|
||||
template_path = resolve_template_path(config.frame_template)
|
||||
|
||||
# Get content metadata from storyboard
|
||||
content_metadata = storyboard.content_metadata if storyboard else None
|
||||
@@ -224,15 +213,13 @@ class FrameProcessor:
|
||||
ext["content_subtitle"] = content_metadata.subtitle or ""
|
||||
ext["content_genre"] = content_metadata.genre or ""
|
||||
|
||||
# Generate frame using HTML
|
||||
generator = HTMLFrameGenerator(str(template_path))
|
||||
# Generate frame using HTML (size is auto-parsed from template path)
|
||||
generator = HTMLFrameGenerator(template_path)
|
||||
composed_path = await generator.generate_frame(
|
||||
title=storyboard.title,
|
||||
text=frame.narration,
|
||||
image=frame.image_path,
|
||||
ext=ext,
|
||||
width=config.video_width,
|
||||
height=config.video_height,
|
||||
output_path=output_path
|
||||
)
|
||||
|
||||
|
||||
@@ -72,11 +72,9 @@ class VideoGeneratorService:
|
||||
image_workflow: Optional[str] = None,
|
||||
|
||||
# === Video Parameters ===
|
||||
video_width: int = 1080,
|
||||
video_height: int = 1920,
|
||||
video_fps: int = 30,
|
||||
|
||||
# === Frame Template ===
|
||||
# === Frame Template (determines video size) ===
|
||||
frame_template: Optional[str] = None,
|
||||
|
||||
# === Image Style ===
|
||||
@@ -128,12 +126,11 @@ class VideoGeneratorService:
|
||||
image_height: Generated image height (default 1024)
|
||||
image_workflow: Image workflow filename (e.g., "image_flux.json", None = use default)
|
||||
|
||||
video_width: Final video width (default 1080)
|
||||
video_height: Final video height (default 1920)
|
||||
video_fps: Video frame rate (default 30)
|
||||
|
||||
frame_template: HTML template filename or path (None = use default template)
|
||||
e.g., "default.html", "modern.html", "neon.html", or custom path
|
||||
frame_template: HTML template path with size (None = use default "1080x1920/default.html")
|
||||
Format: "SIZExSIZE/template.html" (e.g., "1080x1920/default.html", "1920x1080/modern.html")
|
||||
Video size is automatically determined from template path
|
||||
|
||||
prompt_prefix: Image prompt prefix (overrides config.yaml if provided)
|
||||
e.g., "anime style, vibrant colors" or "" for no prefix
|
||||
@@ -220,8 +217,6 @@ class VideoGeneratorService:
|
||||
max_narration_words=max_narration_words,
|
||||
min_image_prompt_words=min_image_prompt_words,
|
||||
max_image_prompt_words=max_image_prompt_words,
|
||||
video_width=video_width,
|
||||
video_height=video_height,
|
||||
video_fps=video_fps,
|
||||
voice_id=voice_id,
|
||||
tts_workflow=tts_workflow,
|
||||
@@ -230,7 +225,7 @@ class VideoGeneratorService:
|
||||
image_width=image_width,
|
||||
image_height=image_height,
|
||||
image_workflow=image_workflow,
|
||||
frame_template=frame_template or "default.html"
|
||||
frame_template=frame_template or "1080x1920/default.html"
|
||||
)
|
||||
|
||||
# Create storyboard
|
||||
|
||||
Reference in New Issue
Block a user