-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.go
56 lines (47 loc) · 1002 Bytes
/
converter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package radikocast
import (
"context"
"fmt"
)
type Converter interface {
Convert(ctx context.Context, input, output string) error
}
func NewConverter(format string) (Converter, error) {
switch format {
case AudioFormatM4A:
return &ConverterM4A{}, nil
case AudioFormatMP3:
return &ConverterMP3{}, nil
default:
return nil, fmt.Errorf("Bad format: %s", format)
}
}
type ConverterMP3 struct {
}
func (c *ConverterMP3) Convert(ctx context.Context, input, output string) error {
f, err := newFfmpeg(ctx)
if err != nil {
return err
}
f.setInput(input)
f.setArgs(
"-c:a", "libmp3lame",
"-q:a", "2",
"-y", // overwrite the output file without asking
)
return f.run(output)
}
type ConverterM4A struct {
}
func (c *ConverterM4A) Convert(ctx context.Context, input, output string) error {
f, err := newFfmpeg(ctx)
if err != nil {
return err
}
f.setInput(input)
f.setArgs(
"-c:a", "copy",
"-y", // overwrite the output file without asking
)
return f.run(output)
}