Android Camera2 recorded video always showing 30fps frame rate - android

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

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 MediaRecorder CaptureReate and VideoFrameRate have no effect

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?

Frame rate of Camera2 API are coming below of 1 for some of device of Samsung

I am using Camera2 with MediaRecorder. For 30 sec recorded video, the length of the video is coming as 8-9 hours.
When we analyzed, we saw that the frame rate of the video is coming as 0.01 FPS. This is happening only in some of the devices of Samsung like J6, J7.
I am also not able to replicate this issue also.
Here is my code for setting MediaRecorder configuration
mediaRecorder?.apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setVideoSource(MediaRecorder.VideoSource.SURFACE)
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
setOutputFile(nextVideoAbsolutePath)
setVideoEncodingBitRate(1000000)
setVideoSize(320, 240)
setVideoFrameRate(20)
setVideoEncoder(MediaRecorder.VideoEncoder.H264)
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
prepare()
}

MediaCodec Encoding camera surface presentationTime not uniform

I am encoding raw video (1080p) from the camera preview using the MediaCodec class in asynchronous mode. I read the presentation time using the MediaCodec.BufferInfo.presentationTimeUs parameter.
void onOutputBufferAvailable (MediaCodec codec, int index, MediaCodec.BufferInfo info)
I have set the target FPS as 30, so I am expecting a frame every 33 millisecs. However, the presentation time is never uniform and jumps up and down. Has anyone faced similar issue?
See the graph below. It is a graph of time between two consecutive video frames' presentation time as received (Y-Axis) in micro seconds. X-Axis is samples.
Graph plot of video presentation time
Thank you,
Ajay
OpenGL rendering using the Graphika sample app from Google as reference gave much more smoother presentation timestamps.

Getting Low Res. output video recording even after specifying Max Video Size

I am trying to record video in background.When i use codecs to record the video, it is giving me lowest output of 176 x 144 even if i specify video size of 1920 x 1080. Below is my code.
mediaRec.setCamera(camera);
mediaRec.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4_SP);
mediaRec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRec.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRec.setVideoSize(1920,1080);
But when i set profile using Camcorder Profile, i am getting High resolution(1080p) Video But it has some jittery frames in starting.So i want to use codecs, but if i use codecs with below code my app throws exception on stopping video Recording.Any idea on where i doing wrong.I have tested this code on Nexus 4 & One plus One.
mediaRec.setCamera(camera);
mediaRec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRec.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

Categories

Resources