← View all posts
February 27, 2017

Fiddle-of-the-week: Downscale video in RTCPeerConnection

Contributed by Jan-Ivar Bruaroey,

More of last year’s new laptop cameras have few or no low-resolution modes. These reveal a big difference in how Chrome and Firefox implement the getUserMedia camera API. Whereas Chrome re-scales video to whatever constraints you put in, Firefox does not, instead guaranteeing the closest native resolution. Both are technically within spec. That said, the elaborate constraints language offered by getUserMedia, with minmax ranges and ideal values, was clearly designed for resolution discovery; it is overkill for setting a target resolution override.

But sending large resolution video over a peer connection is expensive. Here’s how you downscale it in Firefox:

Hit the “Run” tab to see it in action. This uses the scaleResolutionDownBy and maxBitrate features of the sender.setParameters method in the WebRTC specification.

Update 2020: This now works in Chrome and Edge as well! You can also resize it dynamically now.