Skip to main content

Codec Selection

lib-jitsi-meet implements sophisticated codec selection to optimize video quality across different network conditions, browsers, and device capabilities.

CodecSelection Class

The CodecSelection class manages codec preferences for both JVB and P2P connections.

Initialization

Source: modules/qualitycontrol/CodecSelection.ts:55-62

Configuration Options

Source: modules/qualitycontrol/CodecSelection.ts:19-27

Default Codec Orders

lib-jitsi-meet uses different default codec orders based on platform and connection type:
Source: modules/qualitycontrol/CodecSelection.ts:15-17 Rationale:
  • Desktop JVB: Prefer newer codecs (AV1, VP9) for better quality/bandwidth
  • Mobile JVB: Prefer VP8 for better hardware support and battery life
  • Mobile P2P: Prefer H.264 for hardware acceleration and interoperability

Codec Support Detection

The codec list is filtered based on browser capabilities:
Source: modules/qualitycontrol/CodecSelection.ts:137-151

Codec Preference Order Generation

The constructor generates the final codec order based on config and browser support:
Source: modules/qualitycontrol/CodecSelection.ts:63-94, 122

Browser-Specific Adjustments

Firefox AV1 Handling

Firefox 136+ supports AV1 but only with simulcast (not SVC) and lacks temporal scalability. AV1 is moved to the end so Firefox decodes AV1 from others but encodes with VP8. Source: modules/qualitycontrol/CodecSelection.ts:96-112

VP9 Encoding Support

VP9 is disabled on Safari (except P2P) and Firefox due to implementation issues. See: https://bugs.webkit.org/show_bug.cgi?id=231074 Source: modules/qualitycontrol/CodecSelection.ts:100-112

Safari AV1 Disabled

Safari reports AV1 as supported on M3+ Macs but has decoder/encoder issues. AV1 is completely disabled until resolved. Source: modules/qualitycontrol/CodecSelection.ts:117-119

Screenshare Codec Selection

Screenshare can use a different codec than camera. By default, AV1 is preferred for screenshare when available. Source: modules/qualitycontrol/CodecSelection.ts:125-127

Codec Negotiation

The selectPreferredCodec method calculates the codec to use based on local preferences and remote capabilities:
Source: modules/qualitycontrol/CodecSelection.ts:179-235

E2EE Constraint

End-to-end encryption is currently only supported with VP8. Source: modules/qualitycontrol/CodecSelection.ts:188-190

Asymmetric Codec Support

lib-jitsi-meet supports asymmetric codecs (decode different codec than encode):
This allows endpoints to encode with VP8 while decoding AV1 from others. Source: modules/qualitycontrol/CodecSelection.ts:209-226

Dynamic Codec Switching

Codecs can be changed dynamically due to CPU restrictions:
Source: modules/qualitycontrol/CodecSelection.ts:244-274

Codec Complexity Order

Codecs are ordered by encoding complexity (from StandardVideoQualitySettings.ts):
When CPU is overloaded, the quality controller switches to a lower complexity codec. Source: modules/qualitycontrol/CodecSelection.ts:6, 249-250

Visitor Codec Support

Visitors (participants without sending capability) can specify their codec support, which is factored into codec negotiation. Source: modules/qualitycontrol/CodecSelection.ts:282-289

Codec Capabilities API

Getting Codec Preference List

Source: modules/qualitycontrol/CodecSelection.ts:159-161

Getting Screenshare Codec

Source: modules/qualitycontrol/CodecSelection.ts:169-171

Integration with TraceablePeerConnection

The codec selection integrates with the peer connection:

setCodecPreferences API

For browsers supporting RTCRtpTransceiver.setCodecPreferences() (Chrome, Edge):
Source: modules/RTC/TraceablePeerConnection.ts:1116-1144

Codec Selection API (Chrome 126+)

For browsers supporting per-encoding codec selection:
This allows changing codecs without renegotiation. Source: modules/RTC/TraceablePeerConnection.ts:1007-1023
VP8 Cannot Be DisabledVP8 is the baseline codec and cannot be disabled:
Attempting to disable VP8 will be ignored. This ensures all endpoints can communicate.Source: modules/qualitycontrol/CodecSelection.ts:83-85

Best Practices

  1. Use preferenceOrder over deprecated settings: The preferenceOrder array provides more flexibility than preferredCodec/disabledCodec.
  2. Different codecs for JVB and P2P: Optimize for each connection type:
  3. Test on target browsers: Codec support varies significantly. Use _getSupportedVideoCodecs() to verify.
  4. Consider hardware acceleration: H.264 has better hardware support on mobile devices.
  5. Monitor CPU usage: Use changeCodecPreferenceOrder() to dynamically adjust based on CPU load.

Next Steps