magic_hour 0.35.0__py3-none-any.whl → 0.36.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of magic_hour might be problematic. Click here for more details.
- magic_hour/README.md +35 -0
- magic_hour/core/base_client.py +6 -5
- magic_hour/core/query.py +12 -6
- magic_hour/core/request.py +3 -3
- magic_hour/core/response.py +18 -14
- magic_hour/core/utils.py +3 -3
- magic_hour/environment.py +1 -1
- magic_hour/helpers/__init__.py +3 -0
- magic_hour/helpers/download.py +75 -0
- magic_hour/resources/v1/README.md +33 -0
- magic_hour/resources/v1/ai_clothes_changer/README.md +73 -0
- magic_hour/resources/v1/ai_clothes_changer/client.py +146 -0
- magic_hour/resources/v1/ai_face_editor/README.md +110 -0
- magic_hour/resources/v1/ai_face_editor/client.py +168 -0
- magic_hour/resources/v1/ai_gif_generator/README.md +59 -0
- magic_hour/resources/v1/ai_gif_generator/client.py +119 -0
- magic_hour/resources/v1/ai_headshot_generator/README.md +60 -0
- magic_hour/resources/v1/ai_headshot_generator/client.py +140 -0
- magic_hour/resources/v1/ai_image_editor/README.md +64 -0
- magic_hour/resources/v1/ai_image_editor/client.py +136 -0
- magic_hour/resources/v1/ai_image_generator/README.md +66 -0
- magic_hour/resources/v1/ai_image_generator/client.py +139 -0
- magic_hour/resources/v1/ai_image_upscaler/README.md +67 -0
- magic_hour/resources/v1/ai_image_upscaler/client.py +150 -0
- magic_hour/resources/v1/ai_meme_generator/README.md +71 -0
- magic_hour/resources/v1/ai_meme_generator/client.py +127 -0
- magic_hour/resources/v1/ai_photo_editor/README.md +98 -7
- magic_hour/resources/v1/ai_photo_editor/client.py +174 -0
- magic_hour/resources/v1/ai_qr_code_generator/README.md +63 -0
- magic_hour/resources/v1/ai_qr_code_generator/client.py +123 -0
- magic_hour/resources/v1/ai_talking_photo/README.md +74 -0
- magic_hour/resources/v1/ai_talking_photo/client.py +170 -0
- magic_hour/resources/v1/animation/README.md +100 -0
- magic_hour/resources/v1/animation/client.py +218 -0
- magic_hour/resources/v1/auto_subtitle_generator/README.md +69 -0
- magic_hour/resources/v1/auto_subtitle_generator/client.py +178 -0
- magic_hour/resources/v1/face_detection/README.md +59 -0
- magic_hour/resources/v1/face_detection/__init__.py +10 -2
- magic_hour/resources/v1/face_detection/client.py +179 -0
- magic_hour/resources/v1/face_swap/README.md +105 -8
- magic_hour/resources/v1/face_swap/client.py +242 -0
- magic_hour/resources/v1/face_swap_photo/README.md +84 -0
- magic_hour/resources/v1/face_swap_photo/client.py +172 -0
- magic_hour/resources/v1/files/README.md +6 -0
- magic_hour/resources/v1/files/client.py +350 -0
- magic_hour/resources/v1/files/client_test.py +414 -0
- magic_hour/resources/v1/files/upload_urls/README.md +8 -0
- magic_hour/resources/v1/image_background_remover/README.md +68 -0
- magic_hour/resources/v1/image_background_remover/client.py +130 -0
- magic_hour/resources/v1/image_projects/README.md +8 -0
- magic_hour/resources/v1/image_projects/__init__.py +10 -2
- magic_hour/resources/v1/image_projects/client.py +138 -0
- magic_hour/resources/v1/image_projects/client_test.py +527 -0
- magic_hour/resources/v1/image_to_video/README.md +77 -9
- magic_hour/resources/v1/image_to_video/client.py +186 -0
- magic_hour/resources/v1/lip_sync/README.md +87 -9
- magic_hour/resources/v1/lip_sync/client.py +210 -0
- magic_hour/resources/v1/photo_colorizer/README.md +59 -0
- magic_hour/resources/v1/photo_colorizer/client.py +130 -0
- magic_hour/resources/v1/text_to_video/README.md +68 -0
- magic_hour/resources/v1/text_to_video/client.py +151 -0
- magic_hour/resources/v1/video_projects/README.md +8 -0
- magic_hour/resources/v1/video_projects/__init__.py +10 -2
- magic_hour/resources/v1/video_projects/client.py +137 -0
- magic_hour/resources/v1/video_projects/client_test.py +527 -0
- magic_hour/resources/v1/video_to_video/README.md +98 -10
- magic_hour/resources/v1/video_to_video/client.py +222 -0
- magic_hour/types/params/__init__.py +58 -0
- magic_hour/types/params/v1_ai_clothes_changer_generate_body_assets.py +33 -0
- magic_hour/types/params/v1_ai_face_editor_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_headshot_generator_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_image_editor_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_image_upscaler_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_photo_editor_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_talking_photo_generate_body_assets.py +26 -0
- magic_hour/types/params/v1_animation_generate_body_assets.py +39 -0
- magic_hour/types/params/v1_auto_subtitle_generator_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_face_detection_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_face_swap_create_body.py +12 -0
- magic_hour/types/params/v1_face_swap_create_body_style.py +33 -0
- magic_hour/types/params/v1_face_swap_generate_body_assets.py +56 -0
- magic_hour/types/params/v1_face_swap_generate_body_assets_face_mappings_item.py +25 -0
- magic_hour/types/params/v1_face_swap_photo_generate_body_assets.py +47 -0
- magic_hour/types/params/v1_face_swap_photo_generate_body_assets_face_mappings_item.py +25 -0
- magic_hour/types/params/v1_image_background_remover_generate_body_assets.py +27 -0
- magic_hour/types/params/v1_image_to_video_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_lip_sync_generate_body_assets.py +36 -0
- magic_hour/types/params/v1_photo_colorizer_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_video_to_video_generate_body_assets.py +27 -0
- magic_hour-0.36.0.dist-info/METADATA +303 -0
- {magic_hour-0.35.0.dist-info → magic_hour-0.36.0.dist-info}/RECORD +93 -65
- magic_hour-0.35.0.dist-info/METADATA +0 -166
- {magic_hour-0.35.0.dist-info → magic_hour-0.36.0.dist-info}/LICENSE +0 -0
- {magic_hour-0.35.0.dist-info → magic_hour-0.36.0.dist-info}/WHEEL +0 -0
|
@@ -1,3 +1,66 @@
|
|
|
1
|
+
# v1_image_to_video
|
|
2
|
+
|
|
3
|
+
## Module Functions
|
|
4
|
+
|
|
5
|
+
<!-- CUSTOM DOCS START -->
|
|
6
|
+
|
|
7
|
+
### Image To Video Generate Workflow <a name="generate"></a>
|
|
8
|
+
|
|
9
|
+
The workflow performs the following action
|
|
10
|
+
|
|
11
|
+
1. upload local assets to Magic Hour storage. So you can pass in a local path instead of having to upload files yourself
|
|
12
|
+
2. trigger a generation
|
|
13
|
+
3. poll for a completion status. This is configurable
|
|
14
|
+
4. if success, download the output to local directory
|
|
15
|
+
|
|
16
|
+
> [!TIP]
|
|
17
|
+
> This is the recommended way to use the SDK unless you have specific needs where it is necessary to split up the actions.
|
|
18
|
+
|
|
19
|
+
#### Parameters
|
|
20
|
+
|
|
21
|
+
In Additional to the parameters listed in the `.create` section below, `.generate` introduces 3 new parameters:
|
|
22
|
+
|
|
23
|
+
- `wait_for_completion` (bool, default True): Whether to wait for the project to complete.
|
|
24
|
+
- `download_outputs` (bool, default True): Whether to download the generated files
|
|
25
|
+
- `download_directory` (str, optional): Directory to save downloaded files (defaults to current directory)
|
|
26
|
+
|
|
27
|
+
#### Synchronous Client
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from magic_hour import Client
|
|
31
|
+
from os import getenv
|
|
32
|
+
|
|
33
|
+
client = Client(token=getenv("API_TOKEN"))
|
|
34
|
+
res = client.v1.image_to_video.generate(
|
|
35
|
+
assets={"image_file_path": "/path/to/1234.png"},
|
|
36
|
+
end_seconds=5.0,
|
|
37
|
+
name="Image To Video video",
|
|
38
|
+
resolution="720p",
|
|
39
|
+
wait_for_completion=True,
|
|
40
|
+
download_outputs=True,
|
|
41
|
+
download_directory="outputs"
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### Asynchronous Client
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from magic_hour import AsyncClient
|
|
49
|
+
from os import getenv
|
|
50
|
+
|
|
51
|
+
client = AsyncClient(token=getenv("API_TOKEN"))
|
|
52
|
+
res = await client.v1.image_to_video.generate(
|
|
53
|
+
assets={"image_file_path": "/path/to/1234.png"},
|
|
54
|
+
end_seconds=5.0,
|
|
55
|
+
name="Image To Video video",
|
|
56
|
+
resolution="720p",
|
|
57
|
+
wait_for_completion=True,
|
|
58
|
+
download_outputs=True,
|
|
59
|
+
download_directory="outputs"
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
<!-- CUSTOM DOCS END -->
|
|
1
64
|
|
|
2
65
|
### Image-to-Video <a name="create"></a>
|
|
3
66
|
|
|
@@ -10,15 +73,19 @@ Get more information about this mode at our [product page](https://magichour.ai/
|
|
|
10
73
|
|
|
11
74
|
#### Parameters
|
|
12
75
|
|
|
13
|
-
| Parameter | Required | Description | Example |
|
|
14
|
-
|
|
15
|
-
| `assets` | ✓ | Provide the assets for image-to-video. | `{"image_file_path": "api-assets/id/1234.png"}` |
|
|
16
|
-
| `
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
20
|
-
| `
|
|
21
|
-
| `
|
|
76
|
+
| Parameter | Required | Deprecated | Description | Example |
|
|
77
|
+
|-----------|:--------:|:----------:|-------------|--------|
|
|
78
|
+
| `assets` | ✓ | ✗ | Provide the assets for image-to-video. | `{"image_file_path": "api-assets/id/1234.png"}` |
|
|
79
|
+
| `└─ image_file_path` | ✓ | — | The path of the image file. This value is either - a direct URL to the video file - `file_path` field from the response of the [upload urls API](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls). Please refer to the [Input File documentation](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls#input-file) to learn more. | `"api-assets/id/1234.png"` |
|
|
80
|
+
| `end_seconds` | ✓ | ✗ | The total duration of the output video in seconds. | `5.0` |
|
|
81
|
+
| `height` | ✗ | ✓ | `height` is deprecated and no longer influences the output video's resolution. Output resolution is determined by the **minimum** of: - The resolution of the input video - The maximum resolution allowed by your subscription tier. See our [pricing page](https://magichour.ai/pricing) for more details. This field is retained only for backward compatibility and will be removed in a future release. | `123` |
|
|
82
|
+
| `name` | ✗ | ✗ | The name of video. This value is mainly used for your own identification of the video. | `"Image To Video video"` |
|
|
83
|
+
| `resolution` | ✗ | ✗ | Controls the output video resolution. Defaults to `720p` if not specified. 480p and 720p are available on Creator, Pro, or Business tiers. However, 1080p require Pro or Business tier. **Options:** - `480p` - Supports only 5 or 10 second videos. Output: 24fps. Cost: 120 credits per 5 seconds. - `720p` - Supports videos between 5-60 seconds. Output: 30fps. Cost: 300 credits per 5 seconds. - `1080p` - Supports videos between 5-60 seconds. Output: 30fps. Cost: 600 credits per 5 seconds. | `"720p"` |
|
|
84
|
+
| `style` | ✗ | ✗ | Attributed used to dictate the style of the output | `{"prompt": "a dog running"}` |
|
|
85
|
+
| `└─ high_quality` | ✗ | ✓ | Deprecated: Please use `resolution` instead. For backward compatibility, * `false` maps to 720p resolution * `true` maps to 1080p resolution This field will be removed in a future version. Use the `resolution` field to directly specify the resolution. | `True` |
|
|
86
|
+
| `└─ prompt` | ✗ | — | The prompt used for the video. | `"a dog running"` |
|
|
87
|
+
| `└─ quality_mode` | ✗ | ✓ | DEPRECATED: Please use `resolution` field instead. For backward compatibility: * `quick` maps to 720p resolution * `studio` maps to 1080p resolution This field will be removed in a future version. Use the `resolution` field to directly to specify the resolution. | `"quick"` |
|
|
88
|
+
| `width` | ✗ | ✓ | `width` is deprecated and no longer influences the output video's resolution. Output resolution is determined by the **minimum** of: - The resolution of the input video - The maximum resolution allowed by your subscription tier. See our [pricing page](https://magichour.ai/pricing) for more details. This field is retained only for backward compatibility and will be removed in a future release. | `123` |
|
|
22
89
|
|
|
23
90
|
#### Synchronous Client
|
|
24
91
|
|
|
@@ -59,3 +126,4 @@ res = await client.v1.image_to_video.create(
|
|
|
59
126
|
|
|
60
127
|
##### Example
|
|
61
128
|
`{"credits_charged": 450, "estimated_frame_cost": 450, "id": "cuid-example"}`
|
|
129
|
+
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import typing
|
|
2
3
|
import typing_extensions
|
|
3
4
|
|
|
@@ -9,13 +10,110 @@ from magic_hour.core import (
|
|
|
9
10
|
to_encodable,
|
|
10
11
|
type_utils,
|
|
11
12
|
)
|
|
13
|
+
from magic_hour.resources.v1.files.client import AsyncFilesClient, FilesClient
|
|
14
|
+
from magic_hour.resources.v1.video_projects.client import (
|
|
15
|
+
AsyncVideoProjectsClient,
|
|
16
|
+
VideoProjectsClient,
|
|
17
|
+
)
|
|
12
18
|
from magic_hour.types import models, params
|
|
13
19
|
|
|
14
20
|
|
|
21
|
+
logging.basicConfig(level=logging.INFO)
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
|
|
15
25
|
class ImageToVideoClient:
|
|
16
26
|
def __init__(self, *, base_client: SyncBaseClient):
|
|
17
27
|
self._base_client = base_client
|
|
18
28
|
|
|
29
|
+
def generate(
|
|
30
|
+
self,
|
|
31
|
+
*,
|
|
32
|
+
assets: params.V1ImageToVideoGenerateBodyAssets,
|
|
33
|
+
end_seconds: float,
|
|
34
|
+
height: typing.Union[
|
|
35
|
+
typing.Optional[int], type_utils.NotGiven
|
|
36
|
+
] = type_utils.NOT_GIVEN,
|
|
37
|
+
name: typing.Union[
|
|
38
|
+
typing.Optional[str], type_utils.NotGiven
|
|
39
|
+
] = type_utils.NOT_GIVEN,
|
|
40
|
+
resolution: typing.Union[
|
|
41
|
+
typing.Optional[typing_extensions.Literal["1080p", "480p", "720p"]],
|
|
42
|
+
type_utils.NotGiven,
|
|
43
|
+
] = type_utils.NOT_GIVEN,
|
|
44
|
+
style: typing.Union[
|
|
45
|
+
typing.Optional[params.V1ImageToVideoCreateBodyStyle], type_utils.NotGiven
|
|
46
|
+
] = type_utils.NOT_GIVEN,
|
|
47
|
+
width: typing.Union[
|
|
48
|
+
typing.Optional[int], type_utils.NotGiven
|
|
49
|
+
] = type_utils.NOT_GIVEN,
|
|
50
|
+
wait_for_completion: bool = True,
|
|
51
|
+
download_outputs: bool = True,
|
|
52
|
+
download_directory: typing.Optional[str] = None,
|
|
53
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
54
|
+
):
|
|
55
|
+
"""
|
|
56
|
+
Generate image-to-video (alias for create with additional functionality).
|
|
57
|
+
|
|
58
|
+
Create a Image To Video video. The estimated frame cost is calculated using 30 FPS. This amount is deducted from your account balance when a video is queued. Once the video is complete, the cost will be updated based on the actual number of frames rendered.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
height: `height` is deprecated and no longer influences the output video's resolution.
|
|
62
|
+
name: The name of video. This value is mainly used for your own identification of the video.
|
|
63
|
+
resolution: Controls the output video resolution. Defaults to `720p` if not specified.
|
|
64
|
+
style: Attributed used to dictate the style of the output
|
|
65
|
+
width: `width` is deprecated and no longer influences the output video's resolution.
|
|
66
|
+
assets: Provide the assets for image-to-video.
|
|
67
|
+
end_seconds: The total duration of the output video in seconds.
|
|
68
|
+
wait_for_completion: Whether to wait for the video project to complete
|
|
69
|
+
download_outputs: Whether to download the outputs
|
|
70
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
71
|
+
request_options: Additional options to customize the HTTP request
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
V1VideoProjectsGetResponseWithDownloads: The response from the Image-to-Video API with the downloaded paths if `download_outputs` is True.
|
|
75
|
+
|
|
76
|
+
Examples:
|
|
77
|
+
```py
|
|
78
|
+
response = client.v1.image_to_video.generate(
|
|
79
|
+
assets={"image_file_path": "path/to/image.png"},
|
|
80
|
+
end_seconds=5.0,
|
|
81
|
+
resolution="720p",
|
|
82
|
+
wait_for_completion=True,
|
|
83
|
+
download_outputs=True,
|
|
84
|
+
download_directory="outputs/",
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
file_client = FilesClient(base_client=self._base_client)
|
|
90
|
+
|
|
91
|
+
# Upload image file
|
|
92
|
+
image_file_path = assets["image_file_path"]
|
|
93
|
+
assets["image_file_path"] = file_client.upload_file(file=image_file_path)
|
|
94
|
+
|
|
95
|
+
create_response = self.create(
|
|
96
|
+
assets=assets,
|
|
97
|
+
end_seconds=end_seconds,
|
|
98
|
+
height=height,
|
|
99
|
+
name=name,
|
|
100
|
+
resolution=resolution,
|
|
101
|
+
style=style,
|
|
102
|
+
width=width,
|
|
103
|
+
request_options=request_options,
|
|
104
|
+
)
|
|
105
|
+
logger.info(f"Image-to-Video response: {create_response}")
|
|
106
|
+
|
|
107
|
+
video_projects_client = VideoProjectsClient(base_client=self._base_client)
|
|
108
|
+
response = video_projects_client.check_result(
|
|
109
|
+
id=create_response.id,
|
|
110
|
+
wait_for_completion=wait_for_completion,
|
|
111
|
+
download_outputs=download_outputs,
|
|
112
|
+
download_directory=download_directory,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
return response
|
|
116
|
+
|
|
19
117
|
def create(
|
|
20
118
|
self,
|
|
21
119
|
*,
|
|
@@ -121,6 +219,94 @@ class AsyncImageToVideoClient:
|
|
|
121
219
|
def __init__(self, *, base_client: AsyncBaseClient):
|
|
122
220
|
self._base_client = base_client
|
|
123
221
|
|
|
222
|
+
async def generate(
|
|
223
|
+
self,
|
|
224
|
+
*,
|
|
225
|
+
assets: params.V1ImageToVideoGenerateBodyAssets,
|
|
226
|
+
end_seconds: float,
|
|
227
|
+
height: typing.Union[
|
|
228
|
+
typing.Optional[int], type_utils.NotGiven
|
|
229
|
+
] = type_utils.NOT_GIVEN,
|
|
230
|
+
name: typing.Union[
|
|
231
|
+
typing.Optional[str], type_utils.NotGiven
|
|
232
|
+
] = type_utils.NOT_GIVEN,
|
|
233
|
+
resolution: typing.Union[
|
|
234
|
+
typing.Optional[typing_extensions.Literal["1080p", "480p", "720p"]],
|
|
235
|
+
type_utils.NotGiven,
|
|
236
|
+
] = type_utils.NOT_GIVEN,
|
|
237
|
+
style: typing.Union[
|
|
238
|
+
typing.Optional[params.V1ImageToVideoCreateBodyStyle], type_utils.NotGiven
|
|
239
|
+
] = type_utils.NOT_GIVEN,
|
|
240
|
+
width: typing.Union[
|
|
241
|
+
typing.Optional[int], type_utils.NotGiven
|
|
242
|
+
] = type_utils.NOT_GIVEN,
|
|
243
|
+
wait_for_completion: bool = True,
|
|
244
|
+
download_outputs: bool = True,
|
|
245
|
+
download_directory: typing.Optional[str] = None,
|
|
246
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
247
|
+
):
|
|
248
|
+
"""
|
|
249
|
+
Generate image-to-video (alias for create with additional functionality).
|
|
250
|
+
|
|
251
|
+
Create a Image To Video video. The estimated frame cost is calculated using 30 FPS. This amount is deducted from your account balance when a video is queued. Once the video is complete, the cost will be updated based on the actual number of frames rendered.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
height: `height` is deprecated and no longer influences the output video's resolution.
|
|
255
|
+
name: The name of video. This value is mainly used for your own identification of the video.
|
|
256
|
+
resolution: Controls the output video resolution. Defaults to `720p` if not specified.
|
|
257
|
+
style: Attributed used to dictate the style of the output
|
|
258
|
+
width: `width` is deprecated and no longer influences the output video's resolution.
|
|
259
|
+
assets: Provide the assets for image-to-video.
|
|
260
|
+
end_seconds: The total duration of the output video in seconds.
|
|
261
|
+
wait_for_completion: Whether to wait for the video project to complete
|
|
262
|
+
download_outputs: Whether to download the outputs
|
|
263
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
264
|
+
request_options: Additional options to customize the HTTP request
|
|
265
|
+
|
|
266
|
+
Returns:
|
|
267
|
+
V1VideoProjectsGetResponseWithDownloads: The response from the Image-to-Video API with the downloaded paths if `download_outputs` is True.
|
|
268
|
+
|
|
269
|
+
Examples:
|
|
270
|
+
```py
|
|
271
|
+
response = await client.v1.image_to_video.generate(
|
|
272
|
+
assets={"image_file_path": "path/to/image.png"},
|
|
273
|
+
end_seconds=5.0,
|
|
274
|
+
resolution="720p",
|
|
275
|
+
wait_for_completion=True,
|
|
276
|
+
download_outputs=True,
|
|
277
|
+
download_directory="outputs/",
|
|
278
|
+
)
|
|
279
|
+
```
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
file_client = AsyncFilesClient(base_client=self._base_client)
|
|
283
|
+
|
|
284
|
+
# Upload image file
|
|
285
|
+
image_file_path = assets["image_file_path"]
|
|
286
|
+
assets["image_file_path"] = await file_client.upload_file(file=image_file_path)
|
|
287
|
+
|
|
288
|
+
create_response = await self.create(
|
|
289
|
+
assets=assets,
|
|
290
|
+
end_seconds=end_seconds,
|
|
291
|
+
height=height,
|
|
292
|
+
name=name,
|
|
293
|
+
resolution=resolution,
|
|
294
|
+
style=style,
|
|
295
|
+
width=width,
|
|
296
|
+
request_options=request_options,
|
|
297
|
+
)
|
|
298
|
+
logger.info(f"Image-to-Video response: {create_response}")
|
|
299
|
+
|
|
300
|
+
video_projects_client = AsyncVideoProjectsClient(base_client=self._base_client)
|
|
301
|
+
response = await video_projects_client.check_result(
|
|
302
|
+
id=create_response.id,
|
|
303
|
+
wait_for_completion=wait_for_completion,
|
|
304
|
+
download_outputs=download_outputs,
|
|
305
|
+
download_directory=download_directory,
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
return response
|
|
309
|
+
|
|
124
310
|
async def create(
|
|
125
311
|
self,
|
|
126
312
|
*,
|
|
@@ -1,3 +1,76 @@
|
|
|
1
|
+
# v1_lip_sync
|
|
2
|
+
|
|
3
|
+
## Module Functions
|
|
4
|
+
|
|
5
|
+
<!-- CUSTOM DOCS START -->
|
|
6
|
+
|
|
7
|
+
### Lip Sync Generate Workflow <a name="generate"></a>
|
|
8
|
+
|
|
9
|
+
The workflow performs the following action
|
|
10
|
+
|
|
11
|
+
1. upload local assets to Magic Hour storage. So you can pass in a local path instead of having to upload files yourself
|
|
12
|
+
2. trigger a generation
|
|
13
|
+
3. poll for a completion status. This is configurable
|
|
14
|
+
4. if success, download the output to local directory
|
|
15
|
+
|
|
16
|
+
> [!TIP]
|
|
17
|
+
> This is the recommended way to use the SDK unless you have specific needs where it is necessary to split up the actions.
|
|
18
|
+
|
|
19
|
+
#### Parameters
|
|
20
|
+
|
|
21
|
+
In Additional to the parameters listed in the `.create` section below, `.generate` introduces 3 new parameters:
|
|
22
|
+
|
|
23
|
+
- `wait_for_completion` (bool, default True): Whether to wait for the project to complete.
|
|
24
|
+
- `download_outputs` (bool, default True): Whether to download the generated files
|
|
25
|
+
- `download_directory` (str, optional): Directory to save downloaded files (defaults to current directory)
|
|
26
|
+
|
|
27
|
+
#### Synchronous Client
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from magic_hour import Client
|
|
31
|
+
from os import getenv
|
|
32
|
+
|
|
33
|
+
client = Client(token=getenv("API_TOKEN"))
|
|
34
|
+
res = client.v1.lip_sync.generate(
|
|
35
|
+
assets={
|
|
36
|
+
"audio_file_path": "/path/to/1234.mp3",
|
|
37
|
+
"video_file_path": "/path/to/1234.mp4",
|
|
38
|
+
"video_source": "file",
|
|
39
|
+
},
|
|
40
|
+
end_seconds=15.0,
|
|
41
|
+
start_seconds=0.0,
|
|
42
|
+
max_fps_limit=12.0,
|
|
43
|
+
name="Lip Sync video",
|
|
44
|
+
wait_for_completion=True,
|
|
45
|
+
download_outputs=True,
|
|
46
|
+
download_directory="outputs"
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Asynchronous Client
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from magic_hour import AsyncClient
|
|
54
|
+
from os import getenv
|
|
55
|
+
|
|
56
|
+
client = AsyncClient(token=getenv("API_TOKEN"))
|
|
57
|
+
res = await client.v1.lip_sync.generate(
|
|
58
|
+
assets={
|
|
59
|
+
"audio_file_path": "/path/to/1234.mp3",
|
|
60
|
+
"video_file_path": "/path/to/1234.mp4",
|
|
61
|
+
"video_source": "file",
|
|
62
|
+
},
|
|
63
|
+
end_seconds=15.0,
|
|
64
|
+
start_seconds=0.0,
|
|
65
|
+
max_fps_limit=12.0,
|
|
66
|
+
name="Lip Sync video",
|
|
67
|
+
wait_for_completion=True,
|
|
68
|
+
download_outputs=True,
|
|
69
|
+
download_directory="outputs"
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
<!-- CUSTOM DOCS END -->
|
|
1
74
|
|
|
2
75
|
### Lip Sync <a name="create"></a>
|
|
3
76
|
|
|
@@ -10,15 +83,19 @@ Get more information about this mode at our [product page](https://magichour.ai/
|
|
|
10
83
|
|
|
11
84
|
#### Parameters
|
|
12
85
|
|
|
13
|
-
| Parameter | Required | Description | Example |
|
|
14
|
-
|
|
15
|
-
| `assets` | ✓ | Provide the assets for lip-sync. For video, The `video_source` field determines whether `video_file_path` or `youtube_url` field is used | `{"audio_file_path": "api-assets/id/1234.mp3", "video_file_path": "api-assets/id/1234.mp4", "video_source": "file"}` |
|
|
16
|
-
| `
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
20
|
-
| `
|
|
21
|
-
| `
|
|
86
|
+
| Parameter | Required | Deprecated | Description | Example |
|
|
87
|
+
|-----------|:--------:|:----------:|-------------|--------|
|
|
88
|
+
| `assets` | ✓ | ✗ | Provide the assets for lip-sync. For video, The `video_source` field determines whether `video_file_path` or `youtube_url` field is used | `{"audio_file_path": "api-assets/id/1234.mp3", "video_file_path": "api-assets/id/1234.mp4", "video_source": "file"}` |
|
|
89
|
+
| `└─ audio_file_path` | ✓ | — | The path of the audio file. This value is either - a direct URL to the video file - `file_path` field from the response of the [upload urls API](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls). Please refer to the [Input File documentation](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls#input-file) to learn more. | `"api-assets/id/1234.mp3"` |
|
|
90
|
+
| `└─ video_file_path` | ✗ | — | Required if `video_source` is `file`. This value is either - a direct URL to the video file - `file_path` field from the response of the [upload urls API](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls). Please refer to the [Input File documentation](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls#input-file) to learn more. | `"api-assets/id/1234.mp4"` |
|
|
91
|
+
| `└─ video_source` | ✓ | — | | `"file"` |
|
|
92
|
+
| `└─ youtube_url` | ✗ | — | Using a youtube video as the input source. This field is required if `video_source` is `youtube` | `"http://www.example.com"` |
|
|
93
|
+
| `end_seconds` | ✓ | ✗ | The end time of the input video in seconds. This value is used to trim the input video. The value must be greater than 0.1, and more than the start_seconds. | `15.0` |
|
|
94
|
+
| `start_seconds` | ✓ | ✗ | The start time of the input video in seconds. This value is used to trim the input video. The value must be greater than 0. | `0.0` |
|
|
95
|
+
| `height` | ✗ | ✓ | `height` is deprecated and no longer influences the output video's resolution. Output resolution is determined by the **minimum** of: - The resolution of the input video - The maximum resolution allowed by your subscription tier. See our [pricing page](https://magichour.ai/pricing) for more details. This field is retained only for backward compatibility and will be removed in a future release. | `123` |
|
|
96
|
+
| `max_fps_limit` | ✗ | ✗ | Defines the maximum FPS (frames per second) for the output video. If the input video's FPS is lower than this limit, the output video will retain the input FPS. This is useful for reducing unnecessary frame usage in scenarios where high FPS is not required. | `12.0` |
|
|
97
|
+
| `name` | ✗ | ✗ | The name of video. This value is mainly used for your own identification of the video. | `"Lip Sync video"` |
|
|
98
|
+
| `width` | ✗ | ✓ | `width` is deprecated and no longer influences the output video's resolution. Output resolution is determined by the **minimum** of: - The resolution of the input video - The maximum resolution allowed by your subscription tier. See our [pricing page](https://magichour.ai/pricing) for more details. This field is retained only for backward compatibility and will be removed in a future release. | `123` |
|
|
22
99
|
|
|
23
100
|
#### Synchronous Client
|
|
24
101
|
|
|
@@ -69,3 +146,4 @@ res = await client.v1.lip_sync.create(
|
|
|
69
146
|
|
|
70
147
|
##### Example
|
|
71
148
|
`{"credits_charged": 450, "estimated_frame_cost": 450, "id": "cuid-example"}`
|
|
149
|
+
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import typing
|
|
2
3
|
|
|
3
4
|
from magic_hour.core import (
|
|
@@ -8,13 +9,121 @@ from magic_hour.core import (
|
|
|
8
9
|
to_encodable,
|
|
9
10
|
type_utils,
|
|
10
11
|
)
|
|
12
|
+
from magic_hour.resources.v1.files.client import AsyncFilesClient, FilesClient
|
|
13
|
+
from magic_hour.resources.v1.video_projects.client import (
|
|
14
|
+
AsyncVideoProjectsClient,
|
|
15
|
+
VideoProjectsClient,
|
|
16
|
+
)
|
|
11
17
|
from magic_hour.types import models, params
|
|
12
18
|
|
|
13
19
|
|
|
20
|
+
logging.basicConfig(level=logging.INFO)
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
14
24
|
class LipSyncClient:
|
|
15
25
|
def __init__(self, *, base_client: SyncBaseClient):
|
|
16
26
|
self._base_client = base_client
|
|
17
27
|
|
|
28
|
+
def generate(
|
|
29
|
+
self,
|
|
30
|
+
*,
|
|
31
|
+
assets: params.V1LipSyncGenerateBodyAssets,
|
|
32
|
+
end_seconds: float,
|
|
33
|
+
start_seconds: float,
|
|
34
|
+
height: typing.Union[
|
|
35
|
+
typing.Optional[int], type_utils.NotGiven
|
|
36
|
+
] = type_utils.NOT_GIVEN,
|
|
37
|
+
max_fps_limit: typing.Union[
|
|
38
|
+
typing.Optional[float], type_utils.NotGiven
|
|
39
|
+
] = type_utils.NOT_GIVEN,
|
|
40
|
+
name: typing.Union[
|
|
41
|
+
typing.Optional[str], type_utils.NotGiven
|
|
42
|
+
] = type_utils.NOT_GIVEN,
|
|
43
|
+
width: typing.Union[
|
|
44
|
+
typing.Optional[int], type_utils.NotGiven
|
|
45
|
+
] = type_utils.NOT_GIVEN,
|
|
46
|
+
wait_for_completion: bool = True,
|
|
47
|
+
download_outputs: bool = True,
|
|
48
|
+
download_directory: typing.Optional[str] = None,
|
|
49
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
50
|
+
):
|
|
51
|
+
"""
|
|
52
|
+
Generate lip sync video (alias for create with additional functionality).
|
|
53
|
+
|
|
54
|
+
Create a Lip Sync video. The estimated frame cost is calculated using 30 FPS. This amount is deducted from your account balance when a video is queued. Once the video is complete, the cost will be updated based on the actual number of frames rendered.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
height: `height` is deprecated and no longer influences the output video's resolution.
|
|
58
|
+
max_fps_limit: Defines the maximum FPS (frames per second) for the output video. If the input video's FPS is lower than this limit, the output video will retain the input FPS. This is useful for reducing unnecessary frame usage in scenarios where high FPS is not required.
|
|
59
|
+
name: The name of video. This value is mainly used for your own identification of the video.
|
|
60
|
+
width: `width` is deprecated and no longer influences the output video's resolution.
|
|
61
|
+
assets: Provide the assets for lip-sync. For video, The `video_source` field determines whether `video_file_path` or `youtube_url` field is used
|
|
62
|
+
end_seconds: The end time of the input video in seconds. This value is used to trim the input video. The value must be greater than 0.1, and more than the start_seconds.
|
|
63
|
+
start_seconds: The start time of the input video in seconds. This value is used to trim the input video. The value must be greater than 0.
|
|
64
|
+
wait_for_completion: Whether to wait for the video project to complete
|
|
65
|
+
download_outputs: Whether to download the outputs
|
|
66
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
67
|
+
request_options: Additional options to customize the HTTP request
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
V1VideoProjectsGetResponseWithDownloads: The response from the Lip Sync API with the downloaded paths if `download_outputs` is True.
|
|
71
|
+
|
|
72
|
+
Examples:
|
|
73
|
+
```py
|
|
74
|
+
response = client.v1.lip_sync.generate(
|
|
75
|
+
assets={
|
|
76
|
+
"audio_file_path": "path/to/audio.mp3",
|
|
77
|
+
"video_file_path": "path/to/video.mp4",
|
|
78
|
+
"video_source": "file",
|
|
79
|
+
},
|
|
80
|
+
end_seconds=15.0,
|
|
81
|
+
start_seconds=0.0,
|
|
82
|
+
max_fps_limit=12.0,
|
|
83
|
+
wait_for_completion=True,
|
|
84
|
+
download_outputs=True,
|
|
85
|
+
download_directory="outputs/",
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
file_client = FilesClient(base_client=self._base_client)
|
|
91
|
+
|
|
92
|
+
# Upload audio file (always required)
|
|
93
|
+
audio_file_path = assets["audio_file_path"]
|
|
94
|
+
assets["audio_file_path"] = file_client.upload_file(file=audio_file_path)
|
|
95
|
+
|
|
96
|
+
# Upload video file if video_source is "file" and video_file_path is provided
|
|
97
|
+
if (
|
|
98
|
+
assets.get("video_source") == "file"
|
|
99
|
+
and "video_file_path" in assets
|
|
100
|
+
and assets["video_file_path"]
|
|
101
|
+
):
|
|
102
|
+
video_file_path = assets["video_file_path"]
|
|
103
|
+
assets["video_file_path"] = file_client.upload_file(file=video_file_path)
|
|
104
|
+
|
|
105
|
+
create_response = self.create(
|
|
106
|
+
assets=assets,
|
|
107
|
+
end_seconds=end_seconds,
|
|
108
|
+
start_seconds=start_seconds,
|
|
109
|
+
height=height,
|
|
110
|
+
max_fps_limit=max_fps_limit,
|
|
111
|
+
name=name,
|
|
112
|
+
width=width,
|
|
113
|
+
request_options=request_options,
|
|
114
|
+
)
|
|
115
|
+
logger.info(f"Lip Sync response: {create_response}")
|
|
116
|
+
|
|
117
|
+
video_projects_client = VideoProjectsClient(base_client=self._base_client)
|
|
118
|
+
response = video_projects_client.check_result(
|
|
119
|
+
id=create_response.id,
|
|
120
|
+
wait_for_completion=wait_for_completion,
|
|
121
|
+
download_outputs=download_outputs,
|
|
122
|
+
download_directory=download_directory,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
return response
|
|
126
|
+
|
|
18
127
|
def create(
|
|
19
128
|
self,
|
|
20
129
|
*,
|
|
@@ -115,6 +224,107 @@ class AsyncLipSyncClient:
|
|
|
115
224
|
def __init__(self, *, base_client: AsyncBaseClient):
|
|
116
225
|
self._base_client = base_client
|
|
117
226
|
|
|
227
|
+
async def generate(
|
|
228
|
+
self,
|
|
229
|
+
*,
|
|
230
|
+
assets: params.V1LipSyncGenerateBodyAssets,
|
|
231
|
+
end_seconds: float,
|
|
232
|
+
start_seconds: float,
|
|
233
|
+
height: typing.Union[
|
|
234
|
+
typing.Optional[int], type_utils.NotGiven
|
|
235
|
+
] = type_utils.NOT_GIVEN,
|
|
236
|
+
max_fps_limit: typing.Union[
|
|
237
|
+
typing.Optional[float], type_utils.NotGiven
|
|
238
|
+
] = type_utils.NOT_GIVEN,
|
|
239
|
+
name: typing.Union[
|
|
240
|
+
typing.Optional[str], type_utils.NotGiven
|
|
241
|
+
] = type_utils.NOT_GIVEN,
|
|
242
|
+
width: typing.Union[
|
|
243
|
+
typing.Optional[int], type_utils.NotGiven
|
|
244
|
+
] = type_utils.NOT_GIVEN,
|
|
245
|
+
wait_for_completion: bool = True,
|
|
246
|
+
download_outputs: bool = True,
|
|
247
|
+
download_directory: typing.Optional[str] = None,
|
|
248
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
249
|
+
):
|
|
250
|
+
"""
|
|
251
|
+
Generate lip sync video (alias for create with additional functionality).
|
|
252
|
+
|
|
253
|
+
Create a Lip Sync video. The estimated frame cost is calculated using 30 FPS. This amount is deducted from your account balance when a video is queued. Once the video is complete, the cost will be updated based on the actual number of frames rendered.
|
|
254
|
+
|
|
255
|
+
Args:
|
|
256
|
+
height: `height` is deprecated and no longer influences the output video's resolution.
|
|
257
|
+
max_fps_limit: Defines the maximum FPS (frames per second) for the output video. If the input video's FPS is lower than this limit, the output video will retain the input FPS. This is useful for reducing unnecessary frame usage in scenarios where high FPS is not required.
|
|
258
|
+
name: The name of video. This value is mainly used for your own identification of the video.
|
|
259
|
+
width: `width` is deprecated and no longer influences the output video's resolution.
|
|
260
|
+
assets: Provide the assets for lip-sync. For video, The `video_source` field determines whether `video_file_path` or `youtube_url` field is used
|
|
261
|
+
end_seconds: The end time of the input video in seconds. This value is used to trim the input video. The value must be greater than 0.1, and more than the start_seconds.
|
|
262
|
+
start_seconds: The start time of the input video in seconds. This value is used to trim the input video. The value must be greater than 0.
|
|
263
|
+
wait_for_completion: Whether to wait for the video project to complete
|
|
264
|
+
download_outputs: Whether to download the outputs
|
|
265
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
266
|
+
request_options: Additional options to customize the HTTP request
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
V1VideoProjectsGetResponseWithDownloads: The response from the Lip Sync API with the downloaded paths if `download_outputs` is True.
|
|
270
|
+
|
|
271
|
+
Examples:
|
|
272
|
+
```py
|
|
273
|
+
response = await client.v1.lip_sync.generate(
|
|
274
|
+
assets={
|
|
275
|
+
"audio_file_path": "path/to/audio.mp3",
|
|
276
|
+
"video_file_path": "path/to/video.mp4",
|
|
277
|
+
"video_source": "file",
|
|
278
|
+
},
|
|
279
|
+
end_seconds=15.0,
|
|
280
|
+
start_seconds=0.0,
|
|
281
|
+
max_fps_limit=12.0,
|
|
282
|
+
wait_for_completion=True,
|
|
283
|
+
download_outputs=True,
|
|
284
|
+
download_directory="outputs/",
|
|
285
|
+
)
|
|
286
|
+
```
|
|
287
|
+
"""
|
|
288
|
+
|
|
289
|
+
file_client = AsyncFilesClient(base_client=self._base_client)
|
|
290
|
+
|
|
291
|
+
# Upload audio file (always required)
|
|
292
|
+
audio_file_path = assets["audio_file_path"]
|
|
293
|
+
assets["audio_file_path"] = await file_client.upload_file(file=audio_file_path)
|
|
294
|
+
|
|
295
|
+
# Upload video file if video_source is "file" and video_file_path is provided
|
|
296
|
+
if (
|
|
297
|
+
assets.get("video_source") == "file"
|
|
298
|
+
and "video_file_path" in assets
|
|
299
|
+
and assets["video_file_path"]
|
|
300
|
+
):
|
|
301
|
+
video_file_path = assets["video_file_path"]
|
|
302
|
+
assets["video_file_path"] = await file_client.upload_file(
|
|
303
|
+
file=video_file_path
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
create_response = await self.create(
|
|
307
|
+
assets=assets,
|
|
308
|
+
end_seconds=end_seconds,
|
|
309
|
+
start_seconds=start_seconds,
|
|
310
|
+
height=height,
|
|
311
|
+
max_fps_limit=max_fps_limit,
|
|
312
|
+
name=name,
|
|
313
|
+
width=width,
|
|
314
|
+
request_options=request_options,
|
|
315
|
+
)
|
|
316
|
+
logger.info(f"Lip Sync response: {create_response}")
|
|
317
|
+
|
|
318
|
+
video_projects_client = AsyncVideoProjectsClient(base_client=self._base_client)
|
|
319
|
+
response = await video_projects_client.check_result(
|
|
320
|
+
id=create_response.id,
|
|
321
|
+
wait_for_completion=wait_for_completion,
|
|
322
|
+
download_outputs=download_outputs,
|
|
323
|
+
download_directory=download_directory,
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
return response
|
|
327
|
+
|
|
118
328
|
async def create(
|
|
119
329
|
self,
|
|
120
330
|
*,
|