zeus
zeus

Reputation: 13357

Ios: how to avoid video orientation change during capture?

I have an iOS app that only supports portrait. When rotating the device the video captured by the RTCCameraVideoCapturer (WebRTC) rotates to landscape orientation, even when the rest of the UI stays in portrait. How to avoid this?

Upvotes: 1

Views: 1934

Answers (2)

Charlotte
Charlotte

Reputation: 11

We can reinit a video frame with pin rotation to video source

// create video source 
let videoSource = self.factroy.videoSource()
self.videoSource = videoSource

// create video capture
self.videoCapture = RTCCameraVideoCapturer.init(delegate: self)

func capturer(_ capturer: RTCVideoCapturer, didCapture frame: RTCVideoFrame) {
    // 把frame发给videosource, 锁定一个方向输出 frame
    let frame = RTCVideoFrame(buffer: frame.buffer, rotation: ._90, timeStampNs: frame.timeStampNs)
    self.videoSource?.capturer(capturer, didCapture: frame)
}

Upvotes: 0

Pallab Gain
Pallab Gain

Reputation: 336

Do you have access to RTCCameraVideoCapturer codebases ? Also, I am not sure which version of the WebRTC codebases you are working with. And, in your application ; is landscape mode is the only mode that you are intending to support ?

There should be rotation calculation method that listen to rotation changes. You can just disabled it, or can use your preferred fixed set of rotation in spite of default.

For example, taking from this sample codebase ; you can just only use RTCVideoRotation_90 to have landscape orientation only.

Upvotes: 1

Related Questions