2

I'm coding my first android app, and my app has a video recording feature. So I did some research to get the "stuff" ready and run and managed to look into the google sample on github: https://github.com/googlesamples/android-Camera2Video

So I took a deep dive into the code and yeah quite much just to make a video..

So I do have some restrictions to my camera feature and that is that it runs smoothly with some stable constant 25 Frames per Seconds...

And what I've seen so far there are some setters from the MediaRecorder class (see https://developer.android.com/reference/android/media/MediaRecorder.html)

        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

        mMediaRecorder.setOutputFile(mNextVideoAbsolutePath);
        mMediaRecorder.setVideoEncodingBitRate(10000000);
        mMediaRecorder.setCaptureRate(25);
        mMediaRecorder.setVideoFrameRate(25);

        mMediaRecorder.setVideoSize(mVideoSize.getWidth(), getHeight());
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

to set the frame rate, but hence those give a damn about my 25 fps - so generally the output "is like" 29,36 fps or 29,54 fps

I do did some resarch looked into my device support fps range and the P30 Pro does support 25 fps and the pixel 3 XL not. I don't even understand why there are such device differences (maybe someone can explain?).

So Camera2 API does provide so much things that there is a CaptureRequest.Builder and so I did some googling and set my captureRequestBuilder with those additional lines

            closePreviewSession();
            setUpMediaRecorder();
            SurfaceTexture texture = mTextureView.getSurfaceTexture();
            assert texture != null;
            texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
            mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);

            mPreviewBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range<Integer>(25,25));

            mPreviewBuilder.set(
                    CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
            mPreviewBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);

But nothing has changed... Is there somebody outhere who has managed to get a stable constant frame rate with the camera2 api?

I hope there is! Thank you if you have read so far!

EDIT Possible duplicates:

Camera2 MediaRecorder changes Frame Rate on Galaxy S9

How to use android camera2 api to record 60 fps video with fixed exposure time

EDIT For the sake of completeness:

Ranges from P30 Pro: P30 Pro ranges

Ranges from Pixel 3 XL: Pixel 3 XL ranges

0stack
  • 51
  • 8
  • 1
    full camera2api support is not a required feature of the android platform currently. lots of devices don't support it fully. you have to see what features are supported on a particular device and design around them(or just tell users that they can't use your app). i recommend doing any framerate smoothing on your own using a native library – Karan Harsh Wardhan Apr 29 '19 at 11:45
  • So I know this particular device that is supporting 25fps (P30pro) and my app doesn't go to the play store.. can you explain a little further your recommendation? what smoothing and which native library? – 0stack Apr 29 '19 at 11:56
  • https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES will give you a definitive answer as to whether the device actually supports the framerate on camera2api or has hidden it on an internal API(some companies do that) . as for video smoothing i meant use a library like ffmpeg to smooth captured video by processing it(either on device or in cloud) – Karan Harsh Wardhan Apr 29 '19 at 12:04
  • I can find no confirmation to your claim that P30 Pro supports video recording at 25 FPS. The reviews I read speak about 60 (bright light only) and 30 FPS. To keep frame rate more stable, you can try to lock auto exposure. – Alex Cohn Apr 29 '19 at 19:24
  • @AlexCohn if I do ```Range[] dummy = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);``` and there I get a range that is [25, 25] for the P30 Pro - maybe I understood something wrong what this range does mean... – 0stack Apr 30 '19 at 08:20
  • If I set ```mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG);``` - there comes nearly 25 fps, but not constant... So is there some extra work to be done? – 0stack Apr 30 '19 at 13:51

0 Answers0