Android MediaRecorder CaptureReate and VideoFrameRate have no effect - android

I'm using the MediaRecorder to record the device's screen. I'd like to be able to control the frame rate of the video captured.
I've tried setting both the Capture Rate and the VideoFrameRate properties of the MediaRecorder, but they seem to have no effect:
this.mRecorder.setCaptureRate(this.fps);
this.mRecorder.setVideoFrameRate(this.fps);
As per the documentation (setCaptureRate, setVideoFrameRate), I am calling setCaptureRate and setVideoFrameRate after setting the format and video source, and before calling prepare:
this.mRecorder = new MediaRecorder();
this.mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
this.mRecorder.setVideoSource(2);
this.mRecorder.setOutputFormat(2);
this.mRecorder.setOutputFile(this.mFilePath);
this.mRecorder.setVideoSize(screenWidth, screenHeight);
this.mRecorder.setVideoEncoder(2);
this.mRecorder.setAudioEncoder(2);
this.mRecorder.setVideoEncodingBitRate(this.mBitRate);
this.mRecorder.setCaptureRate(this.fps);
this.mRecorder.setVideoFrameRate(this.fps);
this.mRecorder.prepare();
I've checked, and this.fps is set to 5, so it is not like some other incorrect value... and the documentation says:
The fps can go as low as desired
Does anyone know how to set the FPS?

Related

Record IFrames only in Android

My app requires to record a video to capture the IFrames only (and not the P/B frames).
I am making use of the Media Recorder to capture the video (Not using cameraX as I need HEVC and camerax is recording in H.264).
The 'MediaRecorder.MetricsConstants.VIDEO_IFRAME_INTERVAL' is set to 1, by default - hence I get an IFrame every 1 sec and the rest of the frames in a second are 'P'. I need the VIDEO_IFRAME_INTERVAL constant to be set to 0, inorder to make all the frames 'I'. I have tried different ways to set it. Any help would be much appreciated.
I have tried setting it this way:
mRecorder.metrics.deepCopy().apply {
this.putInt(MediaRecorder.MetricsConstants.VIDEO_IFRAME_INTERVAL, 0)
}
Even if I set it to '2', '5' or '10' it doesn't seem to be having an effect.

Android Camera2 recorded video always showing 30fps frame rate

Camera2 recorded video always showing 30fps. I am trying to record video at 240fps using Camera2 api.Even if i use slow motion video recording feature of device camera like Samsung s22, which can record video upto 960fps.It always show video frame rate as 30fps
Here is code snippet
mMediaRecorder!!.setAudioSource(MediaRecorder.AudioSource.MIC)
mMediaRecorder!!.setVideoSource(MediaRecorder.VideoSource.SURFACE)
mMediaRecorder!!.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath!!.isEmpty()) {
mNextVideoAbsolutePath = getVideoFilePath(getActivity());
}
mMediaRecorder!!.setOutputFile(mNextVideoAbsolutePath)
mMediaRecorder!!.setVideoEncodingBitRate(10000000)
mMediaRecorder!!.setVideoFrameRate(240)
mMediaRecorder!!.setVideoSize(mVideoSize!!.width, mVideoSize!!.height)
mMediaRecorder!!.setVideoEncoder(MediaRecorder.VideoEncoder.H264)
mMediaRecorder!!.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
I am also trying this configuration:
mPreviewRequestBuilder?.set(
CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,
Range(240, 240)
)
Any help will be appreciated. Thanks
For normal fps range, you can query available fps range from camera's characteristics and set the desired value using target FPS range capture request key.
For high fps capture, please use CameraConstrainedHighSpeedCaptureSession
https://developer.android.com/reference/android/hardware/camera2/CameraConstrainedHighSpeedCaptureSession

Front Camera Video Capturing Distortion - Android

I am working on Video capturing App. It is working fine for back camera. But when i switch to front CAM the video made is very blur (just some line across the video).
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_720P));
mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
mediaRecorder.setMaxDuration(600000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(50000000); // Set max file size 50M
I have searched a lot and eventually found the solution as below.
The BitRate,setEncodingBitRate,setVideoFrameRate,setVideoSize functions can have parameters according to your or user-end devices. I have used constant values working fine for me. Set them generic accordingly. Also, Remember that camera resolution is also set LOW for Front Cameras.
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
mediaRecorder.setVideoEncodingBitRate(512* 1000);
mediaRecorder.setVideoFrameRate(15);
mediaRecorder.setVideoSize(640,480);
mediaRecorder.setVideoSize( 200, 200 );
mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
mediaRecorder.setMaxDuration(600000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(50000000); // Set max file size 50M
`Attaching Links which helped me to come to this solution.
Blurr/Distorted video Error Insight

Android MediaRecorder - Setting the Profile Not Working

I've looked around but cannot find an answer to my issue. I'm setting the MediaRecorder as follows:
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if(CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P))
mMediaRecorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P));
else
mMediaRecorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW));
On my Samsung S3, QUALITY480 is chosen by the code above. A video file is created but it has zero bytes. The same happens if I explicitly set it to QUALITY_LOW. If I set the profile to QUALITY_720P, then I get proper video. Anyone have any ideas? I don't want to set it to 720 so I can keep the file size down.
Thanks!
I hope you have more code than this bc media recorder is not simple to control see the docs..http://developer.android.com/reference/android/media/MediaRecorder.html
Ummm at first look i would say that you are using camera2 api and you are getting true back for your first desired profile but it is not available on device see the has profile doc on android Dev

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);
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.
If any one knows help me out.Thanks
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).
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.
And then when you call mediaRecorder.start(), it either crashes or freezes or displays garbage.
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
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.
So in your case, just before you call mediaRecorder.setCamera(), try the following:
mCamera.stopPreview();
mCamera.setPreviewDisplay(null);
Then further down, do your
mRecorder.setCamera()
That was the solution for me. I can now set the video quality to 720p (or 1080p) and it works perfectly.
However, when you stop recording, your previewing will also stop.
You'll probably need to reinstate your
mCamera.setPreviewDisplay(mPreview.getHolder().getSurface())
to what it was before, and restart the actual preview.
I hope it works for you too :)
Alternative 1
recorder.setVideoSize(640, 480);
recorder.setVideoFrameRate(16); //might be auto-determined due to lighting
recorder.setVideoEncodingBitRate(3000000);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// MPEG_4_SP
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
Alternative 2
CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
Replace this code:
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoSize(getMaxSupportedVideoSize().width,getMaxSupportedVideoSize().height);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
with :
mMediaRecorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH));

Categories

Resources