-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (36 loc) · 963 Bytes
/
main.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
package main
import (
"github.com/vitmod/vdk/av"
"github.com/vitmod/vdk/av/transcode"
"github.com/vitmod/vdk/format"
"github.com/vitmod/vdk/av/avutil"
"github.com/vitmod/vdk/cgo/ffmpeg"
)
// need ffmpeg with libfdkaac installed
func init() {
format.RegisterAll()
}
func main() {
infile, _ := avutil.Open("speex.flv")
findcodec := func(stream av.AudioCodecData, i int) (need bool, dec av.AudioDecoder, enc av.AudioEncoder, err error) {
need = true
dec, _ = ffmpeg.NewAudioDecoder(stream)
enc, _ = ffmpeg.NewAudioEncoderByName("libfdk_aac")
enc.SetSampleRate(stream.SampleRate())
enc.SetChannelLayout(av.CH_STEREO)
enc.SetBitrate(12000)
enc.SetOption("profile", "HE-AACv2")
return
}
trans := &transcode.Demuxer{
Options: transcode.Options{
FindAudioDecoderEncoder: findcodec,
},
Demuxer: infile,
}
outfile, _ := avutil.Create("out.ts")
avutil.CopyFile(outfile, trans)
outfile.Close()
infile.Close()
trans.Close()
}