Resolution and aspect ratio using WebRTC and iOS

3,029 views
Skip to first unread message

Richard Brown

unread,
Mar 1, 2017, 2:28:22 AM3/1/17
to discuss-webrtc
Hi,

I am building an iOS app using WebRTC and although in general I can stream video well, I do have a few issues. Here is my setup:

iPhone 7S+
iOS target 10.1
Using WebRTC 57.5.16123

To display video I have an RTCEAGLVideoView embedded in a UIView which takes up the entire screen minus a navigation bar and the status bar. It is set to Aspect Fit (though I have tried Aspect Fill as well)

I am trying to set the resolution to 640x480 and have an aspect ratio of 4:3. To that end, I have done the following:

NSDictionary* mandatoryConstraints;

NSString *aspectRatio = [NSString stringWithFormat:@"%f",(double)4/3];

    if (aspectRatio) {

        mandatoryConstraints = @{ kRTCMediaConstraintsMaxAspectRatio: aspectRatio};

    }

RTCMediaConstraints *cameraConstraints = [RTCMediaConstraints alloc];
cameraConstraints
= [cameraConstraints initWithMandatoryConstraints:mandatoryConstraints optionalConstraints:nil];



Additionally, I also am using RTCAVFoundationVideoSource like so,


self.source = [self.peerConnectionFactory avFoundationVideoSourceWithConstraints:cameraConstraints];

[self.source adaptOutputFormatToWidth:640 height:480 fps:30];

self.source.useBackCamera = YES;//side note. there is a latency when switching from the front (default) camera and to the back one which my app uses. the user can see a glimmer of themselves before the switch. any way to avoid this?


This delegate method confirms I am getting 640x480 and 480x640 depending upon device orientation.

- (void)videoView:(RTCEAGLVideoView *)videoView didChangeVideoSize:(CGSize)size {
   
/* resize self.localView or self.remoteView based on the size returned */

   
NSLog(@"Height is %f and Width is %f", size.height, size.width);
}



Unfortunately, despite this, in landscape the image on the device is somewhat stretched. If you look at the one photo of the Iron Mountain box (no, I do not work for them) taken by the iOS camera app, it stays true to the correct aspect ratio. The second photo shows how the box appears somewhat elongated. 

So, the question is, how can I fix this?

Thank you!


IMG_1857.jpg
IMG_1858.jpg
Message has been deleted

Richard Brown

unread,
Mar 2, 2017, 10:45:02 AM3/2/17
to discuss-webrtc
Does anyone have any insight as to what I can do to stop this stretching?

Thank you!



On Thursday, March 2, 2017 at 10:43:46 AM UTC-5, Richard Brown wrote:

Richard Brown

unread,
Mar 7, 2017, 9:00:19 AM3/7/17
to discuss-webrtc
No one else encounters these issues?


On Wednesday, March 1, 2017 at 2:28:22 AM UTC-5, Richard Brown wrote:

klaus zhang

unread,
Mar 21, 2017, 9:06:09 AM3/21/17
to discuss-webrtc
same problem.
have you reset the videoview's frame based on size recved in  videoView: didChangeVideoSize: method? just like the AppRTCMobile demo do

I have some questions here
1.how can RTCEAGLVideoView take the whole screen wihout video being stretched?
2.when we reset the videoview's frame size ,just like AppRTCMobile demo do,the video displaying is being more larger than it is ,so we just can see part of the video and video quality is low


在 2017年3月7日星期二 UTC+8下午10:00:19,Richard Brown写道:

deni...@webrtc.org

unread,
Mar 27, 2017, 10:53:41 AM3/27/17
to discuss-webrtc
Hi Richard,

I'd suggest trying out the new Metal enabled video view instead of RTCEAGLVideoView. You can check out the latest version of AppRTCMobile for reference.
I believe it should handle your layout requirements in better way.

Best
/Daniela
Reply all
Reply to author
Forward
0 new messages