restream/reStream.sh

73 lines
1.9 KiB
Bash
Raw Normal View History

2020-02-12 13:13:14 +01:00
#!/bin/sh
2020-03-12 00:17:13 +01:00
# these are probably the only two parameters you need to change
ssh_host="root@10.11.99.1" # location of the remarkable
landscape=true # set to false if you want it horizontal
# technical parameters
2020-02-12 13:13:14 +01:00
width=1408
height=1872
bytes_per_pixel=2
loop_wait="true"
loglevel="info"
2020-03-12 00:17:13 +01:00
# check if we are able to reach the remarkabl
2020-02-12 13:13:14 +01:00
if ! ssh "$ssh_host" true; then
echo "$ssh_host unreachable"
exit 1
fi
2020-03-12 00:17:13 +01:00
fallback_to_gzip() {
echo "Falling back to gzip, your experience may not be optimal."
echo "Go to https://github.com/rien/reStream/#sub-second-latency for a better experience."
compress="gzip"
decompress="gzip -d"
2020-03-12 00:17:13 +01:00
sleep 2
}
# check if zstd is present on remarkable
if ssh "$ssh_host" "[ -f /opt/bin/zstd ]"; then
compress="/opt/bin/zstd"
elif ssh "$ssh_host" "[ -f /home/root/zstd ]"; then
compress="/home/root/zstd"
fi
2020-02-12 13:13:14 +01:00
2020-03-12 00:17:13 +01:00
# gracefully degrade to gzip if zstd is not present on remarkable or host
if [ -z "$compress" ]; then
echo "Your remarkable does not have zstd."
fallback_to_gzip
elif ! which zstd; then
echo "Your host does not have zstd."
fallback_to_gzip
else
decompress="zstd -d"
fi
2020-02-12 13:13:14 +01:00
2020-03-12 00:17:13 +01:00
# calculte how much bytes the window is
2020-02-12 13:13:14 +01:00
window_bytes="$(($width*$height*$bytes_per_pixel))"
2020-03-12 00:17:13 +01:00
# rotate 90 degrees if landscape=true
2020-02-24 09:30:12 +01:00
landscape_param="$($landscape && echo '-vf transpose=1')"
2020-03-12 00:17:13 +01:00
# read the first $window_bytes of the framebuffer
head_fb0="dd if=/dev/fb0 count=1 bs=$window_bytes 2>/dev/null"
2020-03-12 00:17:13 +01:00
# loop that keeps on reading and compressing, to be executed remotely
read_loop="while $head_fb0; do $loop_wait; done | $compress"
2020-03-12 00:17:13 +01:00
set -e # stop if an error occurs
2020-02-12 13:13:14 +01:00
ssh "$ssh_host" "$read_loop" \
| $decompress \
2020-02-12 13:13:14 +01:00
| ffplay -vcodec rawvideo \
-loglevel "$loglevel" \
2020-02-12 13:13:14 +01:00
-f rawvideo \
-pixel_format gray16le \
-video_size "$width,$height" \
$landscape_param \
-i -