scrcpy学习--(2)屏幕获取

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

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 {

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值