Skip to content

Commit

Permalink
Add --seconds parameter to specify video duration
Browse files Browse the repository at this point in the history
Fixes #8

Add the option to specify the `--seconds` parameter for `img2video`.

* **pkg/cli/cli.go**
  - Add a `--seconds` parameter to the `generate` command.
  - Add a `--seconds` parameter to the `extend` command.

* **pkg/cmd/generate/generate.go**
  - Add a `Seconds` field to the `Config` struct.
  - Parse the `--seconds` parameter and set the `Seconds` field in the `Run` function.

* **pkg/cmd/extend/extend.go**
  - Add a `Seconds` field to the `Config` struct.
  - Parse the `--seconds` parameter and set the `Seconds` field in the `Run` function.

* **pkg/runway/runway.go**
  - Use the `Seconds` field from the `GenerateRequest` struct in the `createGen2TaskRequest` and `createGen3TaskRequest` structures.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/igolaizola/vidai/issues/8?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
igolaizola committed Oct 16, 2024
1 parent 6aa19ea commit 103ae28
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func newGenerateCommand() *ffcli.Command {
fs.IntVar(&cfg.Height, "height", 0, "output video height (optional)")
fs.BoolVar(&cfg.Explore, "explore", false, "explore mode (optional)")
fs.BoolVar(&cfg.LastFrame, "last-frame", false, "use source image as the last frame (optional)")
fs.IntVar(&cfg.Seconds, "seconds", 10, "duration of the video in seconds (optional)")

return &ffcli.Command{
Name: cmd,
Expand Down Expand Up @@ -120,6 +121,7 @@ func newExtendCommand() *ffcli.Command {
fs.BoolVar(&cfg.Upscale, "upscale", false, "upscale frames (optional)")
fs.BoolVar(&cfg.Watermark, "watermark", false, "add watermark (optional)")
fs.BoolVar(&cfg.Explore, "explore", false, "explore mode (optional)")
fs.IntVar(&cfg.Seconds, "seconds", 2, "duration of the video in seconds (optional)")

return &ffcli.Command{
Name: cmd,
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/extend/extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Config struct {
Upscale bool
Watermark bool
Explore bool
Seconds int
}

// Run generates a video from an image and a text prompt.
Expand Down Expand Up @@ -106,6 +107,7 @@ func Run(ctx context.Context, cfg *Config) error {
Watermark: cfg.Watermark,
Extend: false,
ExploreMode: cfg.Explore,
Seconds: cfg.Seconds,
})
if err != nil {
return fmt.Errorf("vidai: couldn't generate video: %w", err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Config struct {
Height int
Explore bool
LastFrame bool
Seconds int
}

// Run generates a video from an image and a text prompt.
Expand Down Expand Up @@ -89,6 +90,7 @@ func Run(ctx context.Context, cfg *Config) error {
Height: cfg.Height,
ExploreMode: cfg.Explore,
LastFrame: cfg.LastFrame,
Seconds: cfg.Seconds,
})
if err != nil {
return fmt.Errorf("vidai: couldn't generate video: %w", err)
Expand All @@ -104,6 +106,7 @@ func Run(ctx context.Context, cfg *Config) error {
Upscale: cfg.Upscale,
Watermark: cfg.Watermark,
Extend: true,
Seconds: cfg.Seconds,
})
if err != nil {
return fmt.Errorf("vidai: couldn't extend video: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/runway/runway.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ type GenerateRequest struct {
Height int
ExploreMode bool
LastFrame bool
Seconds int
}

type Error struct {
Expand Down Expand Up @@ -466,7 +467,7 @@ func (c *Client) Generate(ctx context.Context, cfg *GenerateRequest) (*Generatio
AssetGroupName string `json:"assetGroupName"`
ExploreMode bool `json:"exploreMode"`
}{
Seconds: 4,
Seconds: cfg.Seconds,
Gen2Options: gen2Options{
Interpolate: cfg.Interpolate,
Seed: seed,
Expand Down Expand Up @@ -513,7 +514,7 @@ func (c *Client) Generate(ctx context.Context, cfg *GenerateRequest) (*Generatio
Internal: false,
Options: gen3Options{
Name: name,
Seconds: 10,
Seconds: cfg.Seconds,
TextPrompt: cfg.Prompt,
Seed: seed,
ExploreMode: cfg.ExploreMode,
Expand Down

0 comments on commit 103ae28

Please sign in to comment.