My goal is to be able to type a one word command and get a screenshot from a rooted Nexus One attached by USB.
So far, I can get the framebuffer which I believe is a 32bit xRGB888
raw image by pulling it like this:
adb pull /dev/graphics/fb0 fb0
From there though, I'm having a hard time getting it converted to a png. I'm trying with ffmpeg like this:
ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb8888 -s 480x800 -i fb0 -f image2 -vcodec png image.png
That creates a lovely purple image that has parts that vaguely resemble the screen, but it's by no means a clean screenshot.
This might be related to the issue Reading binary Data from adb shell's stdout where adb attempts to do LF to CRLF conversion for you (it's probably just the windows version of adb). I personally had trouble with it conversion \n to \r\r\n so as a way to convert this it's good to either to use the code at [1] or to to use.
for me running it with (in cygwin):
adb shell 'cat /dev/graphics/fb0' | perl -pi -e 's/\r\r\n/\n/g'
seemed to helpother than that try comparing the Width & height to the size of the file. File size should be evenly divisible by
Width * height
if that's not the case then either the adb tool is automatically doing things for you or it's a more exotic format then rgb545 or rgb8888.if it's just a color issue (ie: everything in the result image is in the right spot) then you might want to consider swapping the Red & Blue channels as some systems (in general) use byte order BGRA instead of RGBA.
I believe all framebuffers to date are RGB 565, not 888.
If you have dos2unix installed, then the below
rgb565
instead of8888
also work on emulatorIt seems that frame buffer of N1 uses RGB32 encoding (32 bits per pixel).
Here is my script using ffmpeg:
Another way derived from ADP1 method described here http://code.lardcave.net/entries/2009/07/27/132648/
Python script 'rgb32torgb888.py':
Actually, there is another very simple ability to grab screenshot from your android device: write simple script
1.script
like this:and call
monkeyrunner 1.script
.