Skip to content

Stream publishing parameters changing on the fly

Since WebSDK build 2.0.258 some stream publishing parameters may be changed on the fly, without stopping and starting the stream again. This works in Chromium based and Safari browsers.

Stream resolution changing

A stream publishing resolution may be changed by Stream.updateVideoResolution method

code

function onResolutionClick(stream) {
    stream.updateVideoResolution({
        width: parseInt($('#sendWidth').val()),
        height: parseInt($('#sendHeight').val())
    }).then(function(constraints) {
        console.log("Publishing video constraints changed to " + JSON.stringify(constraints));
    }).catch(function(e) {
        console.error("Error " + e);
    });
}

Under the hoods, the video track will be re-created with the new resolution constraints. All the other constraints are not affected.

Warning

The resolution constraints are recommendations for a browser, not requirement. The browser may drop the video resolution if publisher channel is not so good, or if publisher hardware performance does not allow to capture and encode the resolution.

Stream encoding parameters changing

A stream encoding parameters may be changed by Stream.updateVideoSettings method

  • A maximum bitrate in kbps
    code

     function onBitrateClick(stream) {
         stream.updateVideoSettings({
             maxBitrate: parseInt($('#sendVideoMaxBitrate').val())
         }).then(function(encodings) {
             console.log("Publishing video encoder parameters changed to " + JSON.stringify(encodings));
         }).catch(function(e) {
             console.error("Error " + e);
         });
     }
    

  • A maximum frame rate per second
    code

     function onFpsClick(stream) {
         stream.updateVideoSettings({
             frameRate: parseInt($('#fps').val())
         }).then(function(encodings) {
             console.log("Publishing video encoder parameters changed to " + JSON.stringify(encodings));
         }).catch(function(e) {
             console.error("Error " + e);
         });
     }
    

  • A downscale factor

     stream.updateVideoSettings({
         scaleResolutionDownBy: 2
     }).then(function(encodings) {
         console.log("Publishing video encoder parameters changed to " + JSON.stringify(encodings));
     }).catch(function(e) {
         console.error("Error " + e);
     });
    

In this case, stream video track encoding parameters are changed without the track re-creation. They even may be changed simutaneously

stream.updateVideoSettings({
    maxBitrate: 1000,
    frameRate: 24,
    scaleResolutionDownBy: 1
});

Warning

Encoding bitrate only may be set by such way. A bandwidth limit has a priority above the encoder bitrate. For example, if the bandwidth is limited to 1000 kbps, and encoder bitrate is set to 1500 kbps, the video track will be published with 1000 kbps bitrate