【问题标题】:How to record SurfaceView preview如何录制 SurfaceView 预览
【发布时间】:2020-09-08 11:40:30
【问题描述】:

我正在开发一个应用程序,其中我只使用 Surface View 预览帧。 谁能告诉我如何录制这个 SurfaceView 预览的视频?

【问题讨论】:

  • 使用媒体投影 API 录制整个屏幕。
  • 我不想录全屏,我只想录SurfaceView预览。
  • AFAIK,你别无选择。

标签: android surfaceview video-recording


【解决方案1】:

你有 3 种可能性:

1 - 捕获SurfaceView 的每一帧并将所有捕获的位图存储到一个数组中,之后您可以使用MediaRecord 将其编码为视频文件

这是一个完整的例子:ViewRecorder

2 - 使用EZFilter (我已经测试过),有点长,但值得一试:

XML:

<RelativeLayout
            android: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.TextureFitView
                android: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.GLLinearLayout
                android: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:

GLLinearLayout mLinearLayout = findViewById(R.id.gl_layout);
ISupportRecord mSupportRecord;
TextureFitView renderView;
RenderPipeline mRenderPipeline = new RenderPipeline();

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);

当你想开始录制时:

 private void startRecording() {
        this.mSupportRecord.startRecording();
        this.mSupportRecord.enableRecordAudio(false);
 }

停止录制:

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

3 - 您可以使用FFmpeg捕获整个屏幕并裁剪录制的视频

【讨论】:

    猜你喜欢
    • 2015-01-17
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    相关资源
    最近更新 更多