3

I'm developing my camera app for my LG G4 and I can't find a way to record at a constant framerate. I took the google sample Camera2 app to add my features.

When I want to record in UHD :

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(35 * 1000 * 1000);
mMediaRecorder.setVideoSize(3840, 2160);
mMediaRecorder.setVideoFrameRate(30);

mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

The framerate of 3 differents output videos is 27.61, 28.39, 26.24 etc .. I can't get a constant framterate at 29.97 of 30fps. I tried to increase bitrate to 50Mbps, decrease it to 30Mbps but it doesn't change anything.

The weirdest part is that I can't even record above 30fps in 1080p :

mMediaRecorder.setVideoSize(1920, 1080);
mMediaRecorder.setVideoFrameRate(60);

It records a FHD footage at 29.69 last time I tried but it is as random as UHD footage. What am I doing wrong ?

I've checked Recording 60fps video with Camera2(on Android version 21) API out but it doesn't work either. I also found some answers but they were using the old camera API (with Camera.Parameters) which is deprecated now.

Is there another parameter ?

Community
  • 1
  • 1
Raphaël
  • 117
  • 1
  • 1
  • 10
  • documentation https://developer.android.com/reference/android/media/MediaRecorder.html#setVideoFrameRate(int) says that `setVideoFrameRate` does not guarantee constant frame rate. Maybe you'll have more luck trying to record a video directly with `Camera2` API instead of `MediaRecorder`, but i'm not familiar with camera2 – nandsito Mar 30 '17 at 12:14
  • `MediaRecorder` is part of `Camera2` API isn't it ? Every example I saw with `Camera2` API were using `MediaRecorder`. As far as I know, there is no record method in `android.hardware.camera2`. Would C/C++ be better to achieve constant 29.97 or 30 fps ? – Raphaël Mar 31 '17 at 07:03
  • `MediaRecorder` and `Camera2` are different APIs. The former is a higher level API for recording audio and video media, and the latter offers camera features near to the hardware level, like `AudioRecorder` does for audio. You are right, `Camera2` doesn't offer video recording. I don't think there is a native API for recording video as well – nandsito Mar 31 '17 at 09:43
  • if you really need to ensure constant framerate, you can configure the camera (not the media recorder) to handle preview frames in a constant rate so you can assemble a video file from the preview frames. It will be a hell of a work, but that should do it. Even so, some devices don't guarantee constant preview frame rate, so take care. I know that can be done with the old `Camera` API, so I believe `Camera2` would allow it too – nandsito Mar 31 '17 at 09:53
  • 1
    "handle preview frames in a constant rate" do you mean "take 30 pictures per second to assemble them" ? It will be hard for the processor, also I have no idea of how to assemble pictures to make a video programmatically – Raphaël Apr 03 '17 at 08:52

1 Answers1

0

NOTE: On some devices that have auto-frame rate, this sets the maximum frame rate, not a constant frame rate. Actual frame rate will vary according to lighting conditions.

try this:

mediaRecorder.setCaptureRate(30);
O. Aroesti
  • 1,016
  • 11
  • 32
hyand
  • 1
  • 3
  • This was posted as an answer, but it does not attempt to answer the question. It should possibly be a comment or deleted altogether. – Marcin Orlowski Apr 27 '20 at 01:56