Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ChangeVideoParameters does not do anything

Discussion in 'Unity Render Streaming' started by ypvypv, Jan 12, 2022.

  1. ypvypv

    ypvypv

    Joined:
    Apr 16, 2019
    Posts:
    7
    Hi,

    I would like to control framerate and bitrate dynamically, depending on webrtc network conditions, I would like to set either of them at a given time to create a better user experience. At this point I think I exhausted all options with the H264 NVidia encoder codec 6.2 upgrade. I have read on the forum that some people are successful with changing the bitrate, min or max. I was also able to control the framerate by modifying the encoding parameters in the webrtc native code. I am mostly interested in framerate control and bitrate control is still important, but less so.

    There is a function that allows me to update framerate:
    WebBrowserInputSample has a function I am using, but it only works when the stream has just been created:

    Code (CSharp):
    1.         private IEnumerator HandleStreamStarted(CameraStreamer cameraStreamer, string connectionId)
    2.         {
    3.             // The parameters are not available right away so wait for them
    4.             yield return new WaitForEndOfFrame();
    5.             Debug.Log($"WebRTC stream connected: {cameraStreamer.name} has {cameraStreamer.Senders.Count} active connections, maxBitrate {maxBitrate}, encodedFps {encodedFps}");
    6.             cameraStreamer.ChangeVideoParameters(connectionId, (ulong)(maxBitrate * 1024 * 1024), encodedFps);
    7.             yield return null;
    8.         }
    Calling a modified ChangeVideoParameters at a later arbitrary point of time changes the encoding parameters of a stream, but unfortunately does nothing to the stream properties in chrome://webrtc-internals.

    Does anyone know why ChangeVideoParameters only makes a difference at stream start time?

    What can one do about it?
     
  2. kazuki_unity729

    kazuki_unity729

    Unity Technologies

    Joined:
    Aug 2, 2018
    Posts:
    796
  3. ypvypv

    ypvypv

    Joined:
    Apr 16, 2019
    Posts:
    7
    No this is a different issue. This is specific to ChangeVideoParameters. If I set max framerate at the time of stream creation, I see the correct max framerate. When I call ChangeVideoParameters later, when the stream has been running and displaying, the max framerate does not change and I get some artifacts instead.
     
  4. ypvypv

    ypvypv

    Joined:
    Apr 16, 2019
    Posts:
    7
    @kazuki_unity729

    I am sorry I think I must have forgotten how the original problem occured. I now have full memory of how ChangeVideoParameters operates.

    Basically I want to control bitrate and framerate. None of them work via ChangeVideoParameters. ChangeVideoParameters does not do anything unfortunately.

    I am able to set max framerate only through the Unity Engine itself which works well for me, for now:

    Code (CSharp):
    1. QualitySettings.vSyncCount = 0;
    2. Application.targetFrameRate = parameters.framerate;