开发者

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

How to capture the Android device screen content using /dev/graphics/fb0 and how to make it an image file using开发者_StackOverflow 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,


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


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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜