Reputation: 149
I would like to give the users an option to set different resolutions.
I've tried this solution
camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
....
....
mCamera.unlock();
recorder.setCamera(mCamera);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setProfile(camcorderProfile);
It worked perfectly: nice quality and everything...
When I set it to
camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
with FLASH on, the video came out with greenish and some other weird colors.
I read online and people said it is because QUALITY_480P is probably not supported on my phone. Ok, it makes senses.
Therefore, I started working on the different solution, so I've tried....
recorder.setVideoSize(640, 480);
It worked great,
but the video looked VERY ugly.
Next, I checked for a supported video list.
List<Size> GetSupportedVideosResolutions = params.getSupportedVideoSizes();
Resolution: 1280x720 is in the list, so
I've tried to set the following:
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoSize(1280,720);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
It gave me a RuntimeException error.
The question is
Why can't it let me set the higher resolutions that are available on the phone?
Any help would be greatly appreciated,
Thank you.
Edit: added error log
04-18 17:40:07.391: E/AndroidRuntime(30191): java.lang.RuntimeException: start failed.
04-18 17:40:07.391: E/AndroidRuntime(30191): at android.media.MediaRecorder.start(Native Method)
04-18 17:40:07.391: E/AndroidRuntime(30191): at test.com.VideoActivity.prepare_StartRecorder(VideoActivity.java:1009)
04-18 17:40:07.391: E/AndroidRuntime(30191): at test.com.VideoActivity.Recorder_Start_Stop(VideoActivity.java:1102)
04-18 17:40:07.391: E/AndroidRuntime(30191): at test.com.VideoActivity$6.onClick(VideoActivity.java:246)
04-18 17:40:07.391: E/AndroidRuntime(30191): at android.view.View.performClick(View.java:4489)
04-18 17:40:07.391: E/AndroidRuntime(30191): at android.widget.CompoundButton.performClick(CompoundButton.java:104)
04-18 17:40:07.391: E/AndroidRuntime(30191): at android.view.View$PerformClick.run(View.java:18803)
04-18 17:40:07.391: E/AndroidRuntime(30191): at android.os.Handler.handleCallback(Handler.java:730)
04-18 17:40:07.391: E/AndroidRuntime(30191): at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 17:40:07.391: E/AndroidRuntime(30191): at android.os.Looper.loop(Looper.java:137)
04-18 17:40:07.391: E/AndroidRuntime(30191): at android.app.ActivityThread.main(ActivityThread.java:5493)
04-18 17:40:07.391: E/AndroidRuntime(30191): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 17:40:07.391: E/AndroidRuntime(30191): at java.lang.reflect.Method.invoke(Method.java:525)
04-18 17:40:07.391: E/AndroidRuntime(30191): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
04-18 17:40:07.391: E/AndroidRuntime(30191): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
04-18 17:40:07.391: E/AndroidRuntime(30191): at dalvik.system.NativeStart.main(Native Method)
Upvotes: 6
Views: 923
Reputation: 403
SOLUTION: Iam1414's answer IS CORRECT.
I've been at this all day and as ridiculous as it seams, his technique works.
I was attempting to record in 4k(3840 x 2160), I was positive the device had the ability too, but It kept limiting me to 1080 and would crash on anything higher. The solution was as Iam1414 mentioned.
-set the profile
-set the video size
profile = CamcorderProfile.get(CamcorderProfile.QUALITY_2160P);
recorder.setProfile(profile);
recorder.setVideoSize(3820, 2160); //NEEDED or it will crash
Unfortunately setting the profile locks me in at encoding H264 and hasn't allowed me to set my encoder to my H265 encoder after. So hopefully there's a workaround for that as well.
Iam1414, Thank you. I'd vote you up if I had the rep :)
Edit: This is a very strange error. Seams as though I no longer need to use the workaround. I'm able to record in 2160p simply by using the matching profile. I will investigate further if it continues to be an issue.
Upvotes: 0
Reputation: 149
I figured what the problem was. This may help someone else. I ended up with:
camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
recorder.setVideoSize(1280, 720); //NEEDED or it will crash
Code:
camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
....
....
mCamera.unlock();
recorder.setCamera(mCamera);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setProfile(camcorderProfile);
recorder.setVideoSize(1280 720); //NEEDED or it will crash
....
...
//or
CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
recorder.setProfile(camcorderProfile);
recorder.setVideoSize(1920, 1080); //NEEDED or it will crash
Upvotes: 3