mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 07:37:07 +08:00
add client-read-format-av1 example (#399)
This commit is contained in:
@@ -58,6 +58,7 @@ Features:
|
|||||||
* [client-read-options](examples/client-read-options/main.go)
|
* [client-read-options](examples/client-read-options/main.go)
|
||||||
* [client-read-pause](examples/client-read-pause/main.go)
|
* [client-read-pause](examples/client-read-pause/main.go)
|
||||||
* [client-read-republish](examples/client-read-republish/main.go)
|
* [client-read-republish](examples/client-read-republish/main.go)
|
||||||
|
* [client-read-format-av1](examples/client-read-format-av1/main.go)
|
||||||
* [client-read-format-g711](examples/client-read-format-g711/main.go)
|
* [client-read-format-g711](examples/client-read-format-g711/main.go)
|
||||||
* [client-read-format-g722](examples/client-read-format-g722/main.go)
|
* [client-read-format-g722](examples/client-read-format-g722/main.go)
|
||||||
* [client-read-format-h264](examples/client-read-format-h264/main.go)
|
* [client-read-format-h264](examples/client-read-format-h264/main.go)
|
||||||
|
88
examples/client-read-format-av1/main.go
Normal file
88
examples/client-read-format-av1/main.go
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/bluenviron/gortsplib/v4"
|
||||||
|
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||||
|
"github.com/bluenviron/gortsplib/v4/pkg/format/rtpvp9"
|
||||||
|
"github.com/bluenviron/gortsplib/v4/pkg/url"
|
||||||
|
"github.com/pion/rtp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This example shows how to
|
||||||
|
// 1. connect to a RTSP server
|
||||||
|
// 2. check if there's a AV1 media
|
||||||
|
// 3. get access units of that media
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
c := gortsplib.Client{}
|
||||||
|
|
||||||
|
// parse URL
|
||||||
|
u, err := url.Parse("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 published medias
|
||||||
|
desc, _, err := c.Describe(u)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the AV1 media and format
|
||||||
|
var forma *format.AV1
|
||||||
|
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 AV1 temporal units from RTP packets
|
||||||
|
tu, err := rtpDec.Decode(pkt)
|
||||||
|
if err != nil {
|
||||||
|
if err != rtpvp9.ErrNonStartingPacketAndNoPrevious && err != rtpvp9.ErrMorePacketsNeeded {
|
||||||
|
log.Printf("ERR: %v", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("received temporal unit with PTS %v and size %d\n", pts, len(tu))
|
||||||
|
})
|
||||||
|
|
||||||
|
// start playing
|
||||||
|
_, err = c.Play(nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait until a fatal error
|
||||||
|
panic(c.Wait())
|
||||||
|
}
|
@@ -60,6 +60,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,6 +60,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,6 +60,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -64,6 +64,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,6 +66,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,6 +60,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,6 +60,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,6 +61,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,6 +61,7 @@ func main() {
|
|||||||
// decode timestamp
|
// decode timestamp
|
||||||
pts, ok := c.PacketPTS(medi, pkt)
|
pts, ok := c.PacketPTS(medi, pkt)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
log.Printf("waiting for timestamp")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user