Logan G
7c72c89950
Let's you extract audio from combined video+audio media (most websites supported by yt-dlp)
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
ffmpeg "github.com/u2takey/ffmpeg-go"
|
|
"github.com/charmbracelet/log"
|
|
)
|
|
|
|
func mergeStreams(path1 string, path2 string, format string, output string) (err error) {
|
|
log.Debugf("Merging \"%s\" and \"%s\" to \"%s\" using format \"%s\"", path1, path2, output, format)
|
|
input := []*ffmpeg.Stream{ffmpeg.Input(path1), ffmpeg.Input(path2)}
|
|
|
|
defaultArgs := ffmpeg.KwArgs{"c:v": "copy", "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()
|
|
}
|
|
|
|
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()
|
|
}
|