Media Recorder with HEVC encoding
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start at MainActivity.java:226 and review the MediaRecorder configuration shown in the issue, especially the HEVC encoder and the start failed: -2147483648 exception. Check the surrounding sample entry point and determine whether the issue is reproducible; the payload does not define a code change or a clear done condition.
Written by the indexing model from the issue text.
Description
Hello,
When I set videoEndoderto HEVC mediarecorder.start() is not working below is the exception. Kindly let me know the reason or whats going wrong.
{
// 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();
List<Camera.Size> mSupportedVideoSizes = parameters.getSupportedVideoSizes();
Camera.Size optimalSize = CameraHelper.getOptimalVideoSize(mSupportedVideoSizes,
mSupportedPreviewSizes, mPreview.getWidth(), mPreview.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.setPreviewTexture(mPreview.getSurfaceTexture());
} 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.DEFAULT );
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoSize(1280,720);
mMediaRecorder.setVideoEncodingBitRate(1500);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.HEVC);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
// mMediaRecorder.setProfile(profile);
// Step 4: Set output file
mOutputFile = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO);
if (mOutputFile == null) {
return false;
}
mMediaRecorder.setOutputFile(mOutputFile.getPath());
// 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;
}
Exceptions
D/vndksupport: Loading /vendor/lib/hw/gralloc.msm8974.so from current namespace instead of sphal namespace.
07-02 17:34:19.078 24853-24889/com.example.android.mediarecorder D/vndksupport: Loading /vendor/lib/hw/[email protected] from current namespace instead of sphal namespace.
07-02 17:34:19.080 24853-24889/com.example.android.mediarecorder D/vndksupport: Loading /vendor/lib/hw/gralloc.msm8974.so from current namespace instead of sphal namespace.
07-02 17:34:20.585 24853-24897/com.example.android.mediarecorder E/MediaRecorder: start failed: -2147483648
07-02 17:34:20.592 24853-24897/com.example.android.mediarecorder E/AndroidRuntime: FATAL EXCEPTION: AsyncTask android/android-MediaRecorder#1
Process: com.example.android.mediarecorder, PID: 24853
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:353)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at com.example.android.mediarecorder.MainActivity$MediaPrepareTask.doInBackground(MainActivity.java:226)
at com.example.android.mediarecorder.MainActivity$MediaPrepareTask.doInBackground(MainActivity.java:218)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
- Dominant language
- Kotlin
- Stars
- 1.4k
- Forks
- 777
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from android/media-samples
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
android/media-samples#117 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
android/media-samples#116 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 15/100
android/media-samples#112 ·
-
بانلبرلبتOpen
Difficulty 5/5 Over a week Newbie friendliness 1/100
android/media-samples#111 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
android/media-samples#97 · 3 comments · 2 reactions ·
All issues in android/media-samples
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
MetrolistGroup/Metrolist#5426 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
🐛 Type:Bug 📥 State:Awaiting Assignment 🚨 Priority: P0 - Critical
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
micronizationlab/glafira-ai-hub#785 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sorsama/deepseek-harness-mobile#154 ·
Maintainers usually reply within 1 day
-
0. Needs triage enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day