add option to skip converting lossy sources to lossless

This commit is contained in:
York
2025-11-02 14:01:40 +08:00
committed by GitHub
parent 7d6a02163c
commit 3af2e487b9
3 changed files with 13 additions and 4 deletions

View File

@@ -57,3 +57,6 @@ convert-keep-original: false # Keep original file after successful convers
convert-skip-if-source-matches: true # If already in target format, skip
ffmpeg-path: "ffmpeg" # Override if ffmpeg is not in PATH
convert-extra-args: "" # Additional raw args appended (advanced)
# Conversion warnings and behavior
convert-warn-lossy-to-lossless: true # If true, print a warning when converting a detected lossy source to a lossless container
convert-skip-lossy-to-lossless: true # If true, skip converting detected lossy sources to lossless target formats (flac/wav)

11
main.go
View File

@@ -707,11 +707,16 @@ func convertIfNeeded(track *task.Track) {
outBase := strings.TrimSuffix(srcPath, ext)
outPath := outBase + "." + targetFmt
// Warn about lossy -> lossless
if Config.ConvertWarnLossyToLossless && (targetFmt == "flac" || targetFmt == "wav") &&
isLossySource(ext, track.Codec) {
// Handle lossy -> lossless cases: optionally skip or warn
if (targetFmt == "flac" || targetFmt == "wav") && isLossySource(ext, track.Codec) {
if Config.ConvertSkipLossyToLossless {
fmt.Println("Skipping conversion: source appears lossy and target is lossless; configured to skip.")
return
}
if Config.ConvertWarnLossyToLossless {
fmt.Println("Warning: Converting lossy source to lossless container will not improve quality.")
}
}
if _, err := exec.LookPath(Config.FFmpegPath); err != nil {
fmt.Printf("ffmpeg not found at '%s'; skipping conversion.\n", Config.FFmpegPath)

View File

@@ -45,6 +45,7 @@ type ConfigSet struct {
FFmpegPath string `yaml:"ffmpeg-path"`
ConvertExtraArgs string `yaml:"convert-extra-args"`
ConvertWarnLossyToLossless bool `yaml:"convert-warn-lossy-to-lossless"`
ConvertSkipLossyToLossless bool `yaml:"convert-skip-lossy-to-lossless"`
}
type Counter struct {