video.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # Copyright (C) 2025 AIDC-AI
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """
  13. Video generation API schemas
  14. """
  15. from typing import Optional, Literal, Dict, Any
  16. from pydantic import BaseModel, Field
  17. class VideoGenerateRequest(BaseModel):
  18. """Video generation request"""
  19. # === Input ===
  20. text: str = Field(..., description="Source text for video generation")
  21. # === Processing Mode ===
  22. mode: Literal["generate", "fixed"] = Field(
  23. "generate",
  24. description="Processing mode: 'generate' (AI generates narrations) or 'fixed' (use text as-is)"
  25. )
  26. # === Optional Title ===
  27. title: Optional[str] = Field(None, description="Video title (auto-generated if not provided)")
  28. # === Basic Config ===
  29. n_scenes: Optional[int] = Field(5, ge=1, le=20, description="Number of scenes (only used in 'generate' mode, ignored in 'fixed' mode)")
  30. # === TTS Parameters ===
  31. tts_workflow: Optional[str] = Field(
  32. None,
  33. description="TTS workflow key (e.g., 'runninghub/tts_edge.json'). If not specified, uses default workflow from config."
  34. )
  35. ref_audio: Optional[str] = Field(
  36. None,
  37. description="Reference audio path for voice cloning (optional)"
  38. )
  39. voice_id: Optional[str] = Field(
  40. None,
  41. description="(Deprecated) TTS voice ID for legacy compatibility"
  42. )
  43. # === LLM Parameters ===
  44. min_narration_words: int = Field(5, ge=1, le=100, description="Min narration words")
  45. max_narration_words: int = Field(20, ge=1, le=200, description="Max narration words")
  46. min_image_prompt_words: int = Field(30, ge=10, le=100, description="Min image prompt words")
  47. max_image_prompt_words: int = Field(60, ge=10, le=200, description="Max image prompt words")
  48. # === Media Parameters ===
  49. # Note: media_width and media_height are auto-determined from template meta tags
  50. media_workflow: Optional[str] = Field(None, description="Custom media workflow (image or video)")
  51. # === Video Parameters ===
  52. video_fps: int = Field(30, ge=15, le=60, description="Video FPS")
  53. # === Frame Template (determines video size) ===
  54. frame_template: Optional[str] = Field(
  55. None,
  56. description="HTML template path with size (e.g., '1080x1920/default.html'). Video size is auto-determined from template."
  57. )
  58. # === Template Custom Parameters ===
  59. template_params: Optional[Dict[str, Any]] = Field(
  60. None,
  61. description="Custom template parameters (e.g., {'accent_color': '#ff0000', 'background': 'url'}). "
  62. "Available parameters depend on the template. Use GET /api/templates/{template_path}/params to discover them."
  63. )
  64. # === Image Style ===
  65. prompt_prefix: Optional[str] = Field(None, description="Image style prefix")
  66. # === BGM ===
  67. bgm_path: Optional[str] = Field(None, description="Background music path")
  68. bgm_volume: float = Field(0.3, ge=0.0, le=1.0, description="BGM volume (0.0-1.0)")
  69. class Config:
  70. json_schema_extra = {
  71. "example": {
  72. "text": "Atomic Habits teaches us that small changes compound over time to produce remarkable results.",
  73. "mode": "generate",
  74. "n_scenes": 5,
  75. "frame_template": "1080x1920/image_default.html",
  76. "template_params": {
  77. "accent_color": "#3498db",
  78. "background": "https://example.com/custom-bg.jpg"
  79. },
  80. "title": "The Power of Atomic Habits"
  81. }
  82. }
  83. class VideoGenerateResponse(BaseModel):
  84. """Video generation response (synchronous)"""
  85. success: bool = True
  86. message: str = "Success"
  87. video_url: str = Field(..., description="URL to access generated video")
  88. duration: float = Field(..., description="Video duration in seconds")
  89. file_size: int = Field(..., description="File size in bytes")
  90. class VideoGenerateAsyncResponse(BaseModel):
  91. """Video generation async response"""
  92. success: bool = True
  93. message: str = "Task created successfully"
  94. task_id: str = Field(..., description="Task ID for tracking progress")