package transcode import ( "fmt" "path/filepath" "strings" ) const ( FormatWAV = "wav" FormatPCM = "pcm" ) type FormatSpec struct { ID string Extension string Codec string } var formats = map[string]FormatSpec{ FormatWAV: {ID: FormatWAV, Extension: ".wav", Codec: "pcm_s16le"}, FormatPCM: {ID: FormatPCM, Extension: ".wav", Codec: "pcm_s16le"}, } func ResolveFormat(name string) (FormatSpec, error) { name = strings.ToLower(strings.TrimSpace(name)) if name == "" { name = FormatWAV } spec, ok := formats[name] if !ok { return FormatSpec{}, fmt.Errorf("unsupported format %q (supported: wav)", name) } return spec, nil } func OutputPath(dst, format string) (string, error) { spec, err := ResolveFormat(format) if err != nil { return "", err } ext := filepath.Ext(dst) if ext == "" { return dst + spec.Extension, nil } return dst, nil }