Description
i am capturing video from this method. I am using RTCMTLNSVideoView to display the video. my issue is that i am unable to flip the video.
` func enableMyMedia(callback:@escaping () -> Void){
DispatchQueue.global(qos: .userInitiated).async {
if(PeerConnectionService.localStream == nil){
let _localStream = self.peerConnectionFactory.mediaStream(withStreamId:self.getStreamUniqueId());
let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [ "offerToReceiveAudio": "true",
"offerToReceiveVideo": "true",
"googCpuOveruseDetection": "true",
"googHighStartBitrate": "true",
"googScreencastMinBitrate": "true",
"googCpuUnderuseThreshold": "55", // Optional - adjust according to needs
"googUseHardwareH264": "false"])
let audioSource = self.peerConnectionFactory.audioSource(with: constraints)
let audioTrack = self.peerConnectionFactory.audioTrack(with: audioSource, trackId: self.getUniqueId());
_localStream.addAudioTrack(audioTrack);
if(self.isAudio == false){
self.videoSource = nil;
self.videoSource = self.peerConnectionFactory.videoSource()
self.localVideoTrack = self.peerConnectionFactory.videoTrack(with: self.videoSource!, trackId: self.getUniqueId())
self.videoCapturer = RTCCameraVideoCapturer(delegate: self.videoSource!)
if let localVideoTrack = self.localVideoTrack {
_localStream.addVideoTrack(localVideoTrack)
} else {
print("localVideoTrack is nil")
}
let devices = RTCCameraVideoCapturer.captureDevices()
if let selectedDevice = devices.first(where: { $0.position == .front || $0.position == .back || $0.position == .unspecified }){
let formats = RTCCameraVideoCapturer.supportedFormats(for: selectedDevice)
let selectedFormat = formats.first { format in
let dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription)
return dimensions.width <= 640 && dimensions.height <= 480 // Limit resolution to 480p
}
if let format = selectedFormat {
let maxFrameRateRange = format.videoSupportedFrameRateRanges.min { $0.minFrameRate < $1.minFrameRate }
if let frameRate = maxFrameRateRange?.minFrameRate {
let fps = max(frameRate, 10) // Example to limit to 15 fps
DispatchQueue.main.async {
self.videoCapturer?.startCapture(with: selectedDevice, format: format, fps: Int(fps))
}
}
}
}
}
PeerConnectionService.localStream = _localStream;
callback()
}else{
callback()
}
}
}`
showing video on RTCMTLNSVideoView like this
func renderVideoCall() {
let renderer = RTCMTLNSVideoView(frame: self.view.frame)
renderer.wantsLayer = true
renderer.clipsToBounds = true
renderer.layer?.setAffineTransform(CGAffineTransform(scaleX: -1.0, y: 1.0))
print("Renderer layer class: \(String(describing: renderer.layer?.className))")
// Add renderer to view
self.view.addSubview(renderer)
self.localVideoTrack = self.localStream?.videoTracks[0]
if let videoTrack = self.localVideoTrack {
videoTrack.add(renderer)
print("Video track successfully added to renderer.")
} else {
print("Video track is nil.")
}
self.view.needsDisplay = true
}
But its not working