Use x264 instead of vp8 for rtp example

This commit is contained in:
Lukas Herman
2020-11-07 21:04:26 -08:00
parent a73b1922ed
commit 8dd84b269c
3 changed files with 19 additions and 9 deletions

View File

@@ -1,5 +1,14 @@
## Instructions
### Install required codecs
In this example, we'll be using x264 and opus as our video and audio codecs. Therefore, we need to make sure that these codecs are installed within our system.
Installation steps:
* [x264](https://github.com/pion/mediadevices#x264)
* [opus](https://github.com/pion/mediadevices#opus)
### Download rtpexample
```
@@ -10,13 +19,13 @@ go get github.com/pion/mediadevices/examples/rtp
Install GStreamer and run:
```
gst-launch-1.0 udpsrc port=5000 caps=application/x-rtp,encode-name=VP8 \
! rtpvp8depay ! vp8dec ! videoconvert ! autovideosink
gst-launch-1.0 udpsrc port=5000 caps=application/x-rtp,encode-name=H264 \
! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink
```
Or run VLC media plyer:
```
vlc ./vp8.sdp
vlc ./h264.sdp
```
### Run rtp

View File

@@ -6,4 +6,4 @@ c=IN IP4 0.0.0.0
t=0 0
a=recvonly
m=video 5000 RTP/AVP 100
a=rtpmap:100 VP8/90000
a=rtpmap:100 H264/90000

View File

@@ -6,7 +6,7 @@ import (
"os"
"github.com/pion/mediadevices"
"github.com/pion/mediadevices/pkg/codec/vpx" // This is required to use VP8/VP9 video encoder
"github.com/pion/mediadevices/pkg/codec/x264" // This is required to use H264 video encoder
_ "github.com/pion/mediadevices/pkg/driver/camera" // This is required to register camera adapter
"github.com/pion/mediadevices/pkg/frame"
"github.com/pion/mediadevices/pkg/prop"
@@ -29,12 +29,13 @@ func main() {
}
dest := os.Args[1]
vp8Params, err := vpx.NewVP8Params()
x264Params, err := x264.NewParams()
must(err)
vp8Params.BitRate = 100000 // 100kbps
x264Params.Preset = x264.PresetMedium
x264Params.BitRate = 1_000_000 // 1mbps
codecSelector := mediadevices.NewCodecSelector(
mediadevices.WithVideoEncoders(&vp8Params),
mediadevices.WithVideoEncoders(&x264Params),
)
mediaStream, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
@@ -50,7 +51,7 @@ func main() {
videoTrack := mediaStream.GetVideoTracks()[0]
defer videoTrack.Close()
rtpReader, err := videoTrack.NewRTPReader(vp8Params.RTPCodec().Name, mtu)
rtpReader, err := videoTrack.NewRTPReader(x264Params.RTPCodec().Name, mtu)
must(err)
addr, err := net.ResolveUDPAddr("udp", dest)