This example starts from a standard WHIPClient publish flow and adds runtime control of outgoing video encoding parameters while the stream is live.
It demonstrates a client-side adaptive pattern (often called client-side ABR) where bitrate and resolution scale can be adjusted in response to changing network conditions.
- standard WHIP publish lifecycle with
initWithStream(...) - updating encoder parameters without reconnecting:
maxBitratescaleResolutionDownBy
- optional active-state linkage when video is muted (
encoding.active) - live status feedback for applied encoding values
After publish starts, the Live Video Encoding controls are enabled.
On control changes, the example:
- finds the active video sender on the peer connection
- reads sender parameters (
sender.getParameters()) - updates the first encoding entry:
- set/clear
maxBitrate - set
scaleResolutionDownBy - optionally set
activebased on mute state
- set/clear
- applies updates with
sender.setParameters(params)
No reconnect is required because encoding parameters are updated in place on the existing sender.
const publisher = new red5prosdk.WHIPClient()
await publisher.initWithStream(
{
endpoint,
streamName,
mediaElementId: 'publisher-video',
connectionParams,
streamMode: 'live',
},
mediaStream
)
await publisher.publish()
// Later, while publishing:
const pc = publisher.getPeerConnection()
const sender = pc?.getSenders().find((s) => s.track?.kind === 'video')
if (!sender) throw new Error('No video sender')
const params = sender.getParameters()
params.encodings = params.encodings?.length ? params.encodings : [{}]
params.encodings[0].maxBitrate = 750_000 // 750 kbps
params.encodings[0].scaleResolutionDownBy = 2 // half-resolution
await sender.setParameters(params)- Keep publish running and expose live encoding controls in your UI.
- On each user/network decision, compute target bitrate/scale.
- Update
RTCRtpSenderencoding parameters viasetParameters. - Log and display applied values so operators can confirm state.
- Optionally pair with mute state (
encoding.active) for advanced behavior.
Live encoding updates are independent from deployment mode. Endpoint and connection setup follows the same WHIP pattern as other examples.
const endpoint = `https://${host}:443/live/whip/${streamName}`
const connectionParams = {}const endpoint = `https://${host}/as/v1/proxy/whip/${app}/${streamName}`
const connectionParams = {
// e.g. region, nodeGroup, auth metadata
}- publish flow:
startPublish() - live encoding apply path:
applyLiveVideoEncodingFromControls() - control readers:
readEncodingBandwidthOption()/readEncodingScaleOption() - encoding helper implementation:
applyLiveVideoEncoding()insrc/lib/live-video-encoding.ts - applied summary formatter:
formatAppliedVideoEncodingSummary()
Use this as a reference for client-side runtime video adaptation (bitrate/scaling control) without reconnecting an active WHIP broadcast.