Question: 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.

Answer: 
Using my HTC Hero (and hence adjusting from 480x800 to 320x480), this works if I use rgb565 instead of 8888:

```
ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s 320x480 -i fb0 -f image2 -vcodec png image.png

```
This might be related to the issue [Reading binary Data from adb shell's stdout](https://stackoverflow.com/questions/13578416/read-binary-stdout-data-from-adb-shell) 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](https://stackoverflow.com/questions/13578416/read-binary-stdout-data-from-adb-shell)] 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 help

other 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.