forked from yyoshiki41/radigo
/
output.go
74 lines (62 loc) 路 1.42 KB
/
output.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package radigo
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/yyoshiki41/radigo/internal"
)
var aacResultFile string
func initTempAACDir() (string, error) {
aacDir, err := ioutil.TempDir(radigoPath, "aac")
if err != nil {
return "", err
}
aacResultFile = filepath.Join(aacDir, "result.aac")
return aacDir, nil
}
func createConcatedAACFile(ctx context.Context, aacDir string) error {
name, err := internal.ConcatFileNames(aacDir)
if err != nil {
return err
}
f, err := newFfmpeg(ctx, fmt.Sprintf("concat:%s", name))
if err != nil {
return err
}
f.setDir(aacDir)
f.setArgs("-c", "copy")
// TODO: Run 绲愭灉銇婧栧嚭鍔涖倰鎷俱亞
return f.run(aacResultFile)
}
func output(ctx context.Context, fileType, outputFile string) error {
switch fileType {
case "mp3":
return outputMP3(ctx, outputFile)
case "aac":
return outputAAC(outputFile)
}
return fmt.Errorf("Unsupported file type: %s", fileType)
}
func outputAAC(outputFile string) error {
if err := os.Rename(aacResultFile, outputFile); err != nil {
return err
}
return nil
}
func outputMP3(ctx context.Context, outputFile string) error {
f, err := newFfmpeg(ctx, aacResultFile)
if err != nil {
return err
}
f.setDir(radigoPath)
f.setArgs(
"-c:a", "libmp3lame",
"-ac", "2",
"-q:a", "2",
"-y", // overwrite the output file without asking
)
// TODO: Run 绲愭灉銇婧栧嚭鍔涖倰鎷俱亞
return f.run(outputFile)
}