fix: improve initial video quality by setting x-google-start-bitrate for all video codecs#1050
Open
xianshijing-lk wants to merge 1 commit into
Conversation
…for all video codecs - Add x-google-start-bitrate SDP munging for all video codecs (VP8, VP9, AV1, H264, H265) - Use 90% of target bitrate as start bitrate to prevent initial blurriness - Default degradationPreference to .maintainResolution for video tracks This addresses the issue where video starts blurry for several seconds before improving, by telling WebRTC's bandwidth estimator to start at a higher bitrate instead of ramping up from ~300kbps. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
9772bef to
00a2993
Compare
pblazej
reviewed
Jun 30, 2026
|
|
||
| /// Munge SDP to add x-google-start-bitrate for video codecs. | ||
| /// This helps prevent initial video blurriness by starting at a higher bitrate. | ||
| func mungeStartBitrate(_ sdp: String, trackBitrates: [String: TrackBitrateInfo]) -> String { |
Contributor
There was a problem hiding this comment.
A few suggestions:
- Per-codec, not global max. We compute
max(maxBitrateKbps)across all tracks and stamp that single value onto every video payload. The consensus in the thread was "0.9× of that codec's target." It happens to work because one codec is negotiated at a time, but it's not what it says on the tin. - H264 loses payloads.
codecPayloads[codecName] = payloadkeeps only the last payload per codec name. H264 commonly advertises several profile payloads; only one gets the hint. (Low impact since H264 doesn't benefit anyway, but it shows the matching is loose.) - Can be
staticlikemungeInactiveToRecvOnlyForMedia— it uses no instance state. - Needs a test. This is non-trivial string parsing (CRLF detection, fmtp insert-vs-append, payload matching) with no coverage. Please add a unit test that feeds a representative VP9/AV1 offer and asserts the resulting
a=fmtpline.
Contributor
|
Changing the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
x-google-start-bitrateSDP munging for all video codecs (VP8, VP9, AV1, H264, H265)degradationPreferenceto.maintainResolutionfor video tracksProblem
Video starts blurry for 5-15 seconds before improving. This is caused by WebRTC's bandwidth estimator starting at ~300kbps and slowly ramping up to the target bitrate.
Solution
Changes
TrackBitrateInfostruct and tracking inTransportsetTrackBitrateInfo()method to register bitrate info when publishing video tracksmungeStartBitrate()SDP munging functiondegradationPreferencefrom.autoto.maintainResolutionTest plan
🤖 Generated with Claude Code