Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions google/genai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,13 @@ def _GenerateVideosConfig_to_mldev(
'compression_quality parameter is not supported in Gemini API.'
)

if getv(from_object, ['resize_mode']) is not None:
setv(
parent_object,
['parameters', 'resizeMode'],
getv(from_object, ['resize_mode']),
)

return to_object


Expand Down Expand Up @@ -1970,6 +1977,13 @@ def _GenerateVideosConfig_to_vertex(
getv(from_object, ['compression_quality']),
)

if getv(from_object, ['resize_mode']) is not None:
setv(
parent_object,
['parameters', 'resizeMode'],
getv(from_object, ['resize_mode']),
)

return to_object


Expand Down
41 changes: 41 additions & 0 deletions google/genai/tests/models/test_generate_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
negative_prompt="ugly, low quality",
enhance_prompt=True,
compression_quality=types.VideoCompressionQuality.LOSSLESS,
resize_mode="pad",
),
),
exception_if_mldev=(
Expand Down Expand Up @@ -252,6 +253,28 @@
"output_gcs_uri parameter is not supported in Gemini API"
),
),
pytest_helper.TestTableItem(
name="test_image_to_video_with_resize_mode_pad",
parameters=types._GenerateVideosParameters(
model=VEO_MODEL_LATEST,
image=LOCAL_IMAGE,
config=types.GenerateVideosConfig(
number_of_videos=1,
resize_mode="pad",
),
),
),
pytest_helper.TestTableItem(
name="test_image_to_video_with_resize_mode_crop",
parameters=types._GenerateVideosParameters(
model=VEO_MODEL_LATEST,
image=LOCAL_IMAGE,
config=types.GenerateVideosConfig(
number_of_videos=1,
resize_mode="crop",
),
),
),
]

pytestmark = pytest_helper.setup(
Expand Down Expand Up @@ -538,6 +561,24 @@ def test_reference_images_to_video_poll(client):
assert operation.result.generated_videos[0].video.uri


def test_image_to_video_resize_mode_poll(client):
operation = client.models.generate_videos(
model=VEO_MODEL_LATEST,
image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE,
config=types.GenerateVideosConfig(
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
resize_mode="crop",
),
)
while not operation.done:
# Skip the sleep when in replay mode.
if client._api_client._mode not in ("replay", "auto"):
time.sleep(20)
operation = client.operations.get(operation=operation)

assert operation.result.generated_videos[0].video.uri


def test_video_edit_outpaint_poll(client):
# Editing videos is only supported in Vertex AI.
if not client.vertexai:
Expand Down
9 changes: 9 additions & 0 deletions google/genai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9901,6 +9901,11 @@ class GenerateVideosConfig(_common.BaseModel):
default=None,
description="""Compression quality of the generated videos.""",
)
resize_mode: Optional[str] = Field(
default=None,
description="""The resize mode for image-to-video generation. Supported values
are: pad, crop. Default is pad when not specified.""",
)


class GenerateVideosConfigDict(TypedDict, total=False):
Expand Down Expand Up @@ -9970,6 +9975,10 @@ class GenerateVideosConfigDict(TypedDict, total=False):
compression_quality: Optional[VideoCompressionQuality]
"""Compression quality of the generated videos."""

resize_mode: Optional[str]
"""The resize mode for image-to-video generation. Supported values
are: pad, crop. Default is pad when not specified."""


GenerateVideosConfigOrDict = Union[
GenerateVideosConfig, GenerateVideosConfigDict
Expand Down