Why does audio static when i have video and audio ...
# ask-ai
c
Why does audio static when i have video and audio tracks on at the same time? we're using the react sdk. when video is turned off, the audio stabilizes
t
Thanks for reaching out, Jamell. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about why audio becomes static only when both video and audio tracks are on in the React SDK (and clears up when video is off). Likely cause • CPU or resource contention on the client. Encoding/processing video raises CPU usage and can interfere with audio capture/processing, producing static or artifacts. When video is off, CPU load drops and audio stabilizes. Quick things to check • Reproduce on a higher‑CPU device to confirm it’s resource related. • Watch client CPU while streaming (browser Task Manager or OS monitor). • Check for browser/console warnings such as
LocalTrackCpuConstrained
events. Immediate fixes to try • Reduce video resolution or frame rate when publishing (lower publish settings). • Enable adaptive streaming in the Room options (
adaptiveStream: true
) so streams scale to device/network. • Disable CPU‑heavy video effects (background blur, virtual backgrounds) and any extra audio processors during the call. • Try different codecs or fewer simulcast layers if you have them enabled. If you want, tell me: • which browser and device you’re testing on, • your published video resolution/frame rate and whether you use background effects or simulcast, and I’ll suggest exact settings/代码 snippets for the React SDK to lower load. Sources: Optimizing Video Calls for Low-Powered Devices in LiveKit (JS SDK ≥ v2.14.0... | Codecs and more | LiveKit docs | Debugging Audio/Video Sync Issues in LiveKit Publishing | Bringing Zoom's end-to-end optimizations to WebRTC
c
Here's a summary you can send to Jerry: --- Summary: Audio Static Fix When Video + Audio Enabled Problem: Users were experiencing audio static/artifacts when both video and audio tracks were enabled simultaneously. When video was turned off, audio would stabilize. Root Cause: CPU resource contention. The video encoding settings were too aggressive, causing CPU overload that interfered with audio capture/processing. Specifically: 1. 4K video capture – We were capturing at 2160p (4K) resolution in HQ mode 2. VP9 codec – More CPU-intensive than VP8/H.264 3. DTX disabled – Audio encoding ran continuously even during silence 4. Heavy simulcast layers – Encoding at multiple high resolutions simultaneously Fix Applied (
components/video-conference.tsx
):
| Setting | Before | After | |---------|--------|-------| | Default Codec | VP9 | VP8 | | Video Capture (HQ) | 4K (h2160) | 1080p (h1080) | | DTX | Disabled | Enabled | | Simulcast Layers (HQ) | [1080p, 720p] | [720p, 360p] | | Simulcast Layers (Std) | [540p, 216p] | [360p, 180p] | | Audio Processing | None | autoGainControl, echoCancellation, noiseSuppression | Impact: - ~4x reduction in video encoding workload (4K → 1080p) - Lower CPU usage with VP8 vs VP9 - DTX reduces audio processing during silence - Audio processing flags help stabilize capture quality Note: We already had a
useLowCPUOptimizer
hook that listens for
LocalTrackCpuConstrained
events and reacts by lowering quality. However, this is reactive—by the time it fires, audio degradation has already started. The changes above are preventative and should eliminate the issue before it occurs. Next Steps: - Test on lower-end devices to confirm fix - Monitor for any user reports of reduced video quality (tradeoff for stability) - If needed, can further reduce to 720p capture or add frame rate limits --- [3 tools called] ## VideoConferenceComponent - LiveKit Summary Core Setup: - Creates a
Room
instance from
livekit-client
with configured
RoomOptions
- Wraps children in
RoomContext.Provider
from
@livekit/components-react
- Connects via
room.connect(serverUrl, participantToken, connectOptions)
Room Configuration: - Codec: VP8 (default), falls back for E2EE - Video: 1080p capture (HQ) / 720p (standard), simulcast layers for adaptive quality - Audio: DTX enabled, with
autoGainControl
,
echoCancellation
,
noiseSuppression
- Features:
adaptiveStream: true
,
dynacast: true
, optional E2EE via
ExternalE2EEKeyProvider
Event Handling: -
RoomEvent.Disconnected
→ cleanup & redirect -
RoomEvent.MediaDevicesError
→ device fallback logic -
RoomEvent.EncryptionError
→ error toast Permissions: - Parses
canPublishSources
to determine camera/mic/screen access - Auto-enables devices on connect (non-hosts only) - Hosts stay muted by default CPU Optimization: -
useLowCPUOptimizer
hook listens for
LocalTrackCpuConstrained
events - Reduces video quality when CPU is stressed Rendering: -
MainStage
- primary video grid with pinned layout support -
RemoteAudioRenderer
- renders remote audio tracks -
OverlayControls
- mic/camera/screen controls -
LayoutSync
- syncs host layout preferences to participants -
VideoTracksTracker
- notifies parent of video track changes Let me know if you want me to adjust the tone or add anything else! 🤙
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
c
this is a summary of our findings: Let me research your codebase to understand your current LiveKit implementation and provide specific recommendations. [8 tools called] Now I have a clear picture of your setup. Let me write a comprehensive Slack reply for you: --- Hey! Dug into the codebase and found some specific culprits. Here's what's happening and how to fix it: ## 🔍 Root Cause Analysis Your
video-conference.tsx
has some pretty aggressive settings that are eating CPU for breakfast: 1. 4K Video Capture in HQ Mode
Copy code
192:195:components/video-conference.tsx
    const videoCaptureDefaults: VideoCaptureOptions = {
      deviceId: props.userChoices.videoDeviceId || undefined,
      resolution: props.options.hq ? VideoPresets.h2160 : VideoPresets.h720,
    };
When
hq=true
(which is hardcoded in
room-page-client.tsx
), you're capturing at 2160p/4K resolution. That's a LOT of pixels to encode while also processing audio. The CPU contention causes audio buffer underruns → static/artifacts. 2. VP9 Codec
Copy code
186:188:components/video-conference.tsx
    let videoCodec: VideoCodec | undefined = props.options.codec
      ? props.options.codec
      : "vp9";
VP9 is more CPU-intensive than VP8/H.264, especially without hardware encoding support. 3. DTX is Disabled
Copy code
197:197:components/video-conference.tsx
      dtx: false,
With DTX off, audio encoding runs continuously even during silence—more CPU overhead. 4. Multiple Simulcast Layers
Copy code
198:200:components/video-conference.tsx
      videoSimulcastLayers: props.options.hq
        ? [VideoPresets.h1080, VideoPresets.h720]
        : [VideoPresets.h540, VideoPresets.h216],
Encoding multiple resolution layers simultaneously adds to the load. --- ## ✅ Recommended Fixes Here's what I'd update in `components/video-conference.tsx`:
Copy code
typescript
const videoCaptureDefaults: VideoCaptureOptions = {
  deviceId: props.userChoices.videoDeviceId || undefined,
  // Drop from 4K to 1080p max - still high quality, way less CPU
  resolution: props.options.hq ? VideoPresets.h1080 : VideoPresets.h720,
};

const publishDefaults: TrackPublishDefaults = {
  dtx: true, // Enable DTX - reduces CPU during silence
  videoSimulcastLayers: props.options.hq
    ? [VideoPresets.h720, VideoPresets.h360] // Lower layers
    : [VideoPresets.h360, VideoPresets.h180],
  red: !e2eeEnabled,
  videoCodec: "vp8", // Consider VP8 for better CPU efficiency
};

// Add audio processing hints
audioCaptureDefaults: {
  deviceId: props.userChoices.audioDeviceId || undefined,
  autoGainControl: true,
  echoCancellation: true,
  noiseSuppression: true,
},
You already have
useLowCPUOptimizer
hooked up which listens for
LocalTrackCpuConstrained
events—that's good! But by the time it fires, the damage (static) has already started. These changes are preventative. --- [3 tools called] ## VideoConferenceComponent - LiveKit Summary Core Setup: - Creates a
Room
instance from
livekit-client
with configured
RoomOptions
- Wraps children in
RoomContext.Provider
from
@livekit/components-react
- Connects via
room.connect(serverUrl, participantToken, connectOptions)
Room Configuration: - Codec: VP8 (default), falls back for E2EE - Video: 1080p capture (HQ) / 720p (standard), simulcast layers for adaptive quality - Audio: DTX enabled, with
autoGainControl
,
echoCancellation
,
noiseSuppression
- Features:
adaptiveStream: true
,
dynacast: true
, optional E2EE via
ExternalE2EEKeyProvider
Event Handling: -
RoomEvent.Disconnected
→ cleanup & redirect -
RoomEvent.MediaDevicesError
→ device fallback logic -
RoomEvent.EncryptionError
→ error toast Permissions: - Parses
canPublishSources
to determine camera/mic/screen access - Auto-enables devices on connect (non-hosts only) - Hosts stay muted by default CPU Optimization: -
useLowCPUOptimizer
hook listens for
LocalTrackCpuConstrained
events - Reduces video quality when CPU is stressed Rendering: -
MainStage
- primary video grid with pinned layout support -
RemoteAudioRenderer
- renders remote audio tracks -
OverlayControls
- mic/camera/screen controls -
LayoutSync
- syncs host layout preferences to participants -
VideoTracksTracker
- notifies parent of video track changes --- do you have any extra context you could give otherwise I will report back is this doesn't fix the issue