在 android 中将 SurfaceView 动画录制为视频文件

Record SurfaceView animation as video file in android

上次我调查了 android (Adding watermark bitmap over video in android: 4.3's MediaMuxer or ffmpeg) 上的视频导出,这不是一件容易的事。

这是一个场景:我有一个 SurfaceView 和一个在 x,y 坐标处绘制的 BitMap。用户点击图像并将其拖动到步骤 2 和步骤 3。

所以基本上,如果我记录触摸经过的所有 x、y,我可以通过以特定帧速率绘制位图来重放动画。

现在的问题是:有没有一种简单的方法可以使用 android 组件(无 ffmpeg)将 SurfaceView 中的 "animation" 录制到视频文件中?

据我所知,要记录 SurfaceView 的事件,您必须记录屏幕,因为 SurfaceView 不同并且不会在普通视图层次结构中绘制。

In fact, there are cases where the display data for the SurfaceView isn't even accessible to the app processor - it may be the output of a hardware video pipeline that is composited with the display output of the app processor through a dedicated video overlay. Google Groups

一种创造性的方式可以是在活动期间同时捕获屏幕并从位图创建 MOV。请参阅:Create Video From Screen Capture

既然你在做渲染,你可以只渲染两次:一次到显示器,一次到视频。这假设您想要 SurfaceView 内容...如果您还想要其他视图,那么您需要使用屏幕录制方法。

有关工作示例,请参阅 Grafika. For API 21+, you can render onto a MediaRecorder's Surface 中的 "Record GL App",如果您只需要 .mp4 文件,这可能会更容易。