remux

package
v1.8.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package remux provides a command for remuxing a mpegts to another container.

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:      "remux",
	Usage:     "Remux a mpegts to another container.",
	ArgsUsage: "file",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:        "output-format",
			Value:       "mp4",
			Usage:       "Output format of the container.",
			Aliases:     []string{"format", "f"},
			Destination: &outputFormat,
		},
		&cli.BoolFlag{
			Name:        "extract-audio",
			Value:       false,
			Usage:       "Generate an audio-only copy of the stream.",
			Aliases:     []string{"x"},
			Destination: &extractAudio,
		},
	},
	Action: func(cCtx *cli.Context) error {
		ctx := cCtx.Context
		file := cCtx.Args().Get(0)
		if file == "" {
			log.Error().Msg("arg[0] is empty")
			return errors.New("missing file path")
		}

		if _, err := os.Stat(file); err != nil {
			return err
		}

		fnameMuxed := prepareFile(file, strings.ToLower(outputFormat))
		fnameAudio := prepareFile(file, "m4a")

		log.Info().Str("output", fnameMuxed).Str("input", file).Msg("remuxing stream...")
		if err := remux.Do(ctx, fnameMuxed, file); err != nil {
			log.Error().
				Str("output", fnameMuxed).
				Str("input", file).
				Err(err).
				Msg("ffmpeg remux finished with error")
		}
		if extractAudio {
			log.Error().Str("output", fnameAudio).Str("input", file).Msg("extrating audio...")
			if err := remux.Do(ctx, fnameAudio, file, remux.WithAudioOnly()); err != nil {
				log.Error().
					Str("output", fnameAudio).
					Str("input", file).
					Err(err).
					Msg("ffmpeg audio extract finished with error")
			}
		}
		return nil
	},
}

Command is the command for remuxing a mpegts to another container.

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