mirror of
https://github.com/kerberos-io/joy4.git
synced 2025-12-24 13:57:59 +08:00
add audio_decode.go
This commit is contained in:
40
examples/audio_decode.go
Normal file
40
examples/audio_decode.go
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/nareix/joy4/av"
|
||||
"github.com/nareix/joy4/format"
|
||||
"github.com/nareix/joy4/av/avutil"
|
||||
"github.com/nareix/joy4/cgo/ffmpeg"
|
||||
)
|
||||
|
||||
// need ffmpeg installed
|
||||
|
||||
func init() {
|
||||
format.RegisterAll()
|
||||
}
|
||||
|
||||
func main() {
|
||||
file, _ := avutil.Open("projectindex.flv")
|
||||
streams, _ := file.Streams()
|
||||
var dec *ffmpeg.AudioDecoder
|
||||
|
||||
for _, stream := range streams {
|
||||
if stream.Type() == av.AAC {
|
||||
dec, _ = ffmpeg.NewAudioDecoder(stream.(av.AudioCodecData))
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
pkt, _ := file.ReadPacket()
|
||||
if streams[pkt.Idx].Type() == av.AAC {
|
||||
ok, frame, _ := dec.Decode(pkt.Data)
|
||||
if ok {
|
||||
println("decode samples", frame.SampleCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user