How to capture the screen using /dev/graphics/fb0 (Android)

℡╲_俬逩灬. 提交于 2019-12-20 08:50:47

问题


How to capture the Android device screen content using /dev/graphics/fb0 and how to make it an image file using the collected data from frame buffer. I know for this it requires the device to be rooted and I am ok with that.

Thanks in advance,


回答1:


This should work:

adb pull /dev/graphics/fb0 fb0
ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 320x480 -i fb0 -f image2 -vcodec png image.png



回答2:


If you have the root privilege.

  1. copy data from fb0 to another file, e.g.

    cat fb0 > tmp
    
  2. At this point, you still can't open the new file. because the data structure of the the file cannot met any image file format. So what you need is to decode it. In that file, every two bytes describe a pixel. the higher 5 bites represent the red color, the lower 5bites represent the blue color and the rest middle 6 bites are green. you can use the info above to build a BMP and any other visible file.




回答3:


Nebkat's solution works sometimes, but, in working on the Dollop test tool, I've learned that there is no universal way for making an image directly from fb0. The Motorola Droid 2 uses RGB 32. The Huawei Ascend uses RGB 565. The Samsung Captivate uses neither and doesn't appear to put the entire screen in the buffer.




回答4:


You might want to replace -pix_fmt rgb32 with -pix_fmt rgb565le for 16-bit devices.




回答5:


If you are not sure about the format of your device frame buffer you can iterate ffmpeg supported formats as follows:

for fmt in $(ffmpeg -pix_fmts|cut -d " " -f 2); do ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt $fmt -s 320x480 -i fb0 -f image2 -vcodec png /tmp/image-$fmt.png; done

The outcome thumbnails are also kind of artistic.



来源:https://stackoverflow.com/questions/4654770/how-to-capture-the-screen-using-dev-graphics-fb0-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!