默認情況下,WebRTC視頻採用前置攝像頭,可以正常工作。但是,我需要將其切換回相機,並且我一直無法找到任何代碼來執行此操作。 我需要編輯哪個部分? 它是localView或localVideoTrack或capturer?iOS SWIFT - WebRTC從前置攝像頭變爲後置攝像頭
回答
我不確定哪個chrome版本用於webrtc,但使用v54及以上版本時,在RTCAVFoundationVideoSource類中有稱爲「useBackCamera」的「bool」屬性。您可以利用此屬性在前/後相機之間切換。
頭文件:https://cs.chromium.org/chromium/src/third_party/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAVFoundationVideoSource.h?rcl=c0a0f8d5f2d5b837b4c6ea447b0cdce86723e0d6&l=46 –
夫特3.0
等連接可僅具有用於發送視頻流的一個 'RTCVideoTrack'。
首先,對於更換相機前/後,您必須刪除對等連接上的當前視頻軌道。 然後,您可以在相機上創建您需要的新「RTCVideoTrack」,並將其設置爲對等連接。
我用過這種方法。
func swapCameraToFront() {
let localStream: RTCMediaStream? = peerConnection?.localStreams.first as? RTCMediaStream
localStream?.removeVideoTrack(localStream?.videoTracks.first as! RTCVideoTrack)
let localVideoTrack: RTCVideoTrack? = createLocalVideoTrack()
if localVideoTrack != nil {
localStream?.addVideoTrack(localVideoTrack)
delegate?.appClient(self, didReceiveLocalVideoTrack: localVideoTrack!)
}
peerConnection?.remove(localStream)
peerConnection?.add(localStream)
}
func swapCameraToBack() {
let localStream: RTCMediaStream? = peerConnection?.localStreams.first as? RTCMediaStream
localStream?.removeVideoTrack(localStream?.videoTracks.first as! RTCVideoTrack)
let localVideoTrack: RTCVideoTrack? = createLocalVideoTrackBackCamera()
if localVideoTrack != nil {
localStream?.addVideoTrack(localVideoTrack)
delegate?.appClient(self, didReceiveLocalVideoTrack: localVideoTrack!)
}
peerConnection?.remove(localStream)
peerConnection?.add(localStream)
}
目前我只有一個目標Ç回答了ANKIT的評論下面,將轉換代碼,並再次在一段時間內更新它,你可以
-(RTCVideoTrack *)createLocalVideoTrack {
RTCVideoTrack *localVideoTrack = nil; NSString *cameraID = nil;
for (AVCaptureDevice *captureDevice in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo])
{
if (captureDevice.position == AVCaptureDevicePositionFront) {
cameraID = [captureDevice localizedName]; break;
}
}
RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID]; RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints]; RTCVideoSource *videoSource = [_factory videoSourceWithCapturer:capturer constraints:mediaConstraints]; localVideoTrack = [_factory videoTrackWithID:@"ARDAMSv0" source:videoSource];
return localVideoTrack; }
- (RTCVideoTrack *)createLocalVideoTrackBackCamera {
RTCVideoTrack *localVideoTrack = nil;
//AVCaptureDevicePositionFront
NSString *cameraID = nil;
for (AVCaptureDevice *captureDevice in
[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
if (captureDevice.position == AVCaptureDevicePositionBack) {
cameraID = [captureDevice localizedName];
break;
}
}
RTCVideoCapturer *capturer = [RTCVideoCapturer capturerWithDeviceName:cameraID];
RTCMediaConstraints *mediaConstraints = [self defaultMediaStreamConstraints];
RTCVideoSource *videoSource = [_factory videoSourceWithCapturer:capturer constraints:mediaConstraints];
localVideoTrack = [_factory videoTrackWithID:@"ARDAMSv0" source:videoSource];
return localVideoTrack;
}
這個答案有一些嚴重的格式問題。請編輯和格式化您的答案,否則我將不得不舉牌。 –
ok會再次更新它 –
- 1. 從前置攝像頭切換到後置攝像頭JS
- 2. 在後置攝像頭和前置攝像頭之間切換
- 3. 同時打開android前置攝像頭和後置攝像頭
- 4. 測試iPhone4上的前置攝像頭或後置攝像頭
- 5. 切換到前置攝像頭和後置攝像頭Android SurfaceView
- 6. 用swift訪問前置攝像頭?
- 7. iPhone4可以同時從前置攝像頭和後置攝像頭錄製嗎?
- 8. 從Android 2.2的前置攝像頭和後置攝像頭拍照012
- 9. 如何獲得前置攝像頭,後置攝像頭和音頻AVCaptureDeviceDiscoverySession
- 10. Android攝像頭:前置攝像頭鏡像
- 11. Android前置攝像頭API
- 12. Android前置攝像頭
- 13. Android 2.2前置攝像頭
- 14. Windows 8後置攝像頭
- 15. Android攝像頭API 2自動對焦前置攝像頭
- 16. 無法連接前置攝像頭的攝像頭服務?
- 17. iOS 5的後置攝像頭預覽
- 18. WebRTC:切換攝像頭
- 19. 如何從前置攝像頭
- 20. Nexus 6前置攝像頭倒置
- 21. IOS前置或後置攝像頭斑馬線
- 22. 設置攝像頭轉動改變攝像機的位置
- 23. Android CWAC攝像頭:來自前置攝像頭的圖像總是鏡像
- 24. 開關前置攝像頭ARToolkit Unity
- 25. iOS:從前置攝像頭捕獲圖像
- 26. 如何用前視攝像頭在前置攝像頭中錄製視頻
- 27. 從內置攝像頭捕獲圖像
- 28. 同時從前置和後置攝像頭捕獲視頻
- 29. 如何使用mediaConfig navicon.getUserMedia for webRTC使用前置攝像頭
- 30. WPF 3D攝像頭位置
您正在使用的WebRTC庫或openwebrtc檢查下面的代碼圖書館 ? –
@ DuraiAmuthan.H我正在使用libjingle_peerconnection pod – mrnobody
嘗試從AVCaptureSession中刪除現有的AVCameraInput,然後使用AVCaptureDevicePositionBack將新的AVCameraInput添加到AVCaptureSession中 –