如何录制 SurfaceView 预览 [英] How to record SurfaceView preview
问题描述
我正在开发一个应用程序,在该应用程序中我仅将 Surface View 用于帧预览.谁能告诉我如何录制 SurfaceView 预览的视频?
你有 3 种可能性:
1 - 捕获 SurfaceView
的每一帧并将所有捕获的位图存储到一个数组中,之后您可以使用 MediaRecord
以下是其工作原理的完整示例:ViewRecorder
2 - 使用 EZFilter (我已经测试过),有点长,但值得一试:
XML:
<!--将您的 SURFACEVIEW XML 放在这里--></cn.ezandroid.ezfilter.view.glview.GLLinearLayout></RelativeLayout>
JAVA:
GLLinearLayout mLinearLayout = findViewById(R.id.gl_layout);ISupportRecord mSupportRecord;TextureFitView 渲染视图;RenderPipeline mRenderPipeline = new RenderPipeline();mRenderPipeline.setRenderSize((int)surfaceWidth,(int)surfaceHeight);mRenderPipeline = EZFilter.input(mLinearLayout).addFilter(null).enableRecord(videoPath, true, false).into(renderView);for (GLRender 渲染:mRenderPipeline.getEndPointRenders()) {如果(呈现 ISupportRecord 的实例){mSupportRecord = (ISupportRecord) 渲染;}}mSupportRecord.setRecordSize(surfaceWidth,surfaceHeight);
何时开始录制:
private void startRecording() {this.mSupportRecord.startRecording();this.mSupportRecord.enableRecordAudio(false);}
停止录制:
private void stopRecording(){如果(mSupportRecord != null)mSupportRecord.stopRecording();}
3 - 您可以使用 FFmpeg
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?
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 :
<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);
When you want to start recording :
private void startRecording() {
this.mSupportRecord.startRecording();
this.mSupportRecord.enableRecordAudio(false);
}
To stop recording :
private void stopRecording(){
if (mSupportRecord != null)
mSupportRecord.stopRecording();
}
3 - You can capture the whole screen and crop the recorded video using FFmpeg
这篇关于如何录制 SurfaceView 预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!