Skip to content
FastVideo
Esc
↑↓navigate↵open⌘Jpreview
On this page

resolution_utils

fastvideo.models.dits.hyworld.resolution_utils.generate_crop_size_list

generate_crop_size_list(base_size = 256, patch_size = 16, max_ratio = 4.0)

fastvideo.models.dits.hyworld.resolution_utils.get_closest_resolution

get_closest_resolution(image_height, image_width, target_resolution = '480p')

Get closest supported resolution for given image dimensions.

Parameters

image_height

Height of input image

image_width

Width of input image

target_resolution

Target resolution string (e.g., "480p", "720p")

Returns

tuple[int, int]: (height, width) of closest supported resolution

Source
def get_closest_resolution(image_height, image_width, target_resolution="480p"):
    """
    Get closest supported resolution for given image dimensions.
Args:
    image_height: Height of input image
    image_width: Width of input image  
    target_resolution: Target resolution string (e.g., "480p", "720p")

Returns:
    tuple[int, int]: (height, width) of closest supported resolution
"""
config = TARGET_SIZE_CONFIG[target_resolution]
bucket_hw_base_size = config["bucket_hw_base_size"]
bucket_hw_bucket_stride = config["bucket_hw_bucket_stride"]

crop_size_list = generate_crop_size_list(bucket_hw_base_size, bucket_hw_bucket_stride)
aspect_ratios = np.array([round(float(h) / float(w), 5) for h, w in crop_size_list])

# Find closest aspect ratio
image_ratio = float(image_height) / float(image_width)
closest_idx = np.abs(aspect_ratios - image_ratio).argmin()
closest_size = crop_size_list[closest_idx]

return closest_size&#91;0&#93;, closest_size&#91;1&#93;  # (height, width)</code></pre></details>

fastvideo.models.dits.hyworld.resolution_utils.get_resolution_from_image

get_resolution_from_image(image_path, target_resolution = '480p')

Automatically determine resolution from input image.

Parameters

image_path

Path or URL to input image

target_resolution

Target resolution tier ("480p", "720p", etc.)

Returns

tuple[int, int]: (height, width) matching HY-WorldPlay's bucket selection

Source
def get_resolution_from_image(image_path, target_resolution="480p"):
    """
    Automatically determine resolution from input image.
Args:
    image_path: Path or URL to input image
    target_resolution: Target resolution tier (&quot;480p&quot;, &quot;720p&quot;, etc.)

Returns:
    tuple&#91;int, int&#93;: (height, width) matching HY-WorldPlay&#x27;s bucket selection
&quot;&quot;&quot;
# Handle URL inputs
if isinstance(image_path, str) and image_path.startswith((&#x27;http://&#x27;, &#x27;https://&#x27;)):
    response = requests.get(image_path)
    response.raise_for_status()
    img = Image.open(BytesIO(response.content))
else:
    img = Image.open(image_path)
img_width, img_height = img.size
return get_closest_resolution(img_height, img_width, target_resolution)</code></pre></details>

Was this page helpful?