ytva/ffmpeg.go

55 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-12-31 16:33:46 -05:00
package main
import (
ffmpeg "github.com/u2takey/ffmpeg-go"
2024-12-31 19:48:37 -05:00
"github.com/charmbracelet/log"
2024-12-31 16:33:46 -05:00
)
2024-12-31 18:59:03 -05:00
func mergeStreams(path1 string, path2 string, format string, output string) (err error) {
2024-12-31 19:48:37 -05:00
log.Debugf("Merging \"%s\" and \"%s\" to \"%s\" using format \"%s\"", path1, path2, output, format)
2024-12-31 16:33:46 -05:00
input := []*ffmpeg.Stream{ffmpeg.Input(path1), ffmpeg.Input(path2)}
2024-12-31 18:59:03 -05:00
defaultArgs := ffmpeg.KwArgs{"c:v": "copy", "c:a": "copy", "format": format}
2024-12-31 16:33:46 -05:00
var ffmpegLogLevel ffmpeg.KwArgs
var silent bool
if Flags.Verbose {
ffmpegLogLevel = ffmpeg.KwArgs{"v": "info"}
silent = false
} else if Flags.Quiet {
ffmpegLogLevel = ffmpeg.KwArgs{"v": "quiet"}
silent = true
} else {
ffmpegLogLevel = ffmpeg.KwArgs{"v": "error"}
silent = true
}
kwArgs := ffmpeg.MergeKwArgs([]ffmpeg.KwArgs{ffmpegLogLevel, defaultArgs})
return ffmpeg.Output(input, output, kwArgs).OverWriteOutput().ErrorToStdOut().Silent(silent).Run()
}
func extractAudio(path1 string, format string, output string) (err error) {
input := []*ffmpeg.Stream{ffmpeg.Input(path1)}
defaultArgs := ffmpeg.KwArgs{"map": "0:a", "c:a": "copy", "format": format}
var ffmpegLogLevel ffmpeg.KwArgs
var silent bool
if Flags.Verbose {
ffmpegLogLevel = ffmpeg.KwArgs{"v": "info"}
silent = false
} else if Flags.Quiet {
ffmpegLogLevel = ffmpeg.KwArgs{"v": "quiet"}
silent = true
} else {
ffmpegLogLevel = ffmpeg.KwArgs{"v": "error"}
silent = true
}
kwArgs := ffmpeg.MergeKwArgs([]ffmpeg.KwArgs{ffmpegLogLevel, defaultArgs})
return ffmpeg.Output(input, output, kwArgs).OverWriteOutput().ErrorToStdOut().Silent(silent).Run()
}