【问题标题】:RTCVideoTrack shows stretched WebRTCRTCVideoTrack 显示拉伸的 WebRTC
【发布时间】:2018-11-14 21:55:00
【问题描述】:

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

我尝试在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]; 

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

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

【问题讨论】:

    标签: ios iphone uiview webrtc


    【解决方案1】:

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

    如果要使用 RTCEAGLVideoView,请使用 RTCEAGLVideoViewDelegate 方法。

    - (void)videoView:(RTCEAGLVideoView *)videoView didChangeVideoSize:(CGSize)size;
    

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

    【讨论】:

    • 使用 RCMTLVideoView 代替 RTCEAGLVideoView 对我有用。它适用于任何配备 A7 或更高版本处理器(iPhone5S 或更高版本)的 ios 设备。
    • 不,他问的是 RTCCameraPreviewView,而不是从 webrtc 获取的远程视图
    【解决方案2】:

    (对于 Swift)-> 使用 RTCMTLVideoView 并设置 videoContentMode

    #if arch(arm64)
    let renderer = RTCMTLVideoView(frame: videoView.frame)
    renderer.videoContentMode = .scaleAspectFill
    #else
    let renderer = RTCEAGLVideoView(frame: videoView.frame)
    #endif
    

    【讨论】:

    • RTCMTLVideoView 旧,使用 RTCEAGLVideoView 更好
    猜你喜欢
    • 1970-01-01
    • 2022-06-14
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多