CameraX Video UseCase Audio Quality

Although video recording is not yet officially supported in the CameraX library, you still can use the VideoCapture UseCase. There are plenty of StackOverflow and GitHub sample projects showing how to implement this, so I will not go over that here. What I will mention, however, is that none of the samples that I have seen so far address the audio quality.

When you are setting up your VideoCapture instance, you may have noticed VideoCaptureConfig has a couple audio methods. You may have also noticed that the default values for these will leave you with terrible audio quality, and that searching the web reveals nothing as to what you should use for these – no documentation from Google as it isn’t supported yet, and no samples I have seen so far touch on it. The relevant ones you should adjust will set the bit rate, sample rate, and audio channel count. Here’s an example:

    VideoCaptureConfig.Builder().apply {
        setAudioBitRate(320_000)
        setAudioSampleRate(44_100)
        setAudioChannelCount(2)

        /* setup other things here  */
    }

This will set a bitrate of 320bps, a sample rate of 44.1 kHz, and record in stereo. Your videos will sound much better!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s