返回 Pixelle-Video
media.py
根目录 / pixelle_video / models / media.py
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 """
14 Media generation result models
15 """
16
17 from typing import Literal, Optional
18 from pydantic import BaseModel, Field
19
20
21 class MediaResult(BaseModel):
22 """
23 Media generation result from workflow execution
24
25 Supports both image and video outputs from ComfyUI workflows.
26 The media_type indicates what kind of media was generated.
27
28 Attributes:
29 media_type: Type of media generated ("image" or "video")
30 url: URL or path to the generated media
31 duration: Duration in seconds (only for video, None for image)
32
33 Examples:
34 # Image result
35 MediaResult(media_type="image", url="http://example.com/image.png")
36
37 # Video result
38 MediaResult(media_type="video", url="http://example.com/video.mp4", duration=5.2)
39 """
40
41 media_type: Literal["image", "video"] = Field(
42 description="Type of generated media"
43 )
44 url: str = Field(
45 description="URL or path to the generated media file"
46 )
47 duration: Optional[float] = Field(
48 None,
49 description="Duration in seconds (only applicable for video)"
50 )
51
52 @property
53 def is_image(self) -> bool:
54 """Check if this is an image result"""
55 return self.media_type == "image"
56
57 @property
58 def is_video(self) -> bool:
59 """Check if this is a video result"""
60 return self.media_type == "video"
61
62
62 lines PYTHON