timelapse.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Schemas for timelapse video processing."""
  2. from pydantic import BaseModel, Field
  3. class TimelapseInfoResponse(BaseModel):
  4. """Video metadata response."""
  5. duration: float = Field(description="Video duration in seconds")
  6. width: int = Field(description="Video width in pixels")
  7. height: int = Field(description="Video height in pixels")
  8. fps: float = Field(description="Frames per second")
  9. codec: str = Field(description="Video codec name")
  10. file_size: int = Field(description="File size in bytes")
  11. has_audio: bool = Field(description="Whether video has audio track")
  12. class ThumbnailResponse(BaseModel):
  13. """Timeline thumbnail response."""
  14. thumbnails: list[str] = Field(description="Base64 encoded JPEG thumbnails")
  15. timestamps: list[float] = Field(description="Timestamp for each thumbnail in seconds")
  16. class TimelapseJobResponse(BaseModel):
  17. """A timelapse re-encode job."""
  18. status: str = Field(description="running, completed, failed or cancelled")
  19. progress: float | None = Field(default=None, description="Share done, 0.0 to 1.0; null before the first report")
  20. output_path: str | None = Field(default=None, description="Relative path to the output file, once completed")
  21. message: str | None = Field(default=None, description="Result message, once completed")
  22. error: str | None = Field(default=None, description="Why it failed")
  23. @classmethod
  24. def from_job(cls, job) -> "TimelapseJobResponse":
  25. return cls(
  26. status=job.status,
  27. progress=job.progress,
  28. output_path=job.output_path,
  29. message=job.message,
  30. error=job.error,
  31. )