From b47bf35e47f03614c8159383319f4a7a91597422 Mon Sep 17 00:00:00 2001 From: xufuji456 Date: Tue, 22 Mar 2022 22:01:26 +0800 Subject: [PATCH] Feature: apply profile to MediaRecorder --- .../controller/MediaRecordController.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/AndroidMedia/src/main/java/com/frank/androidmedia/controller/MediaRecordController.kt b/AndroidMedia/src/main/java/com/frank/androidmedia/controller/MediaRecordController.kt index e61a21f..cb6693c 100644 --- a/AndroidMedia/src/main/java/com/frank/androidmedia/controller/MediaRecordController.kt +++ b/AndroidMedia/src/main/java/com/frank/androidmedia/controller/MediaRecordController.kt @@ -14,6 +14,7 @@ import android.view.Surface */ open class MediaRecordController { + private val usingProfile = true private var mCamera: Camera? = null private var mMediaRecorder: MediaRecorder? = null @@ -26,9 +27,20 @@ open class MediaRecordController { mMediaRecorder?.setCamera(mCamera) mMediaRecorder?.setAudioSource(MediaRecorder.AudioSource.MIC) mMediaRecorder?.setVideoSource(MediaRecorder.VideoSource.CAMERA) - mMediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4) - mMediaRecorder?.setAudioEncoder(MediaRecorder.AudioEncoder.AAC) - mMediaRecorder?.setVideoEncoder(MediaRecorder.VideoEncoder.H264) + if (usingProfile) { + // QUALITY_480P QUALITY_720P QUALITY_1080P QUALITY_2160P + val profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P) + mMediaRecorder?.setProfile(profile) + } else { + mMediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4) + mMediaRecorder?.setAudioEncoder(MediaRecorder.AudioEncoder.AAC) + mMediaRecorder?.setVideoEncoder(MediaRecorder.VideoEncoder.H264) +// mMediaRecorder?.setVideoSize(640, 480) +// mMediaRecorder?.setVideoEncodingBitRate(5000 * 1000) +// mMediaRecorder?.setVideoFrameRate(25) +// mMediaRecorder?.setAudioChannels(2) +// mMediaRecorder?.setAudioSamplingRate(48000) + } mMediaRecorder?.setOutputFile(outputPath) mMediaRecorder?.setPreviewDisplay(surface) }