demo · v131

Aspect-ratio aware downscaling for adaptive bitrates

The motivating SFU use case: simulcast layers want target output sizes that fit a screen-share aspect ratio (often not 16:9). scaleResolutionDownBy is a divisor that doesn't know aspect ratios — push it on a 21:9 ultrawide and you can end up off the simulcast layer's budget. scaleResolutionDownTo takes {width, height} and the browser fits within that box. Pick a source.

Blue = source frame · Red = encoded layer. With scaleResolutionDownBy the encoded layer is whatever-divided source — overruns the target. With scaleResolutionDownTo it fits the target box maintaining aspect ratio.

the api

const sender = pc.getSenders().find(s => s.track?.kind === "video");
const params = sender.getParameters();

params.encodings = [
  { rid: "high", scaleResolutionDownTo: { maxWidth: 1280, maxHeight: 720 } },
  { rid: "mid",  scaleResolutionDownTo: { maxWidth: 640,  maxHeight: 360 } },
  { rid: "low",  scaleResolutionDownTo: { maxWidth: 320,  maxHeight: 180 } }
];

await sender.setParameters(params);

see also