miroslavpejic85 / mirotalkc2c

✨WebRTC - C2C - Real-time cam-2-cam video calls & screen sharing, end-to-end encrypted, to embed in any website with a simple iframe.
https://c2c.mirotalk.com
GNU Affero General Public License v3.0
232 stars 57 forks source link

Add video codec and max bitrate settings #10

Open ZZYSonny opened 1 year ago

ZZYSonny commented 1 year ago

This pull request introduces two new settings to allow users to enhance their video quality.

By default, Chrome utilizes VP8 for WebRTC video encoding and imposes a 3Mbps limit on video bitrate. These limits might be too conservative, especially in the case of 1-1. Users may choose to use a more recent video encoder (if supported) / higher bitrate (if network allows) for much better video quality.

ZZYSonny commented 1 year ago

Hi. Thank you for making this feature greater by allowing changing codec and bitrate on the go.

One thing I would suggest is to order the codec items from high quality (but slower / less support) to lower quality (faster). Even better if it is in the same (quality) ordering as bitrate option.

In my opinion AV1 > VP9 > VP8 ≈ H264 in terms of quality.

ZZYSonny commented 1 year ago

I am trying to see if I can apply the new codec (without a refresh) by restarting the peerConnection.

ZZYSonny commented 1 year ago

Codec change should work without refreshing the window now. Feel free to review, experiment and adapt the code. (As a reminder you may need to refresh chrome://webrtc-internals to see the codec changes).

Also, it is probably useful to try refreshCodec after sender.replaceTrack() (See https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/replaceTrack#usage_notes)

ZZYSonny commented 1 year ago

Hi. It is been a while since I first submitted this PR and made the enhancement. Please let me know how you feel about this PR. If you find no value in it, I can close the PR for you.

miroslavpejic85 commented 1 year ago

Hey @ZZYSonny, It's great to hear from you, and I appreciate your patience in waiting for a response. I'll hope to take a look at your PR this weekend and provide you with feedback as soon as possible.

From what I understand, you have tested the code, and it works fine, right? Have you noticed any particular differences when changing the codec and Mbps?

Thank you for your contribution, and we'll discuss its merits and any potential changes if necessary. Feel free to reach out to me anytime, and sorry for the delay, I'm swamped with other commitments. 😊

ZZYSonny commented 1 year ago

Thank you for your update and wish you all the best in your life.

I've deployed mirotalk with this PR. I typically use VP9 (unfortuantely chrome android does not support AV1 yet) with 8Mbps. The video quality improvement is substantial, especially when you move around. With low bitrate the video is just full of pixels.

Thanks again for maintaining this wonderful project and hope to hearing from you soon.

miroslavpejic85 commented 1 year ago

You're very welcome! I appreciate your kind words and support. It's great to hear that you've deployed Mirotalk with the PR and are enjoying improved video quality with VP9. The advancement of video codecs like VP9 and AV1 is indeed crucial for enhancing video quality, especially in low bandwidth scenarios.

I've made some adjustments to ensure compatibility across various browsers and devices. Please feel free to thoroughly test it, and let me know if you encounter any issues or anomalies during your testing.

Best wishes to you too, and I'm here whenever you need assistance or have more updates to share!

ZZYSonny commented 1 year ago

Hi. It is good to see the compatibility adjustments and the new error catchings. I've refined the error catching and restoring in the last few commits. Now if you select a codec which is not supported on the other sides (which won't really happen because we don't have a AV1 standalone choice.), the error will be caught as well and you will reset to the default codec. Also a few other error catching refining for bitrate. Hope you enjoy the new commits.

miroslavpejic85 commented 1 year ago

Hey! That sounds like fantastic progress on the compatibility adjustments and error catching in your recent commits. It's great to hear that you've gone the extra mile to ensure smooth operation even in scenarios that are unlikely to happen. The attention to detail with error catching for bitrates is also a valuable addition.

Your commitment to improving the project is truly appreciated, and it's clear you're dedicated to delivering a robust and user-friendly experience. Keep up the excellent work, and I'm sure users will indeed enjoy these new commits. If you have any more updates in the future, feel free to reach me out.

PS: Could you please align this branch with the main branch of the Mirotalk C2C repository and If you think something can still be improved feel free to send commits.

Happy coding and thank you so much for you valuable time and have a great weekend! 😊🚀

ZZYSonny commented 1 year ago

Hello. I think this PR is in a good shape to merge. Please consider doing a final review and merging the PR. Thank you so much for your invaluable input and wish that the codec option and the project will help more and more people.

One thing I would suggest though is to make the setting saving per-room. If someone talks to a person with high bandwidth in a meeting room, but wants to talk to another person in another room with lower bandwidth. It would probably save some hassle. Maybe the resolution and fps can be saved as well. But personally I feel these improvements are outside this PR.

miroslavpejic85 commented 1 year ago

Hello, I hope you understand that I've been quite occupied with other commitments. I do find the concept of managing codecs and Mbps intriguing. However, I've come across situations where infinite loops can be triggered, especially when one of the parties involved doesn't support a specific codec or Mbps. Additionally, I think it would be beneficial to conduct thorough testing across various browsers to create a comprehensive test matrix. I promise to return to this pull request when my schedule permits. In the meantime, please feel free to make improvements, conduct further testing, and address any issues, including the one I mentioned earlier. Thank you for Your time and for the dedication to this project are greatly appreciated!