iOS - Scaling remote video to fit in view bounds

2,321 views
Skip to first unread message

Suman Cherukuri

unread,
Apr 11, 2017, 7:54:01 PM4/11/17
to discuss-webrtc
Hi,

I just updated my WebRTC project to the latest code.  I changed my app to work with the latest codebase and as part of that change, I used RTCMTLVideoView for the remote video view.

My app always works in landscape mode.  If the device sizes are different (for example iPhone 7+ on one side and iPhone 6 on the remote side, remote video is rendered in a scaled down window to keep the aspect ratio.

My local view and remote views are split exactly in half the device side in landscape mode and rendered side by side.  How can I fill the remote video to scale and fit in the remote view and keep the aspect ratio?

I am on XCode 8.3.1 and iOS 10.3.1

Thanks,

--Suman

deni...@webrtc.org

unread,
Apr 13, 2017, 5:46:41 AM4/13/17
to discuss-webrtc
Hi Suman,
The RTCMTLVideoView embeds a MTKView that has hardcoded 
contentMode = UIViewContentModeScaleAspectFit
If I understand correctly you would want a UIViewContentModeScaleAspectFill.
Can you try changing that locally and see if it works for you.
Thank you for pointing this out. We should change the hardcoded contentMode of the embedded MTKView to be same as the one of the RTCMTLVideoView so consumer apps can specify their own value for this property.

Suman Cherukuri

unread,
Apr 13, 2017, 11:51:18 AM4/13/17
to discuss-webrtc
Hi,

Thank you for the reply.  Along with the ability to change the content mode, I need additional callbacks from MTKView like 
didChangeVideoSize from the GLKView to resize the view back to the original size.  For now I moved back to RTCEAGLVideoView. Also, I noticed few crashes when using metal view.  I will investigate them and post another message if needed.

Thanks,

--Suman

mar...@viktora.com

unread,
Aug 21, 2017, 5:57:22 AM8/21/17
to discuss-webrtc
Are there any plans to add didChangeVideoSize protocol method to RTCMTLVideoView? Or at least the ability to determine the remote video's aspect ration is important for properly laying out other views.

Thanks!


On Thursday, April 13, 2017 at 2:46:41 AM UTC-7, deni...@webrtc.org wrote:

Michael Kirk

unread,
Oct 5, 2017, 6:48:59 AM10/5/17
to discuss-webrtc
On Thursday, April 13, 2017 at 5:46:41 AM UTC-4, deni...@webrtc.org wrote:
Hi Suman,
The RTCMTLVideoView embeds a MTKView that has hardcoded 
contentMode = UIViewContentModeScaleAspectFit
If I understand correctly you would want a UIViewContentModeScaleAspectFill.
Can you try changing that locally and see if it works for you.
Thank you for pointing this out. We should change the hardcoded contentMode of the embedded MTKView to be same as the one of the RTCMTLVideoView so consumer apps can specify their own value for this property.


Sorry to resurrect an old thread, but yes, specifying UIViewContentModeScaleAspectFill locally works for my layout needs of an edge-to-edge video view.

Additionally, in my client code I needed to specify the layout margins:

        remoteVideoView.layoutMargins = UIEdgeInsets.zero


Your suggestion of passing through the contentMode of RTCMTLVideoView seems correct. I would appreciate this change being made upstream so I can get rid of my local patch.

Suman Cherukuri

unread,
Oct 5, 2017, 10:40:14 AM10/5/17
to discuss...@googlegroups.com
Thanks for the reply Michael confirming.  For now, I reverted back to RTCEAGLVideoView.  I will switch to MTKView later.

--

---
You received this message because you are subscribed to a topic in the Google Groups "discuss-webrtc" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/discuss-webrtc/Fn4Q0dUranY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to discuss-webrtc+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/261b7138-bd94-4dcf-bcda-8f3b37a2c7eb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages