Reputation: 21
I succeeded in playing the remote video on the screen in real time using webrtc-ios and swiftui. But I also want real-time recording video. I know how to change the RTCVideooframe to CMsamplebuffer, and I know that I have to save it using Avassetwriter. But I'm not sure where to extract RTCVideoFrame in real time.
This is my code.
struct VideoView: UIViewRepresentable {
let videoTrack: RTCVideoTrack?
@Binding var refreshVideoTrack: Bool
//RTCNSGLVideoView
//RTCMTLNSVideoView
func makeUIView(context: Context) -> RTCEAGLVideoView {
let view = RTCEAGLVideoView(frame: .zero)
view.contentMode = .scaleAspectFill
return view
}
func updateUIView(_ view: RTCEAGLVideoView, context: Context) {
if(refreshVideoTrack){
videoTrack?.add(view)
refreshVideoTrack = false
}
}
}
VideoView(videoTrack: homeViewModel.remoteVideoTrack, refreshVideoTrack: Binding<Bool>(get: {return homeViewModel.refreshRemoteVideoTrack},
set: { p in homeViewModel.refreshRemoteVideoTrack = p}))
I'm using RTCPeerConnectionDelegate for get remoteVideoTrack
func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
dLog("")
remoteVideoTrack = stream.videoTracks.first
remoteVideoTrack?.isEnabled = true
refreshRemoteVideoTrack = true
}
Upvotes: 1
Views: 1197
Reputation: 591
To get the RTCVideoFrame,you can create an intermediate RTCVideoRenderer
class FrameRenderer : NSObject, RTCVideoRenderer {
func setSize(_ size: CGSize) {}
func renderFrame(_ frame: RTCVideoFrame?) {}
}
videoTrack?.add(FrameRenderer())
Upvotes: 1