Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何录制SurfaceView预览_Android_Surfaceview_Video Recording - Fatal编程技术网

Android 如何录制SurfaceView预览

Android 如何录制SurfaceView预览,android,surfaceview,video-recording,Android,Surfaceview,Video Recording,我正在开发一个应用程序,其中我只使用Surface View预览帧。 有人能告诉我如何录制此SurfaceView预览的视频吗?您有3种可能: 1-捕获SurfaceView的每一帧并将所有捕获的位图存储到一个数组中,然后可以使用MediaRecord将其编码为视频文件 下面是它工作原理的完整示例: 2-使用(我已经测试过了),它有点长,但值得一试: XML: <RelativeLayout android:id="@+id/frm"

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

您有3种可能:

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

下面是它工作原理的完整示例:

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

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>
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();
  }
要停止录制,请执行以下操作:

 private void startRecording() {
        this.mSupportRecord.startRecording();
        this.mSupportRecord.enableRecordAudio(false);
 }
  private void stopRecording(){
       if (mSupportRecord != null) 
            mSupportRecord.stopRecording();
  }

3-您可以使用
FFmpeg

捕获整个屏幕并裁剪录制的视频使用媒体投影API录制整个屏幕。我不想录制整个屏幕,我只想录制SurfaceView预览。好吧,您没有太多选择。