scrcpy的开发文档DEVELOP.md中,对屏幕获取的方法是轻描淡写的说了下,使用MediaCodeC的相关接口,关联屏幕surface对象,就可以获取屏幕数据了。
https://github.com/Genymobile/scrcpy
打不开的可以看这个
https://gitee.com/mirrors/scrcpy/blob/master/DEVELOP.md
Screen video encoding
The encoding is managed by ScreenEncoder.
The video is encoded using the MediaCodec API. The codec takes its input from a surface associated to the display, and writes the resulting H.264 stream to the provided output stream (the socket connected to the client).
code
private void internalStreamScreen(Device device, FileDescriptor fd) throws IOException {
MediaFormat format = createFormat(bitRate, maxFps, codecOptions);
device.setRotationListener(this);
boolean alive;
try {
do {

本文详细介绍了Android设备上使用MediaCodec和VirtualDisplay实现屏幕录制的代码和流程。通过创建MediaCodec编码器,设置视频格式,创建虚拟显示,并利用编码器从屏幕Surface获取数据,实现屏幕内容的编码和输出。
最低0.47元/天 解锁文章
1317

被折叠的 条评论
为什么被折叠?



