Skip to content

Commit 90e3a83

Browse files
committed
Add support to AV1 in play-from-disk
Resolves pion/rtp#190 Resolves pion/rtp#191
1 parent 24b241a commit 90e3a83

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

examples/play-from-disk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ play-from-disk demonstrates how to send video and/or audio to your browser from
44
For an example of playing H264 from disk see [play-from-disk-h264](https://github.com/pion/example-webrtc-applications/tree/master/play-from-disk-h264)
55

66
## Instructions
7-
### Create IVF named `output.ivf` that contains a VP8 track and/or `output.ogg` that contains a Opus track
7+
### Create IVF named `output.ivf` that contains a VP8/VP9/AV1 track and/or `output.ogg` that contains a Opus track
88
```
99
ffmpeg -i $INPUT_FILE -g 30 -b:v 2M output.ivf
1010
ffmpeg -i $INPUT_FILE -c:a libopus -page_duration 20000 -vn output.ogg

examples/play-from-disk/main.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,31 @@ func main() {
6161
iceConnectedCtx, iceConnectedCtxCancel := context.WithCancel(context.Background())
6262

6363
if haveVideoFile {
64+
file, openErr := os.Open(videoFileName)
65+
if openErr != nil {
66+
panic(openErr)
67+
}
68+
69+
_, header, openErr := ivfreader.NewWith(file)
70+
if openErr != nil {
71+
panic(openErr)
72+
}
73+
74+
// Determine video codec
75+
var trackCodec string
76+
switch header.FourCC {
77+
case "AV01":
78+
trackCodec = webrtc.MimeTypeAV1
79+
case "VP90":
80+
trackCodec = webrtc.MimeTypeVP9
81+
case "VP80":
82+
trackCodec = webrtc.MimeTypeVP8
83+
default:
84+
panic(fmt.Sprintf("Unable to handle FourCC %s", header.FourCC))
85+
}
86+
6487
// Create a video track
65-
videoTrack, videoTrackErr := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeVP8}, "video", "pion")
88+
videoTrack, videoTrackErr := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: trackCodec}, "video", "pion")
6689
if videoTrackErr != nil {
6790
panic(videoTrackErr)
6891
}

examples/save-to-disk-av1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ If you wish to save VP8 and Opus instead of AV1 see [save-to-disk](https://githu
55

66
If you wish to save VP8/Opus inside the same file see [save-to-webm](https://github.com/pion/example-webrtc-applications/tree/master/save-to-webm)
77

8+
You can then send this video back to your browser using [play-from-disk](https://github.com/pion/example-webrtc-applications/tree/master/play-from-disk)
9+
810
## Instructions
911
### Download save-to-disk-av1
1012
```

examples/save-to-disk/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ save-to-disk is a simple application that shows how to record your webcam/microp
33

44
If you wish to save VP8/Opus inside the same file see [save-to-webm](https://github.com/pion/example-webrtc-applications/tree/master/save-to-webm)
55

6+
If you wish to save AV1 instead see [save-to-disk-av1](https://github.com/pion/webrtc/tree/master/examples/save-to-disk-av1)
7+
8+
You can then send this video back to your browser using [play-from-disk](https://github.com/pion/example-webrtc-applications/tree/master/play-from-disk)
9+
610
## Instructions
711
### Download save-to-disk
812
```

mediaengine.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ func (m *MediaEngine) RegisterDefaultCodecs() error {
182182
PayloadType: 118,
183183
},
184184

185+
{
186+
RTPCodecCapability: RTPCodecCapability{MimeTypeAV1, 90000, 0, "", videoRTCPFeedback},
187+
PayloadType: 45,
188+
},
189+
{
190+
RTPCodecCapability: RTPCodecCapability{"video/rtx", 90000, 0, "apt=45", nil},
191+
PayloadType: 46,
192+
},
193+
185194
{
186195
RTPCodecCapability: RTPCodecCapability{"video/ulpfec", 90000, 0, "", nil},
187196
PayloadType: 116,

0 commit comments

Comments
 (0)