Fix/video codecs patching#245
Conversation
In PublisherPeerConnection, publish_codec_preferences() was called on init, when the list of transceivers was still empty, so it was not applied, and vp8 codec was still used. Moved the func call to `addTrack()` to fix that.
- Updated StreamH264Encoder to pass "preset" to codec options - Added STREAM_PATCH_AIORTC_H264_PRESET env variable with "ultrafast" by default. To reset to default "medium", pass "medium" or empty value
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR introduces environment-driven H.264 encoder preset configuration, refactors when codec preferences are applied to video transceivers, updates related documentation and warnings, and adds test coverage for the new preset behavior. The changes affect encoder patching, transceiver management, and video configuration logic. ChangesVideo Encoding Configuration and Management
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@getstream/video/rtc/encoders_patches.py`:
- Around line 81-101: H264Encoder._encode_frame currently only sets up
self.codec when it is None, so if the parent reassigns a new CodecContext (e.g.,
on resolution change) your preset/options get lost; update _encode_frame to
detect a freshly-created parent codec (check self.codec is not None and
self.codec.name == "libx264" but self.codec.options.get("preset") != self.preset
or missing expected keys) and re-apply the STREAM_H264_PRESET-related settings
(preset, tune, level and any missing fields like pix_fmt, framerate, time_base,
bit_rate, profile) by merging only missing/incorrect keys into
self.codec.options before calling yield from super()._encode_frame(frame,
force_keyframe) so you preserve parent intent while restoring your latency
optimizations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 97cd3af5-f2dd-4dda-9b5b-220812d483b5
📒 Files selected for processing (3)
getstream/video/rtc/encoders_patches.pygetstream/video/rtc/pc.pytests/rtc/test_encoders_patches.py
… robustly in case of resolution change
Fixes publishing codec preferences not being applied, so tracks were still able to use
vp8.Now, only
h264orav1.Sets
"ultrafast"h264 codec preset by default for lowest latency.To use the default
"medium", passSTREAM_PATCH_AIORTC_H264_PRESET=mediumorSTREAM_PATCH_AIORTC_H264_PRESET=(empty) env variable.Summary by CodeRabbit
Release Notes
New Features
Refactoring
Tests