MediaRecorder,录制音视频音量非常小
Posted
技术标签:
【中文标题】MediaRecorder,录制音视频音量非常小【英文标题】:MediaRecorder, recording audio and video has very low volume 【发布时间】:2016-05-02 14:25:38 【问题描述】:我在一个 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;
我在setAudioSource
上尝试了除AudioSource.CAMCORDER
之外的其他选项,但我的音量总是很低
我需要配置任何额外的参数吗?
【问题讨论】:
【参考方案1】:我在使用 MediaRecorder 时遇到了同样的问题,最终找到了正确的工作解决方案。
为了获得高质量的录音,您需要进行以下一些修改:
mRecorder.setAudioEncodingBitRate(16*44100);
mRecorder.setAudioSamplingRate(44100);
*** 上的许多解决方案都会建议.setAudioEncodingBiteRate(16)
,但 16 太低而无法被认为是无意义的。
来源:@Grant 对 *** 的回答 very poor quality of audio recorded on my droidx using MediaRecorder, why?
【讨论】:
【参考方案2】:尝试
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
然后,您的 AudioSource 设置为 MIC。
【讨论】:
原来的录音app或者camcoder app可以吗? 对不起,我只是分享我的经验。并且需要说检查硬件。我是开发语音跟踪应用程序。所以我也有同样的困难。并尝试更改 setAudioSource 选项即可。以上是关于MediaRecorder,录制音视频音量非常小的主要内容,如果未能解决你的问题,请参考以下文章