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

Is there any option to mute audio?

jishan siddique
  • 1,848
  • 2
  • 12
  • 23

2 Answers2

0

Currently you can't record a video without audio using CameraX, so your alternatives are either Camera2, or you can record the video using CameraX, and then remove the audio using FFmpeg - this process does not involve re-encoding so it is pretty quick. You can use a library for executing commands manually like this one, or a library that you have options to automatically separate the audio from the video like this one.

Raz Leshem
  • 191
  • 1
  • 7
0

Using CameraX, you can enable or disable the audio like stated in their sample app :

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

Don't forget too check for permissions before this.

confusedstudent
  • 353
  • 3
  • 11