views:

864

answers:

6

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.

A: 

Why can't you just use the ddms utility? It takes nice screenshots.

Cristian
I'm automating the screenshots.
Marcus
+1  A: 

I believe all framebuffers to date are RGB 565, not 888.

Yann Ramin
+2  A: 

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
Cowan
Yeah, it works for me on the Magic/Dream/Hero but not on the N1. Thanks though.
Marcus
+3  A: 

You can simply build this app from the Android source tree: http://android.git.kernel.org/?p=platform/sdk.git;a=tree;f=screenshot;h=d3bfa8c5d4ba1a6b4ac0d7d6f01f8df288917d4e;hb=master

It's a command line utility that grabs a screenshot from the device.

Romain Guy
Awesome! I had no idea that was there. If you're building from source, you've already got it (on OS X) at out/host/darwin-x86/obj/EXECUTABLES/screenshot2_intermediates/screenshot2You can move that somewhere sane, or put it in your path then just: screenshot2 capture.pngand you're done.Thanks!
Marcus
+2  A: 

It seems that frame buffer of N1 uses RGB32 encoding (32 bits per pixel).

Here is my script using ffmpeg:

adb pull /dev/graphics/fb0 fb0
dd bs=1920 count=800 if=fb0 of=fb0b
ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 480x800 -i fb0b -f image2 -vcodec png fb0.png

Another way derived from ADP1 method described here http://code.lardcave.net/entries/2009/07/27/132648/

adb pull /dev/graphics/fb0 fb0
dd bs=1920 count=800 if=fb0 of=fb0b
python rgb32torgb888.py <fb0b >fb0b.888
convert -depth 8 -size 480x800 RGB:fb0b.888 fb0.png

Python script 'rgb32torgb888.py':

import sys
while 1:
 colour = sys.stdin.read(4)
 if not colour:
  break
 sys.stdout.write(colour[2])
 sys.stdout.write(colour[1])
 sys.stdout.write(colour[0])
Olivier
A: 

I think rgb32torgb888.py should be

 sys.stdout.write(colour[0])
 sys.stdout.write(colour[1])
 sys.stdout.write(colour[2])
clsung