[REQUEST] Need a way to adjust encoding bitrate
In the Unity WebRTC package, the encoding bitrate can normally be adjusted from an RTCRtpSender instance. However, the RTCRtpSender is not exposed directly in the Render Streaming package. In version 3.0.1 and earlier of Render Streaming, the AddTrack() function in SignalingHandlerBase returned the Transceiver, and it was possible to adjust the video quality in a custom Broadcast class like this:
private void ApplyBitrate(RTCRtpTransceiver transceiver) {
var parameters = transceiver.Sender.GetParameters();
for (int i = 0; i < parameters.encodings.Length; i++) {
RTCRtpEncodingParameters encoding = parameters.encodings[i];
encoding.maxBitrate = this.maxBitrate;
encoding.minBitrate = this.minBitrate;
parameters.encodings[i] = encoding;
}
transceiver.Sender.SetParameters(parameters);
}
As of version 3.1, SignalingHandlerBase no longer returns the Transceiver. There is no way to access the Transceiver from any code outside of the Render Streaming package, and therefore no way to access the RTCRtpSender and adjust the encoding bitrate.
you can inherit from any StreamSender class you need, and then override SetSender method, so that you can get the sender and its parameter, finally you can set bitrate of encoding from parameter
@kevinfoley Right, we will add the API to control bitrate and framerate of video stream.
memo: URS-330
@karasusan When will we be able to use the API to control bitrate based on your plan?
same problem, now only 300kbps as default
@chopin1998 We will try to support this next milestone.
@kevinfoley @chopin1998
I checked this issue.
How about VideoStreamSender.ChangeVideoParameters method for your use?
FYI https://github.com/Unity-Technologies/UnityRenderStreaming/issues/453#issuecomment-884873236
@chopin1998 We will try to support this next milestone.
thanks! can i know the time for next milestone?
@chopin1998 The next milestone is in this month but we noticed that this issue should be fixed at first. https://github.com/Unity-Technologies/com.unity.webrtc/issues/552
@chopin1998 I think you have the same issue reported here. What are your thoughts on? https://github.com/Unity-Technologies/com.unity.webrtc/issues/552
@karasusan
i have upgraded to 3.1.0-exp.3, no bitrate options found.
bitrate still too low ~300k,
@chopin1998 Sorry but we omitted the feature this version. Could you read this thread and try? https://forum.unity.com/threads/webrtc-renderstreaming-code-improvements.1145162/
@karasusan
i believe there is a simply way to modify code (hardcode) to change the default bitrate setting, could you please tell me where to change it?
and will 3.1.0~exp.4 support birate interface?
@chopin1998 Have you checked this? https://github.com/Unity-Technologies/UnityRenderStreaming/issues/611#issuecomment-1027647660
@karasusan you mean file: com.unity.renderstreaming/Runtime/Scripts/VideoStreamSender.cs Line 43, right?
i noticed the function, and do some modify on this, but nothing happen. even i write a Debug.Log at begin of the function, no output in console, so i believe this function is not called.
i wanna call it by myself, but i donot know how to get "connectionId" for its first parameter.
@chopin1998 Sorry, we have not provided the sample for controlling setting of encoder. I promise that we will make the sample for the future release.
I guess you can see the "Bidirectional" sample to understand how to use connectionId.
In the Unity WebRTC package, the encoding bitrate can normally be adjusted from an
RTCRtpSenderinstance. However, theRTCRtpSenderis not exposed directly in the Render Streaming package. In version 3.0.1 and earlier of Render Streaming, theAddTrack()function inSignalingHandlerBasereturned the Transceiver, and it was possible to adjust the video quality in a custom Broadcast class like this:private void ApplyBitrate(RTCRtpTransceiver transceiver) { var parameters = transceiver.Sender.GetParameters(); for (int i = 0; i < parameters.encodings.Length; i++) { RTCRtpEncodingParameters encoding = parameters.encodings[i]; encoding.maxBitrate = this.maxBitrate; encoding.minBitrate = this.minBitrate; parameters.encodings[i] = encoding; } transceiver.Sender.SetParameters(parameters); }As of version 3.1,
SignalingHandlerBaseno longer returns the Transceiver. There is no way to access the Transceiver from any code outside of the Render Streaming package, and therefore no way to access theRTCRtpSenderand adjust the encoding bitrate.
@kevinfoley I also need to adjust the bitrate, and I tried above on 3.0.1, and set breakpoint in AddTrack(), but found that transceiver.Sender.GetParameters().encodings have zero element. And therefore I'm not able to set any parameter for encoder. I was always seeing empty encodings no matter I enabled hardware encoding or not. Also @karasusan did you ever hit this? Any tip about what's wrong?
@yinhew I am not sure the situation. It might be possible to found values after completing signaling process.
@chopin1998 Sorry, we have not provided the sample for controlling setting of encoder. I promise that we will make the sample for the future release.
I guess you can see the "Bidirectional" sample to understand how to use
connectionId.
is next miltstone coming soon? ;-)
@chopin1998 It should be add to the next milestone but the time is a few month later.
bled hardware encoding or not. Also @karasusan did you ever hit this? Any tip about what's wrong?
I had the same problem too. I solved this problem by doing this bitrate modificatino in "OnAnswer()" where Sender.GetParameters().encodings is not empty.