简体   繁体   English

在Android中记录屏幕的选定区域

[英]Recording selected area of screen in android

I am trying to implement screen recorder. 我正在尝试实现屏幕录像机。 I followed grafika . 我关注了grafika Simply giving Surface from encoder.getInputSurface() to VirtualDisplay does the trick. 只需将Surface从encoder.getInputSurface()给VirtualDisplay就可以了。 Now my task is to encode a certain part of the screen. 现在,我的任务是对屏幕的特定部分进行编码。 So, I was trying to modify the input Surface for the encoder using SurfaceTexture (I think this is right method). 因此,我试图使用SurfaceTexture修改编码器的输入Surface(我认为这是正确的方法)。 But I am not able to use the created surface to record screen and when I pass this Surface to VirtualDisplay I do not get any callback. 但是我无法使用创建的表面来记录屏幕,当我将此表面传递给VirtualDisplay时,我没有得到任何回调。 I also tried to record using TextureMovieEncoder(from grafika) but may be I do not know the correct method. 我也尝试使用TextureMovieEncoder(来自grafika)进行录制,但可能是我不知道正确的方法。

I tried to understand through following userful links. 我试图通过以下有用的链接来理解。 How does an output surface of a Decoder is passed to an input surface of an Encoder? 解码器的输出表面如何传递到编码器的输入表面?

and

Android: Is it possible to create a SurfaceTexture without a SurfaceView? Android:是否可以在没有SurfaceView的情况下创建SurfaceTexture?

And I am sure grafika is a great tutorial but I am stuck. 而且我相信grafika是不错的教程,但是我被困住了。

Please suggest solution or another workable method. 请提出解决方案或其他可行方法。 I am now stuck for days. 我现在被困了好几天。

I think the right way is as follows: 我认为正确的方法如下:

  1. create a SurfaceTexture with an oes texture. 创建具有oes纹理的SurfaceTexture。

  2. connect VirtualDisplay to the surfacetexture created in step 1, so frame will go to the oes texture 将VirtualDisplay连接到在步骤1中创建的曲面纹理,这样框架将转到oes纹理

  3. Register onFrameAvailable listener on the surfacetexture, then you will get the callback continuously 在表面纹理上注册onFrameAvailable侦听器,然后您将连续获得回调

  4. Render the frame in the oes texture to the input surface of encoder. 将oes纹理中的帧渲染到编码器的输入表面。

The key process is step 4. During the process of rendering, you can crop the frame through modify the texture coordinate. 关键过程是步骤4。在渲染过程中,您可以通过修改纹理坐标来裁剪框架。

There is a crop example below: Crop video before encoding with MediaCodec for Grafika's "Continuous Capture" Activity 下面是一个裁剪示例: 在使用MediaCodec进行Grafika的“连续捕获”活动编码之前,裁剪视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM