OGeek|极客世界-中国程序员成长平台

标题: ios - RTCVideoTrack 显示拉伸(stretch)的 WebRTC [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 04:19
标题: ios - RTCVideoTrack 显示拉伸(stretch)的 WebRTC

我正在使用核心 WebRTC 框架 并在 iPhone 全屏模式下呈现我的本地流。不幸的是,我的视频显示拉伸(stretch),不像相机应用程序中的视频 View 那样显示。

我尝试在 RTCMediaConstraints 中添加宽高比,还使用了 adaptOutputFormatToWidth 方法来修复输出。

NSDictionary* mandatoryConstraints;

/* want to calculate aspect ratio dynamically */
NSString *aspectRatio = [NSString stringWithFormat"%f",(double)4/3];
if (aspectRatio) {
   mandatoryConstraints = @{ kRTCMediaConstraintsMaxAspectRatio: 
   aspectRatio};
}

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


RTCAVFoundationVideoSource *localVideoSource =  [peerFactory avFoundationVideoSourceWithConstraints:mediaConstraint];
        [localVideoSource adaptOutputFormatToWidth:devicewidth:devicewidth fps:30]; 

在下面的链接中,显示了相机视频 View 和我的应用程序调用视频 View 之间的区别

https://drive.google.com/file/d/1HN3KQcJphtC3VzJjlI4Hm-D3u2E6qmdQ/view?usp=sharing



Best Answer-推荐答案


我相信您正在使用 RTCEAGLVideoView 渲染视频,这需要调整大小,您可以使用 RTCMTLVideoView 代替 RTCEAGLVideoView

如果您想使用 RTCEAGLVideoView,请使用 RTCEAGLVideoViewDelegate 方法。

- (void)videoViewRTCEAGLVideoView *)videoView didChangeVideoSizeCGSize)size;

此方法将为您提供正确的视频大小。

关于ios - RTCVideoTrack 显示拉伸(stretch)的 WebRTC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50699626/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4