SetVideoSize () crashes in high resolution

I would like to give users the ability to set different permissions.

I 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: good quality and all ...

When I installed it in

 camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P); 

with FLASH on , the video turned greenish and some other weird colors.

I read online and people said it was because QUALITY_480P was probably not supported on my phone. Well, that makes sense.

So I started working on another solution, so I tried ...

 recorder.setVideoSize(640, 480); 

It worked great

but the video looked VERY ugly.

Then I checked the list of supported videos.

 List<Size> GetSupportedVideosResolutions = params.getSupportedVideoSizes(); 

Resolution: 1280x720 listed, therefore

I tried to install 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); 

This gave me a RuntimeException error.

Question:

Why doesn't it let me set the higher resolutions available on the phone?

Any help would be greatly appreciated.

Thanks.

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) 
+6
source share
2 answers

I realized what the problem is. It 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 
+3
source

SOLUTION: Iam1414 answer is CORRECT.

I was all this day and as ridiculous as the seams, his technique works.

I tried to write in 4k (3840 x 2160), I was sure that the device also had the opportunity, but it continued to limit me to 1080 and fell for something more. The decision was mentioned in I144.

-to compose a profile
-set video size

 profile = CamcorderProfile.get(CamcorderProfile.QUALITY_2160P); recorder.setProfile(profile); recorder.setVideoSize(3820, 2160); //NEEDED or it will crash 

Unfortunately, setting the profile blocks me when encoding H264 and did not allow me to install my encoder into my H265 encoder after. So, I hope there is a workaround for this.

Iam1414, Thanks. I would vote for you if I had a reputation :)

Edit: This is a very strange error. Stitches, as if I no longer need to use a workaround. I can write to 2160p just using the appropriate profile. I will investigate further if this remains a problem.

0
source

Source: https://habr.com/ru/post/985443/


All Articles