This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathresnap.sh
More file actions
executable file
·145 lines (131 loc) · 3.62 KB
/
resnap.sh
File metadata and controls
executable file
·145 lines (131 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bash
# 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/>.
# Author : Evan Widloski <evan@evanw.org>, Patrick Pedersen <ctx.xda@gmail.com>
#
# Description : Host sided script for screenshotting the current reMarkable display
#
# Dependencies : FFmpeg, ssh
#
# Thanks to https://github.com/canselcik/libremarkable/wiki/Framebuffer-Overview
# Current version (MAJOR.MINOR)
VERSION="1.0"
# Usage
function usage {
echo "Usage: resnap.sh [-h | --help] [-v | --version] [-r ssh_address] [output_jpg]"
echo
echo "Arguments:"
echo -e "output_jpg\tFile to save screenshot to (default resnap.jpg)"
echo -e "-v --version\tDisplay version and exit"
echo -e "-i\t\tpath to ssh pubkey"
echo -e "-r\t\tAddress of reMarkable (default 10.11.99.1)"
echo -e "-h --help\tDisplay usage and exit"
echo
}
# default ssh address
ADDRESS=10.11.99.1
# default output file
OUTPUT=resnap.jpg
PARAMS=""
while (( "$#" )); do
case "$1" in
-r)
ADDRESS=$2
shift 2
;;
-i)
SSH_OPT="-i $2"
shift 2
;;
-h|--help)
shift 1
usage
exit 1
;;
--) # end argument parsing
shift
break
;;
-*|--*=) # unsupported flags
echo "resnap: Error: Unsupported flag $1" >&2
usage
exit 1
;;
*) # preserve positional arguments
OUTPUT=$1
shift
;;
esac
done
# check if ffmpeg installed
hash ffmpeg > /dev/null
if [ $? -eq 1 ]
then
echo "resnap: Error: Command 'ffmpeg' not found. FFmpeg not installed"
exit 1
fi
# Check if output file already exists
if [ -f $OUTPUT ]; then
extension=$([[ "$OUTPUT" = *.* ]] && echo ".${OUTPUT##*.}" || echo '')
filename="${OUTPUT%.*}"
index="$(ls "$filename"*"$extension" | grep -P "$filename(-[0-9]*)?$extension" | wc -l)";
OUTPUT="$filename-$index$extension"
fi
ssh_cmd() {
ssh root@$ADDRESS $SSH_OPT "$@"
}
rm_version="$(ssh_cmd cat /sys/devices/soc0/machine)"
case "$rm_version" in
"reMarkable 1.0")
pixel_format="gray16le"
video_filters=""
width=1408
height=1872
dump_framebuffer_cmd='cat /dev/fb0'
;;
"reMarkable 2.0")
pixel_format="gray8"
video_filters="-vf transpose=2"
width=1872
height=1404
# see https://github.com/rien/reStream/issues/28
dump_framebuffer_cmd=$(cat << "EOF"
pid=$(pidof xochitl);
offset=$(grep "/dev/fb0" /proc/$pid/maps | awk -F '-' '{print substr($2, 0, 8)}');
dd if=/proc/$pid/mem bs=1 count=2628288 skip=$((0x$offset + 8)) 2>/dev/null
EOF
)
;;
*)
echo "Unsupported reMarkable version: $rm_version."
exit 1
;;
esac
grab_framebuffer() {
ssh_cmd "$dump_framebuffer_cmd"
}
grab_framebuffer | ffmpeg \
-loglevel panic \
-vcodec rawvideo \
-f rawvideo \
-pixel_format "$pixel_format" \
-s "$width","$height" \
-i - \
-vframes 1 \
-f image2 \
$video_filters \
-vcodec mjpeg $OUTPUT
if [ ! -f "$OUTPUT" ]; then
echo "resnap: Error: Failed to capture screenshot"
exit 1
fi