Screenshot of the Nexus One from adb?

2019-01-20 23:05发布

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.

14条回答
祖国的老花朵
2楼-- · 2019-01-20 23:38

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

查看更多
放我归山
3楼-- · 2019-01-20 23:39

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

查看更多
我命由我不由天
4楼-- · 2019-01-20 23:40

If you have dos2unix installed, then the below

adb shell screencap -p | dos2unix > screen.png
查看更多
狗以群分
5楼-- · 2019-01-20 23:40

rgb565 instead of 8888 also work on emulator

查看更多
老娘就宠你
6楼-- · 2019-01-20 23:41

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])
查看更多
我只想做你的唯一
7楼-- · 2019-01-20 23:42

Actually, there is another very simple ability to grab screenshot from your android device: write simple script 1.script like this:

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

# Takes a screenshot
result = device.takeSnapshot()

# Writes the screenshot to a file
result.writeToFile('1.png','png')

and call monkeyrunner 1.script.

查看更多
登录 后发表回答