diff options
author | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2017-03-02 00:22:39 +0100 |
---|---|---|
committer | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2017-03-02 00:22:39 +0100 |
commit | 32aca4cd4a4de2db13665a49483d7c21601e19f3 (patch) | |
tree | a5307e71dada8dbc0d1daa803430d02d0678e6ad | |
parent | f4f1bb259ec37c05ccaefd80126508ba26a0e666 (diff) | |
download | user-scripts-32aca4cd4a4de2db13665a49483d7c21601e19f3.tar.gz user-scripts-32aca4cd4a4de2db13665a49483d7c21601e19f3.tar.bz2 user-scripts-32aca4cd4a4de2db13665a49483d7c21601e19f3.zip |
a script for taking screenshots
Signed-off-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
-rwxr-xr-x | screencap/screencap.sh | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/screencap/screencap.sh b/screencap/screencap.sh new file mode 100755 index 0000000..77fba1a --- /dev/null +++ b/screencap/screencap.sh @@ -0,0 +1,124 @@ +#!/bin/sh +# +# Copyright (C) 2017 Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +set -e + +FFMEG="ffmpeg" +ADB="adb" +FB_PATH="/dev/graphics/fb0" + +TMP_FB="fb_raw" +TMP_FB_RS="fb_raw_rs" +RECOVERY=false + +print_usage () { + echo + echo "Usage: $0 [OPTIONS] -f OUTPUT.PNG" + echo " $0 [OPTIONS] --filename OUTPUT.PNG" + echo + echo "Options:" + echo "-r, --recovery Device is booted in recovery mode" + echo "-s, --screen-size Specify screen size (mandatory in recovery mode)" + echo +} + +print_recovery_advice () { + echo "For screenshots in recovery mode, the screen size needs to be specified," + echo "e.g. with \"-s 720x1280\"" +} + +get_screen_size () { + if [ -f $( $ADB shell command -v wm ) ]; then + echo "Screen size can't be determined. Are you in recovery mode?" + print_recovery_advice + exit 1 + fi + + SCREEN_SIZE=$( $ADB shell wm size ) + SCREEN_SIZE=$( echo ${SCREEN_SIZE#*: } | tr -d '\r' ) + + echo "Screen size is $SCREEN_SIZE" +} + +take_screenshot () { + SCREEN_SIZE_X=${SCREEN_SIZE%x*} + SCREEN_SIZE_Y=${SCREEN_SIZE#*x} + + if [ $RECOVERY = true ]; then + BS=$(( $SCREEN_SIZE_X * 4 )) + PIX_FMT="bgr0" + else + BS=$(( $SCREEN_SIZE_X * 2 )) + PIX_FMT="rgb565" + fi + + $ADB pull $FB_PATH $TMP_FB + dd bs=$BS count=$SCREEN_SIZE_Y if=$TMP_FB of=$TMP_FB_RS + + $FFMEG -vcodec rawvideo -f rawvideo -pix_fmt $PIX_FMT -s $SCREEN_SIZE \ + -i $TMP_FB_RS -f image2 -vcodec png $OUTFILE + + # cleanup + rm -f $TMP_FB $TMP_FB_RS +} + +while true +do + case "$1" in + -r|--recovery) + RECOVERY=true + shift + ;; + -f|--filename) + OUTFILE="$2" + shift 2 + ;; + -s|--screen-size) + SCREEN_SIZE="$2" + shift 2 + ;; + "") + break + ;; + *) + echo "Unknown option" + print_usage + exit 1 + ;; + esac +done + +if [ "$OUTFILE" = "" ]; then + echo "No output file specified" + print_usage + exit 1 +fi + +if [ $RECOVERY = true ] && [ -f $SCREEN_SIZE ]; then + print_recovery_advice + exit 1 +fi + +$ADB root + +if [ $RECOVERY = false ] && [ -f $SCREEN_SIZE ]; then + get_screen_size +fi + +take_screenshot + +echo "Finished successfully" |