如何使用CameraX录制无音频视频


videoCapture = VideoCapture.Builder()
.setMaxResolution(size)
.setDefaultResolution(size)
.setCameraSelector(cameraSelector!!)
.setTargetAspectRatio(AspectRatio.RATIO_4_3)
.build()

是否有静音的选项?

目前你不能使用CameraX录制没有音频的视频,所以你的替代品要么是Camera2,要么你可以使用CameraX录制视频,然后使用FFmpeg删除音频-这个过程不涉及重新编码,所以它是相当快的。你可以使用一个库来手动执行命令,比如这个,或者一个库,你可以选择自动将音频从视频中分离出来,比如这个。

使用CameraX,您可以启用或禁用音频,就像他们的示例应用程序中所述:

private var audioEnabled=false //you can enable it later
private fun startRecording() {
// create MediaStoreOutputOptions for our recorder: resulting our recording!
val name = "CameraX-recording-" +
SimpleDateFormat(FILENAME_FORMAT, Locale.US)
.format(System.currentTimeMillis()) + ".mp4"
val contentValues = ContentValues().apply {
put(MediaStore.Video.Media.DISPLAY_NAME, name)
}
val mediaStoreOutput = MediaStoreOutputOptions.Builder(
requireActivity().contentResolver,
MediaStore.Video.Media.EXTERNAL_CONTENT_URI)
.setContentValues(contentValues)
.build()

// configure Recorder and Start recording to the mediaStoreOutput.
currentRecording = videoCapture.output
.prepareRecording(requireActivity(), mediaStoreOutput)
.apply { if (audioEnabled) withAudioEnabled() } // here is where the audio gets disabled or enabled based on the boolean
.start(mainThreadExecutor, captureListener)
Log.i(TAG, "Recording started")
}

在此之前不要忘记检查权限。

最新更新