github.com/pion/webrtc/v3@v3.2.24/examples/rtp-to-webrtc/README.md (about) 1 # rtp-to-webrtc 2 rtp-to-webrtc demonstrates how to consume a RTP stream video UDP, and then send to a WebRTC client. 3 4 With this example we have pre-made GStreamer and ffmpeg pipelines, but you can use any tool you like! 5 6 ## Instructions 7 ### Download rtp-to-webrtc 8 ``` 9 export GO111MODULE=on 10 go get github.com/pion/webrtc/v3/examples/rtp-to-webrtc 11 ``` 12 13 ### Open jsfiddle example page 14 [jsfiddle.net](https://jsfiddle.net/z7ms3u5r/) you should see two text-areas and a 'Start Session' button 15 16 17 ### Run rtp-to-webrtc with your browsers SessionDescription as stdin 18 In the jsfiddle the top textarea is your browser's SessionDescription, copy that and: 19 20 #### Linux/macOS 21 Run `echo $BROWSER_SDP | rtp-to-webrtc` 22 23 #### Windows 24 1. Paste the SessionDescription into a file. 25 1. Run `rtp-to-webrtc < my_file` 26 27 ### Send RTP to listening socket 28 You can use any software to send VP8 packets to port 5004. We also have the pre made examples below 29 30 31 #### GStreamer 32 ``` 33 gst-launch-1.0 videotestsrc ! video/x-raw,width=640,height=480,format=I420 ! vp8enc error-resilient=partitions keyframe-max-dist=10 auto-alt-ref=true cpu-used=5 deadline=1 ! rtpvp8pay ! udpsink host=127.0.0.1 port=5004 34 ``` 35 36 #### ffmpeg 37 ``` 38 ffmpeg -re -f lavfi -i testsrc=size=640x480:rate=30 -vcodec libvpx -cpu-used 5 -deadline 1 -g 10 -error-resilient 1 -auto-alt-ref 1 -f rtp 'rtp://127.0.0.1:5004?pkt_size=1200' 39 ``` 40 41 If you wish to send audio replace all occurrences of `vp8` with Opus in `main.go` then run 42 43 ``` 44 ffmpeg -f lavfi -i 'sine=frequency=1000' -c:a libopus -b:a 48000 -sample_fmt s16p -ssrc 1 -payload_type 111 -f rtp -max_delay 0 -application lowdelay 'rtp://127.0.0.1:5004?pkt_size=1200' 45 ``` 46 47 If you wish to send H264 instead of VP8 replace all occurrences of `vp8` with H264 in `main.go` then run 48 49 ``` 50 ffmpeg -re -f lavfi -i testsrc=size=640x480:rate=30 -pix_fmt yuv420p -c:v libx264 -g 10 -preset ultrafast -tune zerolatency -f rtp 'rtp://127.0.0.1:5004?pkt_size=1200' 51 ``` 52 53 ### Input rtp-to-webrtc's SessionDescription into your browser 54 Copy the text that `rtp-to-webrtc` just emitted and copy into second text area 55 56 ### Hit 'Start Session' in jsfiddle, enjoy your video! 57 A video should start playing in your browser above the input boxes. 58 59 Congrats, you have used Pion WebRTC! Now start building something cool 60 61 ## Dealing with broken/lossy inputs 62 Pion WebRTC also provides a [SampleBuilder](https://pkg.go.dev/github.com/pion/webrtc/v3@v3.0.4/pkg/media/samplebuilder). This consumes RTP packets and returns samples. 63 It can be used to re-order and delay for lossy streams. You can see its usage in this example in [daf27b](https://github.com/pion/webrtc/commit/daf27bd0598233b57428b7809587ec3c09510413). 64 65 Currently it isn't working with H264, but is useful for VP8 and Opus. See [#1652](https://github.com/pion/webrtc/issues/1652) for the status of fixing for H264.