androidsurfaceviewandroid-camera2android-mediacodecvideo-recording

Switch Camera (Back to front and Front to back) in Android while recoding the video - Camera2


What I am looking for

What I have tried so far

From the FlipCam repo I can see that they are trying to render the camera output on the GLSurfaceView and when we start the recording they copy the frames using from surface view to MediaRecorder's surface using OpenGL.

Now, OpenGL is very low level API and i would rather go with some high level APIs where there is less maintenance.

Also there is an approach where we just save the temporary part of videos and then merge at the end. But doing so would take some time to process and I would like the output to be almost instant when user stops the recording.

Would this be possible with MediaCodec and MediaMuxer? Please share your thoughts or provide any guiding path to implement this using latest and comparatively high level Android APIs.


Solution

  • The Jetpack CameraX library just added support for this capability in its 1.3.0-rc01 release.

    Even if you don't want to adopt the library, you could see how it added this capability. I'm not sure MediaRecorder can handle this, but MediaCodec certainly can, most likely using persistent surfaces.