Skip to content

Commit cf7b204

Browse files
author
Rain Liu
committed
add play-from-disk-264 example (WIP: need to update RTP h264 payloader to align with pion rtp 1.7.1)
1 parent 414ea6e commit cf7b204

File tree

7 files changed

+415
-12
lines changed

7 files changed

+415
-12
lines changed

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ rtcp = "0.4.1"
2424
srtp = { package = "webrtc-srtp", version = "0.5.0" }
2525
sctp = { package = "webrtc-sctp", version = "0.3.8" }
2626
data = { package = "webrtc-data", version = "0.2.8" }
27-
media = { package = "webrtc-media", version = "0.2.0" }
27+
media = { package = "webrtc-media", version = "0.2.1" }
2828
interceptor = "0.2.3"
2929
tokio = { version = "1.12.0", features = ["full"] }
3030
log = "0.4.14"
@@ -107,6 +107,11 @@ name = "play-from-disk-vp9"
107107
path = "examples/play-from-disk-vp9/play-from-disk-vp9.rs"
108108
bench = false
109109

110+
[[example]]
111+
name = "play-from-disk-h264"
112+
path = "examples/play-from-disk-h264/play-from-disk-h264.rs"
113+
bench = false
114+
110115
[[example]]
111116
name = "play-from-disk-renegotiation"
112117
path = "examples/play-from-disk-renegotiation/play-from-disk-renegotiation.rs"

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All examples are ported from [Pion](https://github.com/pion/webrtc/tree/master/e
88
- [x] [Reflect](reflect): The reflect example demonstrates how to have webrtc-rs send back to the user exactly what it receives using the same PeerConnection.
99
- [x] [Play from Disk VP8](play-from-disk-vp8): The play-from-disk-vp8 example demonstrates how to send VP8 video to your browser from a file saved to disk.
1010
- [x] [Play from Disk VP9](play-from-disk-vp9): The play-from-disk-vp9 example demonstrates how to send VP9 video to your browser from a file saved to disk.
11+
- [ ] [Play from Disk H264](play-from-disk-h264): The play-from-disk-h264 example demonstrates how to send H264 video to your browser from a file saved to disk.
1112
- [x] [Play from Disk Renegotiation](play-from-disk-renegotiation): The play-from-disk-renegotiation example is an extension of the play-from-disk example, but demonstrates how you can add/remove video tracks from an already negotiated PeerConnection.
1213
- [x] [Insertable Streams](insertable-streams): The insertable-streams example demonstrates how webrtc-rs can be used to send E2E encrypted video and decrypt via insertable streams in the browser.
1314
- [x] [Save to Disk](save-to-disk): The save-to-disk example shows how to record your webcam and save the footage to disk on the server side.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# play-from-disk-h264
2+
play-from-disk-h264 demonstrates how to send h264 video and/or audio to your browser from files saved to disk.
3+
4+
## Instructions
5+
### Create IVF named `output.264` that contains a H264 track and/or `output.ogg` that contains a Opus track
6+
```
7+
ffmpeg -i $INPUT_FILE -an -c:v libx264 -bsf:v h264_mp4toannexb -b:v 2M -max_delay 0 -bf 0 output.h264
8+
ffmpeg -i $INPUT_FILE -c:a libopus -page_duration 20000 -vn output.ogg
9+
```
10+
11+
### Build play-from-disk-h264
12+
```
13+
cargo build --example play-from-disk-h264
14+
```
15+
16+
### Open play-from-disk-h264 example page
17+
[jsfiddle.net](https://jsfiddle.net/9s10amwL/) you should see two text-areas and a 'Start Session' button
18+
19+
### Run play-from-disk-h264 with your browsers SessionDescription as stdin
20+
The `output.h264` you created should be in the same directory as `play-from-disk-h264`. In the jsfiddle the top textarea is your browser, copy that and:
21+
22+
#### Linux/macOS
23+
Run `echo $BROWSER_SDP | ./target/debug/examples/play-from-disk-h264 -v output.h264 -a output.ogg`
24+
#### Windows
25+
1. Paste the SessionDescription into a file.
26+
1. Run `./target/debug/examples/play-from-disk-h264 -v output.h264 -a output.ogg < my_file`
27+
28+
### Input play-from-disk-h264's SessionDescription into your browser
29+
Copy the text that `play-from-disk-h264` just emitted and copy into second text area
30+
31+
### Hit 'Start Session' in jsfiddle, enjoy your video!
32+
A video should start playing in your browser above the input boxes. `play-from-disk-h264` will exit when the file reaches the end
33+
34+
Congrats, you have used WebRTC.rs!

0 commit comments

Comments
 (0)