mirror of
https://github.com/aler9/gortsplib
synced 2025-12-24 13:38:08 +08:00
update VP8/VP9 examples to decode/encode frames (#704)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -12,8 +14,11 @@ import (
|
||||
|
||||
// This example shows how to
|
||||
// 1. connect to a RTSP server
|
||||
// 2. check if there's a VP9 format
|
||||
// 3. get access units of that format
|
||||
// 2. check if there's an VP9 format
|
||||
// 3. decode the VP9 stream into RGBA frames
|
||||
|
||||
// This example requires the FFmpeg libraries, that can be installed with this command:
|
||||
// apt install -y libavformat-dev libswscale-dev gcc pkg-config
|
||||
|
||||
func main() {
|
||||
c := gortsplib.Client{}
|
||||
@@ -44,12 +49,20 @@ func main() {
|
||||
panic("media not found")
|
||||
}
|
||||
|
||||
// create decoder
|
||||
// setup RTP -> VP9 decoder
|
||||
rtpDec, err := forma.CreateDecoder()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// setup VP9 -> RGBA decoder
|
||||
vp9Dec := &vp9Decoder{}
|
||||
err = vp9Dec.initialize()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer vp9Dec.close()
|
||||
|
||||
// setup a single media
|
||||
_, err = c.Setup(desc.BaseURL, medi, 0, 0)
|
||||
if err != nil {
|
||||
@@ -65,8 +78,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// extract VP9 frames from RTP packets
|
||||
vf, err := rtpDec.Decode(pkt)
|
||||
// extract access units from RTP packets
|
||||
au, err := rtpDec.Decode(pkt)
|
||||
if err != nil {
|
||||
if err != rtpvp9.ErrNonStartingPacketAndNoPrevious && err != rtpvp9.ErrMorePacketsNeeded {
|
||||
log.Printf("ERR: %v", err)
|
||||
@@ -74,7 +87,18 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("received frame with PTS %v and size %d\n", pts, len(vf))
|
||||
// convert VP9 access units into RGBA frames
|
||||
img, err := vp9Dec.decode(au)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// wait for a frame
|
||||
if img == nil {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("decoded frame with PTS %v and size %v", pts, img.Bounds().Max)
|
||||
})
|
||||
|
||||
// start playing
|
||||
|
||||
Reference in New Issue
Block a user