admin b5c083e06f
Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
first commit
2026-06-04 18:10:52 +07:00

48 lines
980 B
Go

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
}