Overview
TheMediaEngine defines the codecs and RTP capabilities supported by a PeerConnection. It controls which audio and video codecs are negotiated, which RTP header extensions are enabled, and which RTCP feedback mechanisms are available.
By default, Pion WebRTC includes a comprehensive set of codecs. You only need to configure the MediaEngine if you want to customize codec support or add custom header extensions.
Creating a MediaEngine
basic-usage.go
Default Codecs
Pion WebRTC supports these codecs by default:Audio Codecs
1
Opus
MimeTypeOpus - 48kHz, stereo, with in-band FEC2
G.722
MimeTypeG722 - 8kHz narrowband audio3
PCMU
MimeTypePCMU - 8kHz μ-law encoding (G.711)4
PCMA
MimeTypePCMA - 8kHz A-law encoding (G.711)Video Codecs
1
VP8
MimeTypeVP8 - Popular codec with RTX support2
VP9
MimeTypeVP9 - Profile 0 and Profile 2 with RTX3
H.264
MimeTypeH264 - Multiple profiles:- Baseline (profile-level-id=42001f, 42e01f)
- Main (profile-level-id=4d001f)
- High (profile-level-id=64001f)
4
H.265
MimeTypeH265 - HEVC codec5
AV1
MimeTypeAV1 - Next-generation codecgoog-remb- Receiver Estimated Maximum Bitrateccm fir- Full Intra Requestnack- Negative Acknowledgmentnack pli- Picture Loss Indication
Custom Codec Registration
Register a Single Codec
custom-codec.go
Register Specific Codecs Only
specific-codecs.go
RTP Header Extensions
Header extensions provide additional metadata in RTP packets.Registering Header Extensions
header-extensions.go
Common Header Extensions
Transport-CC (sdp.TransportCCURI)
Transport-CC (sdp.TransportCCURI)
Used for bandwidth estimation and congestion control. Required for TWCC (Transport Wide Congestion Control).
Audio Level (sdp.AudioLevelURI)
Audio Level (sdp.AudioLevelURI)
Indicates the audio level of the RTP packet.
MID (sdp.SDESMidURI)
MID (sdp.SDESMidURI)
Media stream identification. Required for simulcast.
RTP Stream ID (sdp.SDESRTPStreamIDURI)
RTP Stream ID (sdp.SDESRTPStreamIDURI)
RTP stream identifier. Required for simulcast.
Direction-Specific Extensions
You can limit header extensions to specific transceiver directions:directional-extensions.go
RTCP Feedback
Add RTCP feedback mechanisms to codecs:rtcp-feedback.go
Common Feedback Types
string
Google’s Receiver Estimated Maximum Bitrate - for bandwidth estimation
string
Negative Acknowledgment - request retransmission of lost packets
string
Picture Loss Indication - request keyframe when packet loss affects decoding
string
Full Intra Request - request keyframe
string
Transport-wide Congestion Control - modern bandwidth estimation
Advanced Usage
Disable MediaEngine Copy
By default, the MediaEngine is copied for each PeerConnection. You can disable this:disable-copy.go
Query Negotiated Codecs
query-codecs.go
Complete Example
Custom MediaEngine with Specific Codecs
Custom MediaEngine with Specific Codecs
complete-example.go
Related Resources
SettingEngine
Configure advanced WebRTC behavior
Interceptors
Process RTP/RTCP packets