Skip to content

Commit cc0c966

Browse files
authored
improve examples (#778)
1 parent 4e3c5e6 commit cc0c966

File tree

55 files changed

+494
-435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+494
-435
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ Features:
9595
* [server](examples/server/main.go)
9696
* [server-tls](examples/server-tls/main.go)
9797
* [server-auth](examples/server-auth/main.go)
98-
* [server-h264-to-disk](examples/server-h264-to-disk/main.go)
99-
* [server-h264-from-disk](examples/server-h264-from-disk/main.go)
98+
* [server-record-format-h264-to-disk](examples/server-record-format-h264-to-disk/main.go)
99+
* [server-play-format-h264-from-disk](examples/server-play-format-h264-from-disk/main.go)
100100
* [proxy](examples/proxy/main.go)
101101

102102
## API Documentation

examples/client-play-backchannel/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
)
1414

1515
// This example shows how to
16-
// 1. generate a dummy G711 audio stream
17-
// 2. connect to a RTSP server, find a back channel that supports G711
18-
// 3. route the G711 stream to the channel
16+
// 1. generate a dummy G711 audio stream.
17+
// 2. connect to a RTSP server, find a back channel that supports G711.
18+
// 3. route the G711 stream to the channel.
1919

2020
func multiplyAndDivide(v, m, d int64) int64 {
2121
secs := v / d
@@ -72,7 +72,7 @@ func main() {
7272
// find the back channel
7373
medi, forma := findG711BackChannel(desc)
7474
if medi == nil {
75-
panic("media not found")
75+
panic("back channel not found")
7676
}
7777

7878
// setup a single media
@@ -137,7 +137,7 @@ func main() {
137137
for _, pkt := range pkts {
138138
pkt.Timestamp += uint32(int64(randomStart) + prevPTS)
139139

140-
err = c.WritePacketRTP(desc.Medias[0], pkt)
140+
err = c.WritePacketRTP(medi, pkt)
141141
if err != nil {
142142
panic(err)
143143
}

examples/client-play-format-av1-to-jpeg/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
)
2020

2121
// This example shows how to
22-
// 1. connect to a RTSP server
23-
// 2. check if there's a AV1 stream
24-
// 3. decode the AV1 stream into RGBA frames
25-
// 4. convert RGBA frames to JPEG images and save them on disk
22+
// 1. connect to a RTSP server.
23+
// 2. check if there's a AV1 stream.
24+
// 3. decode the AV1 stream into RGBA frames.
25+
// 4. convert RGBA frames to JPEG images and save them on disk.
2626

2727
// This example requires the FFmpeg libraries, that can be installed with this command:
2828
// apt install -y libavcodec-dev libswscale-dev gcc pkg-config

examples/client-play-format-av1/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
)
1515

1616
// This example shows how to
17-
// 1. connect to a RTSP server
18-
// 2. check if there's a AV1 stream
19-
// 3. decode the AV1 stream into RGBA frames
17+
// 1. connect to a RTSP server.
18+
// 2. check if there's a AV1 stream.
19+
// 3. decode the AV1 stream into RGBA frames.
2020

2121
// This example requires the FFmpeg libraries, that can be installed with this command:
2222
// apt install -y libavcodec-dev libswscale-dev gcc pkg-config

examples/client-play-format-g711/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
// This example shows how to
14-
// 1. connect to a RTSP server
15-
// 2. check if there's a G711 stream
16-
// 3. decode the G711 stream into audio samples
14+
// 1. connect to a RTSP server.
15+
// 2. check if there's a G711 stream.
16+
// 3. decode the G711 stream into audio samples.
1717

1818
func main() {
1919
c := gortsplib.Client{}

examples/client-play-format-h264-mpeg4audio-to-disk/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
// This example shows how to
14-
// 1. connect to a RTSP server
15-
// 2. check if there's a H264 stream and a MPEG-4 audio stream
16-
// 3. save the content of those formats in a file in MPEG-TS format
14+
// 1. connect to a RTSP server.
15+
// 2. check if there's a H264 stream and a MPEG-4 audio stream.
16+
// 3. save the content of those formats in a file in MPEG-TS format.
1717

1818
func main() {
1919
c := gortsplib.Client{}

examples/client-play-format-h264-mpeg4audio-to-disk/mpegts_muxer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ func (e *mpegtsMuxer) initialize() error {
5050
},
5151
}
5252

53-
e.w = mpegts.NewWriter(e.b, []*mpegts.Track{e.h264Track, e.mpeg4AudioTrack})
53+
e.w = &mpegts.Writer{W: e.b, Tracks: []*mpegts.Track{e.h264Track, e.mpeg4AudioTrack}}
54+
err = e.w.Initialize()
55+
if err != nil {
56+
return err
57+
}
5458

5559
return nil
5660
}

examples/client-play-format-h264-to-disk/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
// This example shows how to
14-
// 1. connect to a RTSP server
15-
// 2. check if there's a H264 stream
16-
// 3. save the content of the format in a file in MPEG-TS format
14+
// 1. connect to a RTSP server.
15+
// 2. check if there's a H264 stream.
16+
// 3. save the content of the format in a file in MPEG-TS format.
1717

1818
func main() {
1919
c := gortsplib.Client{}

examples/client-play-format-h264-to-disk/mpegts_muxer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ func (e *mpegtsMuxer) initialize() error {
3434
Codec: &mpegts.CodecH264{},
3535
}
3636

37-
e.w = mpegts.NewWriter(e.b, []*mpegts.Track{e.track})
37+
e.w = &mpegts.Writer{W: e.b, Tracks: []*mpegts.Track{e.track}}
38+
err = e.w.Initialize()
39+
if err != nil {
40+
return err
41+
}
3842

3943
return nil
4044
}

examples/client-play-format-h264-to-jpeg/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
)
2020

2121
// This example shows how to
22-
// 1. connect to a RTSP server
23-
// 2. check if there's a H264 stream
24-
// 3. decode the H264 stream into RGBA frames
25-
// 4. convert RGBA frames to JPEG images and save them on disk
22+
// 1. connect to a RTSP server.
23+
// 2. check if there's a H264 stream.
24+
// 3. decode the H264 stream into RGBA frames.
25+
// 4. convert RGBA frames to JPEG images and save them on disk.
2626

2727
// This example requires the FFmpeg libraries, that can be installed with this command:
2828
// apt install -y libavcodec-dev libswscale-dev gcc pkg-config

examples/client-play-format-h264/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
)
1515

1616
// This example shows how to
17-
// 1. connect to a RTSP server
18-
// 2. check if there's an H264 stream
19-
// 3. decode the H264 stream into RGBA frames
17+
// 1. connect to a RTSP server.
18+
// 2. check if there's an H264 stream.
19+
// 3. decode the H264 stream into RGBA frames.
2020

2121
// This example requires the FFmpeg libraries, that can be installed with this command:
2222
// apt install -y libavcodec-dev libswscale-dev gcc pkg-config

examples/client-play-format-h265-to-disk/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
// This example shows how to
14-
// 1. connect to a RTSP server
15-
// 2. check if there's a H265 stream
16-
// 3. save the content of the format in a file in MPEG-TS format
14+
// 1. connect to a RTSP server.
15+
// 2. check if there's a H265 stream.
16+
// 3. save the content of the format in a file in MPEG-TS format.
1717

1818
func main() {
1919
c := gortsplib.Client{}

examples/client-play-format-h265-to-disk/mpegts_muxer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ func (e *mpegtsMuxer) initialize() error {
3535
Codec: &mpegts.CodecH265{},
3636
}
3737

38-
e.w = mpegts.NewWriter(e.b, []*mpegts.Track{e.track})
38+
e.w = &mpegts.Writer{W: e.b, Tracks: []*mpegts.Track{e.track}}
39+
err = e.w.Initialize()
40+
if err != nil {
41+
return err
42+
}
3943

4044
return nil
4145
}

examples/client-play-format-h265-to-jpeg/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
)
2020

2121
// This example shows how to
22-
// 1. connect to a RTSP server
23-
// 2. check if there's a H265 stream
24-
// 3. decode the H265 stream into RGBA frames
25-
// 4. convert RGBA frames to JPEG images and save them on disk
22+
// 1. connect to a RTSP server.
23+
// 2. check if there's a H265 stream.
24+
// 3. decode the H265 stream into RGBA frames.
25+
// 4. convert RGBA frames to JPEG images and save them on disk.
2626

2727
// This example requires the FFmpeg libraries, that can be installed with this command:
2828
// apt install -y libavcodec-dev libswscale-dev gcc pkg-config

examples/client-play-format-h265/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
)
1515

1616
// This example shows how to
17-
// 1. connect to a RTSP server
18-
// 2. check if there's a H265 stream
19-
// 3. decode the H265 stream into RGBA frames
17+
// 1. connect to a RTSP server.
18+
// 2. check if there's a H265 stream.
19+
// 3. decode the H265 stream into RGBA frames.
2020

2121
// This example requires the FFmpeg libraries, that can be installed with this command:
2222
// apt install -y libavcodec-dev libswscale-dev gcc pkg-config

examples/client-play-format-lpcm/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
)
1111

1212
// This example shows how to
13-
// 1. connect to a RTSP server
14-
// 2. check if there's a LPCM stream
15-
// 3. get LPCM samples of that format
13+
// 1. connect to a RTSP server.
14+
// 2. check if there's a LPCM stream.
15+
// 3. get LPCM samples of that format.
1616

1717
func main() {
1818
c := gortsplib.Client{}

examples/client-play-format-mjpeg/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
)
1414

1515
// This example shows how to
16-
// 1. connect to a RTSP server
17-
// 2. check if there's a M-JPEG stream
18-
// 3. get JPEG images of that format
19-
// 4. decode JPEG images into RGBA frames
16+
// 1. connect to a RTSP server.
17+
// 2. check if there's a M-JPEG stream.
18+
// 3. get JPEG images of that format.
19+
// 4. decode JPEG images into RGBA frames.
2020

2121
func main() {
2222
c := gortsplib.Client{}

examples/client-play-format-mpeg4audio-to-disk/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
// This example shows how to
14-
// 1. connect to a RTSP server
15-
// 2. check if there's a MPEG-4 audio stream
16-
// 3. save the content of the format in a file in MPEG-TS format
14+
// 1. connect to a RTSP server.
15+
// 2. check if there's a MPEG-4 audio stream.
16+
// 3. save the content of the format in a file in MPEG-TS format.
1717

1818
func main() {
1919
c := gortsplib.Client{}

examples/client-play-format-mpeg4audio-to-disk/mpegts_muxer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ func (e *mpegtsMuxer) initialize() error {
3434
}
3535
e.b = bufio.NewWriter(e.f)
3636

37-
e.w = mpegts.NewWriter(e.b, []*mpegts.Track{e.track})
37+
e.w = &mpegts.Writer{W: e.b, Tracks: []*mpegts.Track{e.track}}
38+
err = e.w.Initialize()
39+
if err != nil {
40+
return err
41+
}
3842

3943
return nil
4044
}

examples/client-play-format-mpeg4audio/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
)
1111

1212
// This example shows how to
13-
// 1. connect to a RTSP server
14-
// 2. check if there's a MPEG-4 audio stream
15-
// 3. get access units of that format
13+
// 1. connect to a RTSP server.
14+
// 2. check if there's a MPEG-4 audio stream.
15+
// 3. get access units of that format.
1616

1717
func main() {
1818
c := gortsplib.Client{}

examples/client-play-format-opus-to-disk/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
// This example shows how to
14-
// 1. connect to a RTSP server
15-
// 2. check if there's a Opus stream
16-
// 3. save the content of the format in a file in MPEG-TS format
14+
// 1. connect to a RTSP server.
15+
// 2. check if there's a Opus stream.
16+
// 3. save the content of the format in a file in MPEG-TS format.
1717

1818
func main() {
1919
c := gortsplib.Client{}

examples/client-play-format-opus-to-disk/mpegts_muxer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ func (e *mpegtsMuxer) initialize() error {
3434
}
3535
e.b = bufio.NewWriter(e.f)
3636

37-
e.w = mpegts.NewWriter(e.b, []*mpegts.Track{e.track})
37+
e.w = &mpegts.Writer{W: e.b, Tracks: []*mpegts.Track{e.track}}
38+
err = e.w.Initialize()
39+
if err != nil {
40+
return err
41+
}
3842

3943
return nil
4044
}

examples/client-play-format-opus/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
)
1111

1212
// This example shows how to
13-
// 1. connect to a RTSP server
14-
// 2. check if there's an Opus stream
15-
// 3. get Opus packets of that format
13+
// 1. connect to a RTSP server.
14+
// 2. check if there's an Opus stream.
15+
// 3. get Opus packets of that format.
1616

1717
func main() {
1818
c := gortsplib.Client{}

examples/client-play-format-vp8/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
)
1414

1515
// This example shows how to
16-
// 1. connect to a RTSP server
17-
// 2. check if there's a VP8 stream
18-
// 3. decode the VP8 stream into RGBA frames
16+
// 1. connect to a RTSP server.
17+
// 2. check if there's a VP8 stream.
18+
// 3. decode the VP8 stream into RGBA frames.
1919

2020
// This example requires the FFmpeg libraries, that can be installed with this command:
2121
// apt install -y libavcodec-dev libswscale-dev gcc pkg-config

examples/client-play-format-vp9/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
)
1414

1515
// This example shows how to
16-
// 1. connect to a RTSP server
17-
// 2. check if there's a VP9 stream
18-
// 3. decode the VP9 stream into RGBA frames
16+
// 1. connect to a RTSP server.
17+
// 2. check if there's a VP9 stream.
18+
// 3. decode the VP9 stream into RGBA frames.
1919

2020
// This example requires the FFmpeg libraries, that can be installed with this command:
2121
// apt install -y libavcodec-dev libswscale-dev gcc pkg-config

examples/client-play-options/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
)
1414

1515
// This example shows how to
16-
// 1. set additional client options
17-
// 2. connect to a RTSP server and read all medias on a path
16+
// 1. set additional client options.
17+
// 2. connect to a RTSP server and read all medias on a path.
1818

1919
func main() {
2020
// Client allows to set additional client options

examples/client-play-pause/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
)
1414

1515
// This example shows how to
16-
// 1. connect to a RTSP server and read all medias on a path
17-
// 2. wait for 5 seconds
18-
// 3. pause for 5 seconds
19-
// 4. repeat
16+
// 1. connect to a RTSP server and read all medias on a path.
17+
// 2. wait for 5 seconds.
18+
// 3. pause for 5 seconds.
19+
// 4. repeat.
2020

2121
func main() {
2222
c := gortsplib.Client{}

examples/client-play-timestamp/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
// This example shows how to
14-
// 1. connect to a RTSP server
15-
// 2. read all media streams on a path
16-
// 3. Get the PTS and NTP timestamp of incoming RTP packets
14+
// 1. connect to a RTSP server.
15+
// 2. read all media streams on a path.
16+
// 3. Get the PTS and NTP timestamp of incoming RTP packets.
1717

1818
func main() {
1919
c := gortsplib.Client{}

examples/client-play-to-record/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
// This example shows how to
14-
// 1. connect to a RTSP server
15-
// 2. read all medias on a path
14+
// 1. connect to a RTSP server.
15+
// 2. read all medias on a path.
1616
// 3. re-publish all medias on another path.
1717

1818
func main() {

0 commit comments

Comments
 (0)