【发布时间】:2022-09-29 11:24:37
【问题描述】:
如何为 webRTC 视频轨道添加模糊效果?我正在使用 WebRTC 构建一个视频通话应用程序,出于安全原因,我需要模糊使用我的应用程序的人的背景,还需要模糊来自另一端的所有视频。 (随机的人可以打电话,所以模糊他们所有的视频是一种安全措施,你可以在感觉舒服时关闭它)。
我如何开始本地视频捕获的一些代码
private var videoCapturer: CameraVideoCapturer = getCamera()
private fun getCamera(isFrontFacing: Boolean = true): CameraVideoCapturer {
return Camera1Enumerator(true).run {
deviceNames.find {
if (isFrontFacing)
isFrontFacing(it)
else
isBackFacing(it)
}?.let {
createCapturer(it, null)
} ?: throw IllegalStateException()
}
}
fun startLocalVideoCapture(localVideoOutput: SurfaceViewRenderer, localVideoOutputPiP: SurfaceViewRenderer? = null, localVideoOutputInAppPip: SurfaceViewRenderer? = null, isMicOn: Boolean = true) {
localVideoOutput.setMirror(true)
val localVideoSource = peerConnectionFactory.createVideoSource(false)
val surfaceTextureHelper = SurfaceTextureHelper.create(Thread.currentThread().name, rootEglBase.eglBaseContext)
(videoCapturer as VideoCapturer).initialize(surfaceTextureHelper, localVideoOutput.context, localVideoSource.capturerObserver)
videoCapturer.startCapture(1280, 962, 24)
localVideoTrack = peerConnectionFactory.createVideoTrack(LOCAL_TRACK_ID, localVideoSource)
val localAudioTrack = peerConnectionFactory.createAudioTrack(
LOCAL_AUDIO_TRACK_ID, peerConnectionFactory.createAudioSource(MediaConstraints())
)
localAudioTrack.setEnabled(isMicOn)
localVideoTrack?.addSink(localVideoOutput)
localStream = peerConnectionFactory.createLocalMediaStream(LOCAL_STREAM_ID)
localStream.audioTracks.add(localAudioTrack)
localStream.videoTracks.add(localVideoTrack)
videoSender = peerConnection?.addTrack(localVideoTrack, arrayListOf(LOCAL_STREAM_ID))
peerConnection?.addTrack(localAudioTrack, arrayListOf(LOCAL_STREAM_ID))
}
以及我如何接收视频:
override fun onAddStream(p0: MediaStream?) {
super.onAddStream(p0)
if (p0?.videoTracks?.isNotEmpty() == true) {
p0.videoTracks?.get(0)?.addSink(remote_view)
remoteVideoTrack = p0.videoTracks?.get(0)
callControlsViewModel.isClientCamOn.postValue(true)
}
if (p0?.audioTracks?.isNotEmpty() == true) {
remoteAudioTrack = p0.audioTracks?.get(0)
callControlsViewModel.isClientMicOn.postValue(true)
}
}
标签: android android-studio webrtc webrtc-android