MediaRecorder incorrect bitrate in output file?

36 views Asked by At

I'm trying to understand how bitrate works in MediaRecorder

I have set for example 192 kbps:

MediaRecorder.setAudioEncodingBitRate(192000)

but when I retrieve the bitrate from MediaStore (or from any other software on Android/PC) of recordings I always get a higher value:

getBitrate 194411

private fun getBitrate(context: Context, uri: Uri): Int? {
    try {
        context.contentResolver.query(
            uri,
            arrayOf(MediaStore.MediaColumns.BITRATE),
            null, null, null
        )?.use { cursor ->
            var bitrate: Int? = null
            var duration: Long? = null
            if (cursor.moveToFirst()) {
                val bitrateColumnIdx = cursor.getColumnIndex(MediaStore.MediaColumns.BITRATE)
                if (bitrateColumnIdx != -1) {
                    return cursor.getIntOrNull(bitrateColumnIdx).also {
                        Timber.d("getBitrate $it")
                    }
                }
            }
        }
    } catch (e: Throwable) {
        e.printStackTrace()
    }
    return null
}

Why is it happening?

1

There are 1 answers

1
vrobbi On

The code below works on chrome well

var options = { mimeType: 'video/webm; codecs=av1,opus', audioBitsPerSecond: 8000, videoBitsPerSecond: 32000 };

try to put a higher number for videoBitsPerSeconds (eg, 512000) and you will see the quality of video is better