2020-02-12 13:13:14 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-04-02 14:14:36 +02:00
|
|
|
# default values for arguments
|
2020-04-02 19:32:59 +02:00
|
|
|
ssh_host="root@10.11.99.1" # remarkable connected through USB
|
2020-04-02 14:14:36 +02:00
|
|
|
landscape=true # rotate 90 degrees to the right
|
2020-04-02 19:32:59 +02:00
|
|
|
output_path=- # display output through ffplay
|
|
|
|
format=- # automatic output format
|
2020-04-01 16:51:01 +02:00
|
|
|
|
2020-04-02 14:14:36 +02:00
|
|
|
# loop through arguments and process them
|
2020-04-02 16:17:21 +02:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
2020-04-01 16:51:01 +02:00
|
|
|
-p|--portrait)
|
2020-04-02 14:14:36 +02:00
|
|
|
landscape=false
|
|
|
|
shift
|
|
|
|
;;
|
2020-04-02 19:32:59 +02:00
|
|
|
-s|--source)
|
2020-04-02 14:14:36 +02:00
|
|
|
ssh_host="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2020-04-02 19:32:59 +02:00
|
|
|
-o|--output)
|
|
|
|
output_path="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-f|--format)
|
|
|
|
format="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2020-04-01 16:51:01 +02:00
|
|
|
*)
|
2020-04-02 19:32:59 +02:00
|
|
|
echo "Usage: $0 [-p] [-s <source>] [-o <output>] [-f <format>]"
|
2020-04-02 14:14:36 +02:00
|
|
|
exit 1
|
2020-04-01 16:51:01 +02:00
|
|
|
esac
|
|
|
|
done
|
2020-03-12 00:17:13 +01:00
|
|
|
|
|
|
|
# technical parameters
|
2020-02-12 13:13:14 +01:00
|
|
|
width=1408
|
|
|
|
height=1872
|
|
|
|
bytes_per_pixel=2
|
2020-02-12 14:47:47 +01:00
|
|
|
loop_wait="true"
|
|
|
|
loglevel="info"
|
2020-04-02 14:14:36 +02:00
|
|
|
ssh_cmd="ssh -o ConnectTimeout=1 "$ssh_host""
|
2020-02-12 14:47:47 +01:00
|
|
|
|
2020-03-17 23:44:55 +01:00
|
|
|
# check if we are able to reach the remarkable
|
2020-04-02 14:14:36 +02:00
|
|
|
if ! $ssh_cmd true; then
|
2020-02-12 13:13:14 +01:00
|
|
|
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."
|
2020-02-12 14:47:47 +01:00
|
|
|
compress="gzip"
|
|
|
|
decompress="gzip -d"
|
2020-03-12 00:17:13 +01:00
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
2020-03-17 23:44:55 +01:00
|
|
|
|
|
|
|
# check if lz4 is present on remarkable
|
2020-04-02 14:14:36 +02:00
|
|
|
if $ssh_cmd "[ -f /opt/bin/lz4 ]"; then
|
2020-03-17 23:44:55 +01:00
|
|
|
compress="/opt/bin/lz4"
|
2020-04-02 14:14:36 +02:00
|
|
|
elif $ssh_cmd "[ -f ~/lz4 ]"; then
|
2020-03-17 23:44:55 +01:00
|
|
|
compress="~/lz4"
|
2020-02-12 14:47:47 +01:00
|
|
|
fi
|
2020-02-12 13:13:14 +01:00
|
|
|
|
2020-03-17 23:44:55 +01:00
|
|
|
# gracefully degrade to gzip if is not present on remarkable or host
|
2020-03-12 00:17:13 +01:00
|
|
|
if [ -z "$compress" ]; then
|
2020-03-17 23:44:55 +01:00
|
|
|
echo "Your remarkable does not have lz4."
|
2020-03-12 00:17:13 +01:00
|
|
|
fallback_to_gzip
|
2020-03-18 16:19:12 +01:00
|
|
|
elif ! which lz4; then
|
2020-03-17 23:44:55 +01:00
|
|
|
echo "Your host does not have lz4."
|
2020-03-12 00:17:13 +01:00
|
|
|
fallback_to_gzip
|
|
|
|
else
|
2020-03-17 23:44:55 +01:00
|
|
|
decompress="lz4 -d"
|
2020-03-12 00:17:13 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-12 13:13:14 +01:00
|
|
|
|
2020-04-02 19:32:59 +02:00
|
|
|
output_args=()
|
2020-04-03 11:25:20 +02:00
|
|
|
video_filters=()
|
2020-04-02 19:32:59 +02:00
|
|
|
|
|
|
|
# calculate 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-04-03 11:25:20 +02:00
|
|
|
$landscape && video_filters+=('transpose=1')
|
2020-03-12 00:17:13 +01:00
|
|
|
|
|
|
|
# read the first $window_bytes of the framebuffer
|
2020-02-12 14:47:47 +01:00
|
|
|
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
|
2020-02-12 14:47:47 +01:00
|
|
|
read_loop="while $head_fb0; do $loop_wait; done | $compress"
|
|
|
|
|
2020-04-02 19:32:59 +02:00
|
|
|
if [ "$output_path" = - ]; then
|
|
|
|
output_command=ffplay
|
|
|
|
else
|
|
|
|
output_command=ffmpeg
|
|
|
|
|
|
|
|
if [ "$format" != - ]; then
|
|
|
|
output_args+=('-f' "$format")
|
|
|
|
fi
|
|
|
|
|
|
|
|
output_args+=("$output_path")
|
|
|
|
fi
|
|
|
|
|
2020-04-03 11:25:20 +02:00
|
|
|
# set frame presentation time to the time it was received
|
|
|
|
video_filters+=('setpts=(RTCTIME - RTCSTART) / (TB * 1000000)')
|
|
|
|
|
|
|
|
joined_filters=$(IFS=,; echo "${video_filters[*]}")
|
|
|
|
output_args+=('-vf' "$joined_filters")
|
|
|
|
|
2020-03-12 00:17:13 +01:00
|
|
|
set -e # stop if an error occurs
|
2020-02-12 13:13:14 +01:00
|
|
|
|
2020-04-02 14:14:36 +02:00
|
|
|
$ssh_cmd "$read_loop" \
|
2020-02-12 14:47:47 +01:00
|
|
|
| $decompress \
|
2020-04-02 19:32:59 +02:00
|
|
|
| "$output_command" \
|
|
|
|
-vcodec rawvideo \
|
2020-02-12 14:47:47 +01:00
|
|
|
-loglevel "$loglevel" \
|
2020-02-12 13:13:14 +01:00
|
|
|
-f rawvideo \
|
|
|
|
-pixel_format gray16le \
|
|
|
|
-video_size "$width,$height" \
|
2020-04-02 19:32:59 +02:00
|
|
|
-i - \
|
|
|
|
"${output_args[@]}"
|