From 040331c05980d89f20d32fa72bfe34ef8c0b82d7 Mon Sep 17 00:00:00 2001 From: nareix Date: Sat, 16 Jul 2016 13:26:54 +0800 Subject: [PATCH] add audio_decode.go --- examples/audio_decode.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/audio_decode.go diff --git a/examples/audio_decode.go b/examples/audio_decode.go new file mode 100644 index 0000000..99594be --- /dev/null +++ b/examples/audio_decode.go @@ -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() +} +