Skip to content Skip to sidebar Skip to footer

How To Record Surfaceview Preview

I am working on an app in which I am using Surface View only for preview of frames. Can anyone tell me how can I record videos of this SurfaceView preview?

Solution 1:

You have 3 possibilities :

1 - Capture each frame of your SurfaceView and store all the captured bitmaps into an array, after that you can encode it to a video file using MediaRecord

Here's a full example of how it works : ViewRecorder

2 - Using EZFilter (I've already tested), It's a little long but it's worth a try :

XML :

<RelativeLayoutandroid:id="@+id/frm"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:animateLayoutChanges="true"android:gravity="center_vertical|center_horizontal"><cn.ezandroid.ezfilter.core.environment.TextureFitViewandroid:id="@+id/render_view"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:layout_gravity="center"android:visibility="gone" /><cn.ezandroid.ezfilter.view.glview.GLLinearLayoutandroid:id="@+id/gl_layout"android:layout_width="wrap_content"android:gravity="center"android:layout_height="wrap_content"android:layout_centerInParent="true"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:background="@android:color/transparent"android:visibility="invisible"><!--PUT YOUR SURFACEVIEW XML HERE--></cn.ezandroid.ezfilter.view.glview.GLLinearLayout></RelativeLayout>

JAVA :

GLLinearLayoutmLinearLayout= findViewById(R.id.gl_layout);
ISupportRecord mSupportRecord;
TextureFitView renderView;
RenderPipelinemRenderPipeline=newRenderPipeline();

mRenderPipeline.setRenderSize((int) surfaceWidth, (int) surfaceHeight);
                mRenderPipeline = EZFilter.input(mLinearLayout)
                        .addFilter(null)
                        .enableRecord(videoPath, true, false)
                        .into(renderView);
                for (GLRender render : mRenderPipeline.getEndPointRenders()) {
                    if (render instanceof ISupportRecord) {
                        mSupportRecord = (ISupportRecord) render;
                    }
                }
                mSupportRecord.setRecordSize(surfaceWidth, surfaceHeight);

When you want to start recording :

privatevoidstartRecording() {
        this.mSupportRecord.startRecording();
        this.mSupportRecord.enableRecordAudio(false);
 }

To stop recording :

privatevoidstopRecording(){
       if (mSupportRecord != null) 
            mSupportRecord.stopRecording();
  }

3 - You can capture the whole screen and crop the recorded video using FFmpeg

Post a Comment for "How To Record Surfaceview Preview"