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 24b241a commit 38fd93f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 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
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 38fd93f

Please sign in to comment.