视频编码
说明:
使用MediaCodec对由Camera采集的数据进行编码
1.采集视频数据
参数设置:
帧率:30fps
视频size:1280 x 720
视频比特率:1280 x 720 x 2
mCameraId = if(cameraType == TYPE_FRONT) Camera.CameraInfo.CAMERA_FACING_FRONT else Camera.CameraInfo.CAMERA_FACING_BACK
mCamera = Camera.open(mCameraId)
val params = mCamera?.parameters
//设置nv21格式
params?.previewFormat = ImageFormat.NV21
val videoSizes = params?.supportedVideoSizes
val videoSize = videoSizes?.let {
chooseVideoSize(it) }
mVideoSize = videoSize
//设置预览视频size
params?.setPreviewSize(videoSize?.width!!, videoSize.height)
//设置帧率,此处需要乘以1000
params?.setPreviewFpsRange(mFrameRate * 1000, mFrameRate * 1000)
mCamera?.parameters = params
mCamera?.setPreviewCallback(mPreviewCallback)
mCamera?.setErrorCallback(mErrorCallback)
//设置camera预览角度
val orientation = mContext.resources.configuration.orientation
if(orientation == Configuration.ORIENTATION_LANDSCAPE){
mCamera?.setDisplayOrientation(0)
}else{
mCamera?.setDi