1 Star 0 Fork 0

我还是我 / gortsplib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"log"
"github.com/bluenviron/gortsplib/v4"
"github.com/bluenviron/gortsplib/v4/pkg/base"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/pion/rtp"
)
// This example shows how to
// 1. connect to a RTSP server
// 2. check if there's a G722 format
// 3. get G722 frames of that format
func main() {
c := gortsplib.Client{}
// parse URL
u, err := base.ParseURL("rtsp://localhost:8554/mystream")
if err != nil {
panic(err)
}
// connect to the server
err = c.Start(u.Scheme, u.Host)
if err != nil {
panic(err)
}
defer c.Close()
// find available medias
desc, _, err := c.Describe(u)
if err != nil {
panic(err)
}
// find the G722 media and format
var forma *format.G722
medi := desc.FindFormat(&forma)
if medi == nil {
panic("media not found")
}
// create decoder
rtpDec, err := forma.CreateDecoder()
if err != nil {
panic(err)
}
// setup a single media
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
if err != nil {
panic(err)
}
// called when a RTP packet arrives
c.OnPacketRTP(medi, forma, func(pkt *rtp.Packet) {
// decode timestamp
pts, ok := c.PacketPTS(medi, pkt)
if !ok {
log.Printf("waiting for timestamp")
return
}
// extract G722 frames from RTP packets
op, err := rtpDec.Decode(pkt)
if err != nil {
log.Printf("ERR: %v", err)
return
}
// print
log.Printf("received G722 frame with PTS %v size %d\n", pts, len(op))
})
// start playing
_, err = c.Play(nil)
if err != nil {
panic(err)
}
// wait until a fatal error
panic(c.Wait())
}
Go
1
https://gitee.com/likunde_admin/gortsplib.git
git@gitee.com:likunde_admin/gortsplib.git
likunde_admin
gortsplib
gortsplib
main

搜索帮助