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,
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.
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.
copy data from fb0 to another file, e.g.
cat fb0 > tmp
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With