【问题标题】:How to record video without audio using CameraX如何使用 CameraX 录制没有音频的视频
【发布时间】:2021-08-10 03:35:44
【问题描述】:
videoCapture = VideoCapture.Builder()
            .setMaxResolution(size)
            .setDefaultResolution(size)
            .setCameraSelector(cameraSelector!!)
            .setTargetAspectRatio(AspectRatio.RATIO_4_3)
            .build()

有没有静音的选项?

【问题讨论】:

  • 可能this有帮助
  • @Sniffer 我无法从该链接中找到任何解决方案,无论如何谢谢您的帮助。

标签: android kotlin android-camerax


【解决方案1】:

目前您无法使用 CameraX 录制没有音频的视频,因此您可以选择 Camera2,或者您可以使用 CameraX 录制视频,然后使用 FFmpeg 删除音频 - 此过程不涉及重新编码,因此很快。 您可以使用库来手动执行命令,例如 this one,或者您可以选择自动将音频与视频分开的库,例如 this one

【讨论】:

    【解决方案2】:

    使用 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")
        }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多