Actually I need to record video of different resolution (like 480p, 720p, 1080p) with my app. In HTC One S (Android 4.0.4), video recording is not working with any of the Camcorder profile (except with QUALITY_LOW, QUALITY_CIF and QUALITY_QCIF but recorded video gets corrupted). Below is my code snippet:
mMediaRecorder = new MediaRecorder();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH));
mMediaRecorder.setOutputFile(getOutputMediaFile().toString());
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
I have also tried to set the MediaRecorder profile parameters manually, but I am only able to record video with mMediaRecorder.setVideoSize(640, 480). With other value-pairs( like (960, 540) ), I am not able to record video.
mMediaRecorder = new MediaRecorder();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFile(getOutputMediaFile().toString());
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setAudioEncodingBitRate(196608);
mMediaRecorder.setVideoSize(640, 480);
// mMediaRecorder.setVideoSize(1920, 1080); // Not Working
// mMediaRecorder.setVideoSize(1280, 720); // Not Working
// mMediaRecorder.setVideoSize(960, 540); // Not Working
mMediaRecorder.setVideoFrameRate(16);
mMediaRecorder.setVideoEncodingBitRate(3000000);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setOutputFile(getOutputMediaFile().toString());
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
With other values of video size (e.g. setVideoSize(1280, 720)), I am not able to record video and getting RunTimeException. Below is my stacktrace:
09-17 19:29:22.431: E/MediaRecorder(11634): start failed: -19
09-17 19:29:22.431: V/MediaRecorderJNI(11634): process_media_recorder_call
09-17 19:29:22.431: E/MediaRecorder(11634): start failed.
09-17 19:29:22.431: E/MediaRecorder(11634): try to delete broken file: /mnt/sdcard /Movies/MyApp/VID_20140917_192922.mp4
09-17 19:29:22.431: D/AndroidRuntime(11634): Shutting down VM
09-17 19:29:22.431: W/dalvikvm(11634): threadid=1: thread exiting with uncaught exception (group=0x40aaaa08)
09-17 19:29:22.431: E/AndroidRuntime(11634): FATAL EXCEPTION: main
09-17 19:29:22.431: E/AndroidRuntime(11634): java.lang.RuntimeException: start failed.
09-17 19:29:22.431: E/AndroidRuntime(11634): at android.media.MediaRecorder._start(Native Method)
09-17 19:29:22.431: E/AndroidRuntime(11634): at android.media.MediaRecorder.start(MediaRecorder.java:770)
09-17 19:29:22.431: E/AndroidRuntime(11634): at com.collaaj.activity.camera.CameraActivity.captureVideo(CameraActivity.java:98)
09-17 19:29:22.431: E/AndroidRuntime(11634): at com.collaaj.activity.camera.CameraActivity.onClick(CameraActivity.java:68)
09-17 19:29:22.431: E/AndroidRuntime(11634): at android.view.View.performClick(View.java:3538)
09-17 19:29:22.431: E/AndroidRuntime(11634): at android.view.View$PerformClick.run(View.java:14319)
09-17 19:29:22.431: E/AndroidRuntime(11634): at android.os.Handler.handleCallback(Handler.java:608)
09-17 19:29:22.431: E/AndroidRuntime(11634): at android.os.Handler.dispatchMessage(Handler.java:92)
09-17 19:29:22.431: E/AndroidRuntime(11634): at android.os.Looper.loop(Looper.java:156)
09-17 19:29:22.431: E/AndroidRuntime(11634): at android.app.ActivityThread.main(ActivityThread.java:5045)
09-17 19:29:22.431: E/AndroidRuntime(11634): at java.lang.reflect.Method.invokeNative(Native Method)
09-17 19:29:22.431: E/AndroidRuntime(11634): at java.lang.reflect.Method.invoke(Method.java:511)
09-17 19:29:22.431: E/AndroidRuntime(11634): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-17 19:29:22.431: E/AndroidRuntime(11634): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-17 19:29:22.431: E/AndroidRuntime(11634): at dalvik.system.NativeStart.main(Native Method)
Note: 1). Video recording of every available resolution is working fine with native camera app of HTC One S. 2). Video recording with all Camcorder profiles are working fine on other devices like Samsung Galaxy S3(Android 4.3), Samsung Galaxy S4(Android 4.4.2) and LG Nexus 4(Android 4.4).
Please guide me to resolve the issue. Any help or guidance will be well appreciated.