2023-12-15 20:31:28 +00:00
""" Command for generating AI-powered videos """
2023-11-22 18:33:58 +00:00
import logging
import click
logger = logging . getLogger ( __name__ )
@click.command ( )
@click.option (
" --start-image " ,
default = " other/images/sound-music.jpg " ,
help = " Input path for image file. " ,
)
@click.option ( " --num-frames " , default = None , type = int , help = " Number of frames. " )
2023-11-23 18:16:12 +00:00
@click.option (
" -s " , " --steps " , default = None , type = int , help = " Number of diffusion steps. "
)
2023-11-22 18:33:58 +00:00
@click.option (
" --model " ,
default = " svd " ,
2024-04-18 02:04:18 +00:00
help = " Model to use. One of: svd, svd-xt, svd-image-decoder, svd-xt-image-decoder " ,
2023-11-22 18:33:58 +00:00
)
@click.option (
" --fps " , default = 6 , type = int , help = " FPS for the AI to target when generating video "
)
2024-01-08 02:11:20 +00:00
@click.option (
" --size " ,
default = " 1024,576 " ,
show_default = True ,
type = str ,
help = " Video dimensions. Can be a named size, single integer, or WIDTHxHEIGHT pair. Should be multiple of 8. Examples: SVD, 512x512, 4k, UHD, 8k, 512, 1080p " ,
)
2023-11-22 18:33:58 +00:00
@click.option ( " --output-fps " , default = None , type = int , help = " FPS for the output video " )
2024-01-08 02:11:20 +00:00
@click.option (
" --output-format " ,
default = " webp " ,
help = " Output video format " ,
type = click . Choice ( [ " webp " , " mp4 " , " gif " ] ) ,
)
2023-11-22 18:33:58 +00:00
@click.option (
" --motion-amount " ,
default = 127 ,
type = int ,
help = " How much motion to generate. value between 0 and 255. " ,
)
@click.option (
" -r " ,
" --repeats " ,
default = 1 ,
show_default = True ,
type = int ,
help = " How many times to repeat the renders. " ,
)
@click.option ( " --cond-aug " , default = 0.02 , type = float , help = " Conditional augmentation. " )
@click.option (
" --seed " , default = None , type = int , help = " Seed for random number generator. "
)
@click.option (
" --decoding_t " , default = 1 , type = int , help = " Number of frames decoded at a time. "
)
@click.option ( " --output_folder " , default = None , help = " Output folder. " )
def videogen_cmd (
start_image ,
num_frames ,
2023-11-23 18:16:12 +00:00
steps ,
2023-11-22 18:33:58 +00:00
model ,
fps ,
2024-01-08 02:11:20 +00:00
size ,
2023-11-22 18:33:58 +00:00
output_fps ,
2024-01-08 02:11:20 +00:00
output_format ,
2023-11-22 18:33:58 +00:00
motion_amount ,
repeats ,
cond_aug ,
seed ,
decoding_t ,
output_folder ,
) :
"""
AI generate a video from an image
Example :
aimg videogen - - start - image assets / rocket - wide . png
"""
2023-12-15 21:47:39 +00:00
from imaginairy . api . video_sample import generate_video
2023-12-15 21:40:10 +00:00
from imaginairy . utils . log_utils import configure_logging
2023-11-22 18:33:58 +00:00
configure_logging ( )
output_fps = output_fps or fps
2023-11-23 20:24:48 +00:00
try :
generate_video (
input_path = start_image ,
num_frames = num_frames ,
num_steps = steps ,
model_name = model ,
fps_id = fps ,
2024-01-08 02:11:20 +00:00
size = size ,
2023-11-23 20:24:48 +00:00
output_fps = output_fps ,
2024-01-08 02:11:20 +00:00
output_format = output_format ,
2023-11-23 20:24:48 +00:00
motion_bucket_id = motion_amount ,
cond_aug = cond_aug ,
seed = seed ,
decoding_t = decoding_t ,
output_folder = output_folder ,
repetitions = repeats ,
)
except FileNotFoundError as e :
logger . error ( str ( e ) )
exit ( 1 )