可以使用MediaProjection API在录制过程中处理每一帧记录的内容吗?

huangapple go评论71阅读模式
英文:

Is it possible to use MediaProjection API and process every recorded frame during recording?

问题

我想制作一个应用,模拟飞利浦电视上常见的Ambilight效果。为此,我有一个Arduino控制着LED灯,并在串行端口上监听命令以设置LED灯的颜色。

理论上,我希望我的应用能够在后台录制我的Android电视屏幕。这可以通过使用MediaProjection API来实现。但据我所知,你只能在停止录制后获得视频文件。但我希望能够在每隔n毫秒处理每一帧,或者每隔n秒截取一次屏幕截图。

我的问题: 在录制过程中是否可以访问单个帧,或者是否可以使用MediaProjection API在后台每隔n秒钟截取一次屏幕截图。或者是否有其他实现这一目标的方法?

英文:

I want to build an app which simulates ambilight you know from Philips TV's. For this I have an Arduino that controls my LEDs and listens for commands on the serial port to set the color of the LEDs.

In theory I want my app to record the screen of my Android TV in background. This can be achieved with the MediaProjection API. But as far as I know you can only get the video file after stopping the recording. But I want to process every frame or take a screenshot every n milliseconds.

My Question: Can you access a single frame while recording or is it possible to take a screenshot every n seconds in background using the MediaProjection API. Or is there another way achieving this?

答案1

得分: 1

经过进一步调查,我找到了一个解决方案。您可以在MediaProjection上使用ImageReader,并实现其OnImageAvailable回调函数,该回调函数在每次VSync完成时被调用。然后,您可以从阅读器中提取一个位图。

英文:

After further investigation I found a Solution. You can use a ImageReader on the MediaProjection and implement its OnImageAvailable callback this callback gets called every time a VSync is done. Then you are able to extract a Bitmap from the reader.

huangapple
  • 本文由 发表于 2020年10月1日 19:39:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64154640.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定