@@ -48,23 +48,31 @@ func New(cfg *Config) *Client {
4848
4949// Generate generates a video from an image and a text prompt.
5050func (c * Client ) Generate (ctx context.Context , image , text , output string ,
51- extend int , interpolate , upscale , watermark bool ) ([] string , error ) {
51+ extend int , interpolate , upscale , watermark bool ) (string , error ) {
5252 b , err := os .ReadFile (image )
5353 if err != nil {
54- return nil , fmt .Errorf ("vidai: couldn't read image: %w" , err )
54+ return "" , fmt .Errorf ("vidai: couldn't read image: %w" , err )
5555 }
5656 name := filepath .Base (image )
5757
5858 var imageURL string
5959 if image != "" {
6060 imageURL , err = c .client .Upload (ctx , name , b )
6161 if err != nil {
62- return nil , fmt .Errorf ("vidai: couldn't upload image: %w" , err )
62+ return "" , fmt .Errorf ("vidai: couldn't upload image: %w" , err )
6363 }
6464 }
65- videoURL , err := c .client .Generate (ctx , imageURL , text , interpolate , upscale , watermark )
65+ videoURL , err := c .client .Generate (ctx , imageURL , text , interpolate , upscale , watermark , false )
6666 if err != nil {
67- return nil , fmt .Errorf ("vidai: couldn't generate video: %w" , err )
67+ return "" , fmt .Errorf ("vidai: couldn't generate video: %w" , err )
68+ }
69+
70+ // Extend video
71+ for i := 0 ; i < extend ; i ++ {
72+ videoURL , err = c .client .Generate (ctx , videoURL , "" , interpolate , upscale , watermark , true )
73+ if err != nil {
74+ return "" , fmt .Errorf ("vidai: couldn't extend video: %w" , err )
75+ }
6876 }
6977
7078 // Use temp file if no output is set and we need to extend the video
@@ -77,24 +85,14 @@ func (c *Client) Generate(ctx context.Context, image, text, output string,
7785 // Download video
7886 if videoPath != "" {
7987 if err := c .download (ctx , videoURL , videoPath ); err != nil {
80- return nil , fmt .Errorf ("vidai: couldn't download video: %w" , err )
81- }
82- }
83-
84- // Extend video
85- if extend > 0 {
86- extendURLs , err := c .Extend (ctx , videoPath , output , extend ,
87- interpolate , upscale , watermark )
88- if err != nil {
89- return nil , fmt .Errorf ("vidai: couldn't extend video: %w" , err )
88+ return "" , fmt .Errorf ("vidai: couldn't download video: %w" , err )
9089 }
91- return append ([]string {output }, extendURLs ... ), nil
9290 }
9391
94- return [] string { videoURL } , nil
92+ return videoURL , nil
9593}
9694
97- // Extend extends a video using the last frame of the previous video.
95+ // Extend extends a video using the previous video.
9896func (c * Client ) Extend (ctx context.Context , input , output string , n int ,
9997 interpolate , upscale , watermark bool ) ([]string , error ) {
10098 base := strings .TrimSuffix (filepath .Base (input ), filepath .Ext (input ))
@@ -133,7 +131,7 @@ func (c *Client) Extend(ctx context.Context, input, output string, n int,
133131 if err != nil {
134132 return nil , fmt .Errorf ("vidai: couldn't upload image: %w" , err )
135133 }
136- videoURL , err := c .client .Generate (ctx , imageURL , "" , interpolate , upscale , watermark )
134+ videoURL , err := c .client .Generate (ctx , imageURL , "" , interpolate , upscale , watermark , false )
137135 if err != nil {
138136 return nil , fmt .Errorf ("vidai: couldn't generate video: %w" , err )
139137 }
0 commit comments