Camera2 Api: Can It Output Two Cameras Into Same Surface?
Solution 1:
Not directly. A Surface can only be owned by a single producing source at a time, so if you include a particular Surface in a session configuration for camera device 0, trying to use it with camera device 1 at the same time will get you an error in session creation for camera device 1.
If you want to do this, you'll need to implement your own merger, which takes in buffers from each camera, and composites them into one output.
The most efficient route for this is likely via the GPU and OpenGL. In short, you'll need to create an OpenGL context and two SurfaceTextures, one for each camera output. Then you can use EGLCreateWindowSurface with the MediaRecorder Surface to create an output EGL window to draw into.
At that point, you can render with the two input textures into your output surface in any way you want - it sounds like what you want is two side-by-side rectangles, each with one camera's output.
The details of setting up an Android EGL environment are too long to put here, but there should be plenty of samples of that available.
Solution 2:
I'm not sure I totally understand your requirement. So you can only show the front or rear camera at any time, you are not able to show both. However, if you are injecting the camera signal to the Android Screen or streaming it then sure it is no problem to split the screen for two camera views.
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><SurfaceViewandroid:id="@+id/surfaceView1"android:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"/><SurfaceViewandroid:id="@+id/surfaceView2"android:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"/></LinearLayout>
But I'm not sure what you are trying to accomplish, so hopefully this helps. Of course even though we evenly spaced the camera surfaces you still need to do the work to get best layout size per camera and properly maintain the aspect ratio per camera view.
Post a Comment for "Camera2 Api: Can It Output Two Cameras Into Same Surface?"