Skip to content

Commit

Permalink
Add support to AV1 in play-from-disk
Browse files Browse the repository at this point in the history
Resolves pion/rtp#190
Resolves pion/rtp#191
  • Loading branch information
Sean-Der committed Jul 20, 2023
1 parent 3cddada commit 8642fc4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/play-from-disk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ play-from-disk demonstrates how to send video and/or audio to your browser from
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)

## Instructions
### Create IVF named `output.ivf` that contains a VP8 track and/or `output.ogg` that contains a Opus track
### Create IVF named `output.ivf` that contains a VP8/VP9/AV1 track and/or `output.ogg` that contains a Opus track
```
ffmpeg -i $INPUT_FILE -g 30 -b:v 2M output.ivf
ffmpeg -i $INPUT_FILE -c:a libopus -page_duration 20000 -vn output.ogg
Expand Down
25 changes: 24 additions & 1 deletion examples/play-from-disk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,31 @@ func main() {
iceConnectedCtx, iceConnectedCtxCancel := context.WithCancel(context.Background())

if haveVideoFile {
file, openErr := os.Open(videoFileName)
if openErr != nil {
panic(openErr)
}

_, header, openErr := ivfreader.NewWith(file)
if openErr != nil {
panic(openErr)
}

// Determine video codec
var trackCodec string
switch header.FourCC {
case "AV01":
trackCodec = webrtc.MimeTypeAV1
case "VP90":
trackCodec = webrtc.MimeTypeVP9
case "VP80":
trackCodec = webrtc.MimeTypeVP8
default:
panic(fmt.Sprintf("Unable to handle FourCC %s", header.FourCC))
}

// Create a video track
videoTrack, videoTrackErr := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeVP8}, "video", "pion")
videoTrack, videoTrackErr := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: trackCodec}, "video", "pion")
if videoTrackErr != nil {
panic(videoTrackErr)
}
Expand Down
2 changes: 2 additions & 0 deletions examples/save-to-disk-av1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ If you wish to save VP8 and Opus instead of AV1 see [save-to-disk](https://githu

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)

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)

## Instructions
### Download save-to-disk-av1
```
Expand Down
4 changes: 4 additions & 0 deletions examples/save-to-disk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ save-to-disk is a simple application that shows how to record your webcam/microp

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)

If you wish to save AV1 instead see [save-to-disk-av1](https://github.com/pion/webrtc/tree/master/examples/save-to-disk-av1)

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)

## Instructions
### Download save-to-disk
```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/pion/logging v0.2.2
github.com/pion/randutil v0.1.0
github.com/pion/rtcp v1.2.10
github.com/pion/rtp v1.7.13
github.com/pion/rtp v1.8.0
github.com/pion/sctp v1.8.7
github.com/pion/sdp/v3 v3.0.6
github.com/pion/srtp/v2 v2.0.15
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/rtcp v1.2.10 h1:nkr3uj+8Sp97zyItdN60tE/S6vk4al5CPRR6Gejsdjc=
github.com/pion/rtcp v1.2.10/go.mod h1:ztfEwXZNLGyF1oQDttz/ZKIBaeeg/oWbRYqzBM9TL1I=
github.com/pion/rtp v1.7.13 h1:qcHwlmtiI50t1XivvoawdCGTP4Uiypzfrsap+bijcoA=
github.com/pion/rtp v1.7.13/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
github.com/pion/rtp v1.8.0 h1:SYD7040IR+NqrGBOc2GDU5iDjAR+0m5rnX/EWCUMNhw=
github.com/pion/rtp v1.8.0/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/sctp v1.8.5/go.mod h1:SUFFfDpViyKejTAdwD1d/HQsCu+V/40cCs2nZIvC3s0=
github.com/pion/sctp v1.8.7 h1:JnABvFakZueGAn4KU/4PSKg+GWbF6QWbKTWZOSGJjXw=
github.com/pion/sctp v1.8.7/go.mod h1:g1Ul+ARqZq5JEmoFy87Q/4CePtKnTJ1QCL9dBBdN6AU=
Expand Down
9 changes: 9 additions & 0 deletions mediaengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ func (m *MediaEngine) RegisterDefaultCodecs() error {
PayloadType: 118,
},

{
RTPCodecCapability: RTPCodecCapability{MimeTypeAV1, 90000, 0, "", videoRTCPFeedback},
PayloadType: 45,
},
{
RTPCodecCapability: RTPCodecCapability{"video/rtx", 90000, 0, "apt=45", nil},
PayloadType: 46,
},

{
RTPCodecCapability: RTPCodecCapability{"video/ulpfec", 90000, 0, "", nil},
PayloadType: 116,
Expand Down

0 comments on commit 8642fc4

Please sign in to comment.