VideoCapturer.startCamera(宽度,高度,fps)裁剪不同宽度,高度的相机android



我想打开相机,在Android应用程序中拍摄视频通话。首先,我用这个创建了一个视频捕获器

private fun createCameraCapturer(): VideoCapturer? {
val enumerator: CameraEnumerator = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
Camera2Enumerator(context)
} else {
Camera1Enumerator(false)
}
// Try to find front facing camera
enumerator.deviceNames.forEach {
if (enumerator.isFrontFacing(it)) {
videoCapturer = enumerator.createCapturer(it, null)
if (videoCapturer != null) return videoCapturer
}
}

// Front facing camera not found, try something else
enumerator.deviceNames.forEach {
if (!enumerator.isFrontFacing(it)) {
videoCapturer = enumerator.createCapturer(it, null)
if (videoCapturer != null) return videoCapturer
}
}
return null
}

在我得到一个非空的videoCapturer后,我启动了给定宽度、高度和fps的cameraCapture。

videoCapturer?.initialize(surfaceTextureHelper, context, videoSource?.capturerObserver)
videoCapturer?.startCapture(width, height, fps)

宽度和高度的可能组合如下

0 -> VideoHeader(fps: 5, height: 128, width: 96
1 -> VideoHeader(fps: 5, height: 320, width: 240
2 -> VideoHeader(fps: 10, height: 480, width: 360
3 -> VideoHeader(fps: 10, height: 640, width: 480
4 -> VideoHeader(fps: 15, height: 960, width: 720

我注意到,根据VideoHeader,我在UI视图中看到的视频中有一个裁剪。例如,如果我有一个案例:0,那么参与者的面部右上侧会被裁剪。就像有变焦什么的。有什么办法可以解决这个问题吗?

在SurfaceViewRenderer实例上使用以下代码:

surfaceviewrenderer.setScaleType(Scaletofit)

这不会对流产生缩放效果,也不会裁剪流。你可以根据你的需要玩setScaleType

最新更新