mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
add client-read-republish example (#91)
This commit is contained in:
@@ -57,6 +57,7 @@ Features:
|
|||||||
* [client-read-h264-convert-to-jpeg](examples/client-read-h264-convert-to-jpeg/main.go)
|
* [client-read-h264-convert-to-jpeg](examples/client-read-h264-convert-to-jpeg/main.go)
|
||||||
* [client-read-h264-save-to-disk](examples/client-read-h264-save-to-disk/main.go)
|
* [client-read-h264-save-to-disk](examples/client-read-h264-save-to-disk/main.go)
|
||||||
* [client-read-aac](examples/client-read-aac/main.go)
|
* [client-read-aac](examples/client-read-aac/main.go)
|
||||||
|
* [client-read-republish](examples/client-read-republish/main.go)
|
||||||
* [client-publish-h264](examples/client-publish-h264/main.go)
|
* [client-publish-h264](examples/client-publish-h264/main.go)
|
||||||
* [client-publish-aac](examples/client-publish-aac/main.go)
|
* [client-publish-aac](examples/client-publish-aac/main.go)
|
||||||
* [client-publish-opus](examples/client-publish-opus/main.go)
|
* [client-publish-opus](examples/client-publish-opus/main.go)
|
||||||
|
@@ -19,6 +19,7 @@ import (
|
|||||||
// 2. check if there's a H264 track
|
// 2. check if there's a H264 track
|
||||||
// 3. convert H264 into raw frames
|
// 3. convert H264 into raw frames
|
||||||
// 4. encode the frames into JPEG images and save them on disk
|
// 4. encode the frames into JPEG images and save them on disk
|
||||||
|
|
||||||
// This example requires the ffmpeg libraries, that can be installed in this way:
|
// This example requires the ffmpeg libraries, that can be installed in this way:
|
||||||
// apt install -y libavformat-dev libswscale-dev gcc pkg-config
|
// apt install -y libavformat-dev libswscale-dev gcc pkg-config
|
||||||
|
|
||||||
|
@@ -13,6 +13,7 @@ import (
|
|||||||
// 1. connect to a RTSP server and read all tracks on a path
|
// 1. connect to a RTSP server and read all tracks on a path
|
||||||
// 2. check if there's an H264 track
|
// 2. check if there's an H264 track
|
||||||
// 3. convert H264 into raw frames
|
// 3. convert H264 into raw frames
|
||||||
|
|
||||||
// This example requires the ffmpeg libraries, that can be installed in this way:
|
// This example requires the ffmpeg libraries, that can be installed in this way:
|
||||||
// apt install -y libavformat-dev libswscale-dev gcc pkg-config
|
// apt install -y libavformat-dev libswscale-dev gcc pkg-config
|
||||||
|
|
||||||
|
67
examples/client-read-republish/main.go
Normal file
67
examples/client-read-republish/main.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/aler9/gortsplib"
|
||||||
|
"github.com/aler9/gortsplib/pkg/base"
|
||||||
|
"github.com/pion/rtp"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This example shows how to
|
||||||
|
// 1. connect to a RTSP server and read all tracks on a path
|
||||||
|
// 2. re-publish all tracks on another path.
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
reader := gortsplib.Client{}
|
||||||
|
|
||||||
|
// parse source URL
|
||||||
|
sourceURL, err := base.ParseURL("rtsp://localhost:8554/mystream")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// connect to the server
|
||||||
|
err = reader.Start(sourceURL.Scheme, sourceURL.Host)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer reader.Close()
|
||||||
|
|
||||||
|
// get available methods
|
||||||
|
_, err = reader.Options(sourceURL)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// find published tracks
|
||||||
|
tracks, baseURL, _, err := reader.Describe(sourceURL)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("republishing %d tracks", len(tracks))
|
||||||
|
|
||||||
|
publisher := gortsplib.Client{}
|
||||||
|
|
||||||
|
// connect to the server and start publishing
|
||||||
|
err = publisher.StartPublishing("rtsp://localhost:8554/mystream2", tracks)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer publisher.Close()
|
||||||
|
|
||||||
|
// called when a RTP packet arrives
|
||||||
|
reader.OnPacketRTP = func(trackID int, pkt *rtp.Packet) {
|
||||||
|
publisher.WritePacketRTP(trackID, pkt)
|
||||||
|
}
|
||||||
|
|
||||||
|
// start reading tracks
|
||||||
|
err = reader.SetupAndPlay(tracks, baseURL)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait until a fatal error
|
||||||
|
panic(reader.Wait())
|
||||||
|
}
|
@@ -8,8 +8,8 @@ import (
|
|||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This example shows how to
|
// This example shows how to connect to a RTSP server
|
||||||
// 1. connect to a RTSP server and read all tracks on a path
|
// and read all tracks on a path.
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := gortsplib.Client{
|
c := gortsplib.Client{
|
||||||
|
Reference in New Issue
Block a user