gpt4 book ai didi

android - MediaRecorder,录制音视频音量很低

转载 作者:太空狗 更新时间:2023-10-29 13:59:27 26 4
gpt4 key购买 nike

我在 android 项目上使用 MediaRecorder 来录制视频和音频文件。它可以正确录制,但两个文件的音量都非常低。

我用它来配置 MediaRecorder 来录制音频

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + ConfigApp.RECORDINGS_FOLDER);
if (!folder.exists())
success = folder.mkdir();
if (success) {
mFileName = folder + timeStamp + ".m4a";
currentFile = mFileName;
chrono.setBase(SystemClock.elapsedRealtime());
chrono.start();
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);


try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(TAG, "prepare() failed");
}
mRecorder.start();
handler.post(updateVisualizer);
}

当我录制视频时这是

// BEGIN_INCLUDE (configure_preview)
mCamera = CameraHelper.getDefaultCameraInstance();
// We need to make sure that our preview and recording video size are supported by the
// camera. Query camera to find all the sizes and choose the optimal size given the
// dimensions of our preview surface.
Camera.Parameters parameters = mCamera.getParameters();
List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
Camera.Size optimalSize = CameraHelper.getOptimalPreviewSize(mSupportedPreviewSizes,
mSurfaceView.getWidth(), mSurfaceView.getHeight());

// Use the same size for recording profile.
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
profile.videoFrameWidth = optimalSize.width;
profile.videoFrameHeight = optimalSize.height;

// likewise for the camera object itself.
parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
mCamera.setParameters(parameters);
try {
// Requires API level 11+, For backward compatibility use {@link setPreviewDisplay}
// with {@link SurfaceView}
mCamera.setPreviewDisplay(mSurfaceView.getHolder());
mCamera.setDisplayOrientation(90);

} catch (IOException e) {
Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
return false;
}
// END_INCLUDE (configure_preview)


// BEGIN_INCLUDE (configure_media_recorder)
mMediaRecorder = new MediaRecorder();

// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);

// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER );
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
mMediaRecorder.setProfile(profile);

// Step 4: Set output file
String path = getVideoFile(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO).getAbsolutePath();
currentFile = path;
mMediaRecorder.setOutputFile(path);
mMediaRecorder.setOrientationHint(270);

// END_INCLUDE (configure_media_recorder)

// Step 5: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
return true;

除了 AudioSource.CAMCORDER 之外,我还在 setAudioSource 上尝试了其他选项,但音量总是很低

我需要配置任何额外的参数吗?

最佳答案

我在使用 MediaRecorder 时遇到了同样的问题,最终找到了正确的工作解决方案。以下是您需要为高质量录音做的一些修改:
mRecorder.setAudioEncodingBitRate(16*44100);
mRecorder.setAudioSamplingRate(44100);
stackoverflow 上的许多解决方案建议使用 .setAudioEncodingBiteRate(16),但 16 太低而不能被视为无意义。

来源:@Grant 在 stackoverflow 上的回答 very poor quality of audio recorded on my droidx using MediaRecorder, why?

关于android - MediaRecorder,录制音视频音量很低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36984853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com