无法设置视频质量为媒体recorder.video产生闪烁视频 [英] Can't set video quality for media recorder.video produces flickering video
问题描述
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
// activate this for recording with sound\
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoSize(getMaxSupportedVideoSize().width,getMaxSupportedVideoSize().height);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
// Step 4: Set output file
mMediaRecorder.setOutputFile(getOutputMediaFile("movie"));
// Step 4: Set output file
mMediaRecorder.setOutputFile(getOutputMediaFile("movie"));
// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
mMediaRecorder.setOrientationHint(90);
以上code工作正常但是,视频的质量并不像一样的视频我拍了原生的Android摄像头,我的视频使用的媒体记录器质量差比较到本机录制的,我怎么能提高视频的质量。
above code is working fine But, the quality of video is not as same as video i shoot over native android camera, my video recorded using media recorder is poor quality compare to the native one, how can i improve the video quality.
如果任何人知道帮我out.Thanks
If any one knows help me out.Thanks
推荐答案
我不是一个Java / Android开发,我使用Xamarin和C#,但我有很多同样的问题,我的解决办法应该是直接适用(甚至句法几乎是相同的)。
I'm not a Java/Android dev, I'm using Xamarin and C#, but I had much the same problem, and my solution should be directly applicable (even the syntax is almost identical).
我发现,如果你使用 setCamera
(并且是previewing你开始你的mediaRecorder前的摄像头看到的),那么它不会让你改变对 mediaRecorder
质量设置。
I found that if you're using setCamera
(and are previewing what the camera sees before you start up your mediaRecorder) then it won't let you change the quality settings on the mediaRecorder
.
然后当你调用 mediaRecorder.start()
,它要么崩溃或冻结或显示垃圾。
And then when you call mediaRecorder.start()
, it either crashes or freezes or displays garbage.
基本上,只要摄像机是previewing,所述MediaRecorder将不会被允许启动在一个不同的质量到该相机已经录制。您需要
Basically, as long as the Camera is previewing, the MediaRecorder won't be allowed to start recording at a different quality to that which the camera already has. You need to
- 停止在相机 preVIEW,
- 拿走了preVIEW表面
- 分配摄像机到MediaRecorder(与
setCamera
) - 将MediaRecorder了你所需要的品质
- 然后重新安装preVIEW表面
- stop the camera preview,
- take away its preview surface
- assign the camera to the MediaRecorder (with
setCamera
) - set the MediaRecorder up with the quality you need
- then reattach the preview surface
然后,当你开始录制,一切正常,因为它应该。
Then when you start recording, everything works as it should.
所以你的情况,你打电话之前 mediaRecorder.setCamera()
,请尝试以下操作:
So in your case, just before you call mediaRecorder.setCamera()
, try the following:
mCamera.stop preVIEW();
mCamera.set previewDisplay(NULL);
然后再往下,做你的
mRecorder.setCamera()
这是我的解决方案。我现在可以设置视频质量为720p(或1080p),它完美的作品。
That was the solution for me. I can now set the video quality to 720p (or 1080p) and it works perfectly.
然而,当你停止录制,您的previewing也将停止。
However, when you stop recording, your previewing will also stop.
您可能会需要恢复您的
mCamera.set previewDisplay(M preview.getHolder()。getSurface())
要它是什么之前,并重新启动实际preVIEW。
to what it was before, and restart the actual preview.
我希望它为你工作太:)
I hope it works for you too :)
这篇关于无法设置视频质量为媒体recorder.video产生闪烁视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!