video

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cli.Command{
	Name:        "video",
	Usage:       "Interact with video files",
	Subcommands: []*cli.Command{CmdCut, CmdExtract, CmdMerge, CmdConvert},
}
View Source
var CmdConvert = &cli.Command{
	Name:  "convert",
	Usage: "convert video file to MP4",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:     "preset",
			Usage:    fmt.Sprintf("quality preset (%s)", convert.PresetsAvailable),
			Value:    string(convert.Fast),
			Required: false,
		},
	},
	Action: func(cmd *cli.Context) error {
		source := cmd.Args().First()

		if source == "" {
			return ErrorMissingSourceArgument
		}

		cfg := config.Ctx(cmd.Context)

		params, err := cfg.Convert.Apply(convert.Params{
			Source: source,
			Preset: convert.Preset(cmd.String("preset")),
		})
		if err != nil {
			return err
		}

		_, err = convert.ToMP4(cmd.Context, params)

		return err
	},
}
View Source
var CmdCut = &cli.Command{
	Name:  "cut",
	Usage: "cut video file",
	Flags: []cli.Flag{
		&cli.DurationFlag{
			Name:     "start",
			Usage:    "begin of video",
			Required: true,
		},
		&cli.DurationFlag{
			Name:     "finish",
			Usage:    "end of video",
			Required: true,
		},
	},
	Action: func(ctx *cli.Context) error {
		source := ctx.Args().First()

		if source == "" {
			return ErrorMissingSourceArgument
		}

		cfg := config.Ctx(ctx.Context)

		start := ctx.Duration("start")
		finish := ctx.Duration("finish")

		params, err := cfg.Cut.Apply(cut.Params{
			Source: source,
			Start:  start,
			Finish: finish,
		})
		if err != nil {
			return err
		}

		_, err = cut.Video(ctx.Context, params)

		return err
	},
}
View Source
var CmdExtract = &cli.Command{
	Name:        "extract",
	Usage:       "Extract audio from a video file",
	Subcommands: []*cli.Command{CmdExtractAudio},
}
View Source
var CmdExtractAudio = &cli.Command{
	Name: "audio",
	Action: func(ctx *cli.Context) error {
		source := ctx.Args().First()

		if source == "" {
			return ErrorMissingSourceArgument
		}

		if !path.IsAbs(source) {
			pwd, _ := os.Getwd()
			source = path.Join(pwd, source)
		}

		cfg := config.Ctx(ctx.Context)

		params, err := cfg.Audio.Apply(audios.Params{
			Source: source,
		})
		if err != nil {
			return err
		}

		file, err := audios.Extract(ctx.Context, params)

		if err == nil {
			pterm.Success.Printfln("Done: %s", file.NameRelative())
		}

		return err
	},
}
View Source
var CmdMerge = &cli.Command{
	Name:  "merge",
	Usage: "merge a list of videos in a single video",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:        "name",
			Usage:       "define the name of generated video",
			DefaultText: "hash from input",
			Required:    false,
		},
	},
	Action: func(ctx *cli.Context) error {
		sources := ctx.Args().Slice()

		if len(sources) == 0 {
			return ErrorMissingSourceArgument
		}

		cfg := config.Ctx(ctx.Context)

		params, err := cfg.Merge.Apply(merge.Params{
			Sources: sources,
			Name:    ctx.String("name"),
		})
		if err != nil {
			return err
		}

		out, err := merge.Files(ctx.Context, params)

		if err == nil {
			pterm.Success.Printfln("Done: %s", out.NameRelative())
		}

		return err
	},
}
View Source
var ErrorMissingSourceArgument = errors.Business("Missing 'source' param", "DV:001")

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL